Skip to content

Commit 1c0cb4e

Browse files
committed
Java I/O: Context-Specific Deserialization Filters
1 parent 2fbe82d commit 1c0cb4e

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

Chapter06/P138_CustomLambdaFilter/src/main/java/modern/challenge/Converters.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,14 @@ private Converters() {
1515
throw new AssertionError("Cannot be instantiated");
1616
}
1717

18-
public static byte[] objectToBytes(Serializable obj) throws IOException {
18+
public static byte[] objectToBytes(Serializable obj) throws IOException {
1919

20-
ByteArrayOutputStream baos = new ByteArrayOutputStream();
21-
22-
try ( ObjectOutputStream ois = new ObjectOutputStream(baos)) {
20+
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream();
21+
ObjectOutputStream ois = new ObjectOutputStream(baos)) {
2322
ois.writeObject(obj);
24-
}
25-
26-
baos.close();
27-
28-
return baos.toByteArray();
23+
24+
return baos.toByteArray();
25+
}
2926
}
3027

3128
public static Object bytesToObject(byte[] bytes, ObjectInputFilter filter)

Chapter06/P138_CustomLambdaFilter/src/main/java/modern/challenge/Main.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package modern.challenge;
22

33
import java.io.IOException;
4-
import java.io.ObjectInputFilter;
54
import java.io.ObjectInputFilter.Status;
65
import java.util.Arrays;
76

0 commit comments

Comments
 (0)