From 124f869faae3a0f75a3825e6a8e195c17f3c626a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 16 Oct 2014 23:34:20 +0400 Subject: initial for idea --- .../github/junrar/unpack/ppm/AnalyzeHeapDump.java | 94 ++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 org.fox.ttcomics/src/main/java/com/github/junrar/unpack/ppm/AnalyzeHeapDump.java (limited to 'org.fox.ttcomics/src/main/java/com/github/junrar/unpack/ppm/AnalyzeHeapDump.java') diff --git a/org.fox.ttcomics/src/main/java/com/github/junrar/unpack/ppm/AnalyzeHeapDump.java b/org.fox.ttcomics/src/main/java/com/github/junrar/unpack/ppm/AnalyzeHeapDump.java new file mode 100644 index 0000000..634fc92 --- /dev/null +++ b/org.fox.ttcomics/src/main/java/com/github/junrar/unpack/ppm/AnalyzeHeapDump.java @@ -0,0 +1,94 @@ +package com.github.junrar.unpack.ppm; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +/** + * For debugging purposes only. + * + * @author alban + */ +public class AnalyzeHeapDump { + + /** Creates a new instance of AnalyzeHeapDump */ + public AnalyzeHeapDump() { + } + + public static void main(String[] argv) { + File cfile = new File("P:\\test\\heapdumpc"); + File jfile = new File("P:\\test\\heapdumpj"); + if (!cfile.exists()) { + System.err.println("File not found: " + cfile.getAbsolutePath()); + return; + } + if (!jfile.exists()) { + System.err.println("File not found: " + jfile.getAbsolutePath()); + return; + } + long clen = cfile.length(); + long jlen = jfile.length(); + if (clen != jlen) { + System.out.println("File size mismatch"); + System.out.println("clen = " + clen); + System.out.println("jlen = " + jlen); + } + // Do byte comparison + long len = Math.min(clen, jlen); + InputStream cin = null; + InputStream jin = null; + int bufferLen = 256*1024; + try { + cin = new BufferedInputStream( + new FileInputStream(cfile), bufferLen); + jin = new BufferedInputStream( + new FileInputStream(jfile), bufferLen); + boolean matching = true; + boolean mismatchFound = false; + long startOff = 0L; + long off = 0L; + while (off < len) { + if (cin.read() != jin.read()) { + if (matching) { + startOff = off; + matching = false; + mismatchFound = true; + } + } + else { // match + if (!matching) { + printMismatch(startOff, off); + matching = true; + } + } + off++; + } + if (!matching) { + printMismatch(startOff, off); + } + if (!mismatchFound) { + System.out.println("Files are identical"); + } + System.out.println("Done"); + } + catch (IOException e) { + e.printStackTrace(); + } + finally { + try { + cin.close(); + jin.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + private static void printMismatch(long startOff, long bytesRead) { + System.out.println("Mismatch: off=" + startOff + + "(0x" + Long.toHexString(startOff) + + "), len=" + (bytesRead - startOff)); + } +} -- cgit v1.2.3