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") @SuppressWarnings("unchecked")
private void loadSerialized(Pair<File, InputStream> f) { private void loadSerialized(Pair<File, InputStream> f) {
try { log.debug("Reading motors from file " + f.getU().getPath());
log.debug("Reading motors from file " + f.getU().getPath()); try (ObjectInputStream ois = new ObjectInputStream(f.getV())) {
ObjectInputStream ois = new ObjectInputStream(f.getV());
List<ThrustCurveMotor> motors = (List<ThrustCurveMotor>) ois.readObject(); List<ThrustCurveMotor> motors = (List<ThrustCurveMotor>) ois.readObject();
addMotors(motors); addMotors(motors);
} catch (Exception ex) { } 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) public List<ThrustCurveMotor.Builder> load(Reader reader, String filename, boolean removeDelayFromDesignation)
throws IOException { throws IOException {
List<ThrustCurveMotor.Builder> motors = new ArrayList<>(); List<ThrustCurveMotor.Builder> motors = new ArrayList<>();
BufferedReader in = new BufferedReader(reader);
String manufacturer = ""; String manufacturer = "";
String designation = ""; String designation = "";
@ -68,7 +67,7 @@ public class RASPMotorLoader extends AbstractMotorLoader {
double propW = 0; double propW = 0;
double totalW = 0; double totalW = 0;
try { try (BufferedReader in = new BufferedReader(reader)) {
String line; String line;
String[] pieces, buf; String[] pieces, buf;

View File

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