Use try with resources

This commit is contained in:
SiboVG 2024-08-09 05:30:10 +02:00
parent aebb8b87d2
commit 5174eebb3a
3 changed files with 5 additions and 9 deletions

View File

@ -103,9 +103,8 @@ public class MotorDatabaseLoader extends AsynchronousDatabaseLoader {
*/
@SuppressWarnings("unchecked")
private void loadSerialized(Pair<File, InputStream> f) {
try {
log.debug("Reading motors from file " + f.getU().getPath());
ObjectInputStream ois = new ObjectInputStream(f.getV());
log.debug("Reading motors from file " + f.getU().getPath());
try (ObjectInputStream ois = new ObjectInputStream(f.getV())) {
List<ThrustCurveMotor> motors = (List<ThrustCurveMotor>) ois.readObject();
addMotors(motors);
} catch (Exception ex) {

View File

@ -52,7 +52,6 @@ public class RASPMotorLoader extends AbstractMotorLoader {
public List<ThrustCurveMotor.Builder> load(Reader reader, String filename, boolean removeDelayFromDesignation)
throws IOException {
List<ThrustCurveMotor.Builder> motors = new ArrayList<>();
BufferedReader in = new BufferedReader(reader);
String manufacturer = "";
String designation = "";
@ -68,7 +67,7 @@ public class RASPMotorLoader extends AbstractMotorLoader {
double propW = 0;
double totalW = 0;
try {
try (BufferedReader in = new BufferedReader(reader)) {
String line;
String[] pieces, buf;

View File

@ -406,11 +406,9 @@ public class ComponentPreset implements Comparable<ComponentPreset>, Serializabl
* Package scope so the factory can call it.
*/
void computeDigest() {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream os = new DataOutputStream(bos);
try (DataOutputStream os = new DataOutputStream(bos)) {
List<TypedKey<?>> keys = new ArrayList<>(properties.keySet());
keys.sort(new Comparator<>() {