Skip to content
Snippets Groups Projects
Commit 06b6bd25 authored by Alexis Durgnat's avatar Alexis Durgnat :milky_way:
Browse files

Try -> Try-with-ressources

parent 359b56f5
No related tags found
1 merge request!12Try -> Try-with-ressources
......@@ -55,32 +55,29 @@ public abstract class MessageQueue {
}
public static <T extends Serializable> byte[] serialize(T object){
ObjectOutputStream oos = null;
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
try {
oos = new ObjectOutputStream(byteStream);
try (
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(byteStream)
) {
oos.writeObject(object);
oos.flush();
return byteStream.toByteArray();
} catch (final Exception e) {
e.printStackTrace();
}finally{
// TODO
System.exit(1);
}
return null;
}
public static <T extends Serializable> T unserialize(byte[] serializedData){
ByteArrayInputStream inputStream = new ByteArrayInputStream(serializedData);
T result = null;
try {
ObjectInputStream ois = new ObjectInputStream(inputStream);
try (
ByteArrayInputStream inputStream = new ByteArrayInputStream(serializedData);
ObjectInputStream ois = new ObjectInputStream(inputStream)
) {
result = (T) ois.readObject();
} catch (final Exception e) {
e.printStackTrace();
}finally{
// TODO
System.exit(1);
}
return result;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment