I'm reading a file containing binary data followed by a serialized object:
FileInputStream fis = new FileInputStream(file);
GZIPInputStream gzis = new GZIPInputStream(fis);
DataInputStream dis = new DataInputStream(gzis);
ObjectInputStream ois = new ObjectInputStream(gzis);
int i = dis.readInt();
Object o = ois.readObject();
While writing this code some questions came to mind:
1. Which streams should be closed?
2. How to correctly handle exceptions without try-finally spaghetti?