/** return if checksum matches for a snapshot **/ private boolean getCheckSum(FileSnap snap, File snapFile) throws IOException { DataTree dt = new DataTree(); Map<Long, Integer> sessions = new ConcurrentHashMap<Long, Integer>(); InputStream snapIS = new BufferedInputStream(new FileInputStream( snapFile)); CheckedInputStream crcIn = new CheckedInputStream(snapIS, new Adler32()); InputArchive ia = BinaryInputArchive.getArchive(crcIn); try { snap.deserialize(dt, sessions, ia); } catch (IOException ie) { // we failed on the most recent snapshot // must be incomplete // try reading the next one // after corrupting snapIS.close(); crcIn.close(); throw ie; } long checksum = crcIn.getChecksum().getValue(); long val = ia.readLong("val"); snapIS.close(); crcIn.close(); return (val != checksum); }
private static void readSnapshotLog(String snapshotPath) throws Exception { FileInputStream fis = new FileInputStream(snapshotPath); BinaryInputArchive ia = BinaryInputArchive.getArchive(fis); Map<Long, Integer> sessions = new HashMap<Long, Integer>(); DataTree dt = new DataTree(); FileHeader header = new FileHeader(); header.deserialize(ia, "fileheader"); if (header.getMagic() != FileSnap.SNAP_MAGIC) { throw new IOException("mismatching magic headers " + header.getMagic() + " != " + FileSnap.SNAP_MAGIC); } SerializeUtils.deserializeSnapshot(dt, ia, sessions); if (bw != null) { bw.write(sessions.toString()); bw.newLine(); } else { System.out.println(sessions); } traverse(dt, 1, "/"); }
public void run(String snapshotFileName) throws IOException { InputStream is = new CheckedInputStream( new BufferedInputStream(new FileInputStream(snapshotFileName)), new Adler32()); InputArchive ia = BinaryInputArchive.getArchive(is); FileSnap fileSnap = new FileSnap(null); DataTree dataTree = new DataTree(); Map<Long, Integer> sessions = new HashMap<Long, Integer>(); fileSnap.deserialize(dataTree, sessions, ia); printDetails(dataTree, sessions); }