Skip to content

Commit

Permalink
Use try-with-resources
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Dec 2, 2023
1 parent 9238c5a commit 62f75d8
Showing 1 changed file with 2 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,18 @@ public void testRangeMinMax() {
public void testSerialization() {
// Serialize the check digit routine
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
final ObjectOutputStream oos = new ObjectOutputStream(baos);
try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
oos.writeObject(validator);
oos.flush();
oos.close();
} catch (final Exception e) {
fail(validator.getClass().getName() + " error during serialization: " + e);
}

// Deserialize the test object
Object result = null;
try {
final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
try (ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray())) {
final ObjectInputStream ois = new ObjectInputStream(bais);
result = ois.readObject();
bais.close();
} catch (final Exception e) {
fail(validator.getClass().getName() + " error during deserialization: " + e);
}
Expand Down

0 comments on commit 62f75d8

Please sign in to comment.