@Test public void testEBDump_dump() throws Exception { String bookPath = new File(this.getClass().getResource("/data/epwing").getFile()) .getAbsolutePath(); EBDump ebDump = new EBDump(bookPath); try { ebDump.dump(0, 0, 64); } catch (EBException ebe) { fail(ebe.getMessage()); } String expected = "00001:000 00 03 20 00 00 00 00 00 00 00 00 00 00 00 00 00 ................\n" + "00001:010 00 00 00 00 00 02 00 00 00 01 01 00 00 00 00 00 ................\n" + "00001:020 05 00 00 00 00 03 00 00 00 01 01 00 00 00 00 00 ................\n" + "00001:030 91 00 00 00 00 04 00 00 00 02 02 41 55 40 00 00 ............\u5ABD..\n"; assertEquals(outContent.toString("UTF-8"), expected); }
public void dump(final int subindex, final long pos, final int size) throws EBException { int dumpsize; SubBook sub = _book.getSubBook(subindex); if (sub == null) { return; } if (size <= 0) { dumpsize = BookInputStream.PAGE_SIZE; } else { dumpsize = size; } BookInputStream bis = sub.getTextFile().getInputStream(); byte[] b = new byte[dumpsize]; try { bis.seek(pos); bis.readFully(b, 0, b.length); } finally { bis.close(); } long page = BookInputStream.getPage(pos); long pos2 = pos + dumpsize; long start = pos - (pos & 0x0f); long end = pos2; if ((end % 16) > 0) { end = end + (16 - (end % 16)); } StringBuilder buf = new StringBuilder(); int idx = 0; long i = 0L; int j, k; int offset, high, low; for (i=start; i<end; i+=16) { if (pos + idx >= page * BookInputStream.PAGE_SIZE) { page++; } buf.append(_toHexString(page)).append(':'); offset = (int)(i%BookInputStream.PAGE_SIZE); buf.append(_toHexString(offset)).append(' '); k = 0; for (j=0; j<16; j++) { if (j == 8) { buf.append(' '); } buf.append(' '); if (i+j >= pos && i+j < pos2) { buf.append(_toHexString(b[idx+k])); k++; } else { buf.append(" "); } } buf.append(" "); for (j=0; j<16; j+=2) { if (i+j >= pos && i+j < pos2) { high = b[idx++] & 0xff; if (i+j+1 >= pos && i+j+1 < pos2) { low = b[idx++] & 0xff; if (high > 0x20 && high < 0x7f && low > 0x20 && low < 0x7f) { buf.append(ByteUtil.jisx0208ToString(b, idx-2, 2)); } else if (high > 0x20 && high < 0x7f && low > 0xa0 && low < 0xff) { buf.append(ByteUtil.gb2312ToString(b, idx-2, 2)); } else if (high > 0xa0 && high < 0xff && low > 0x20 && low < 0x7f) { buf.append("??"); } else { buf.append(".."); } } else { buf.append(". "); } } else { buf.append(' '); if (i+j+1 >= pos && i+j+1 < pos2) { idx++; buf.append('.'); } else { buf.append(' '); } } } System.out.println(buf.toString()); System.out.flush(); buf.delete(0, buf.length()); } }
EBDump { public void dump(final int subindex, final long pos, final int size) throws EBException { int dumpsize; SubBook sub = _book.getSubBook(subindex); if (sub == null) { return; } if (size <= 0) { dumpsize = BookInputStream.PAGE_SIZE; } else { dumpsize = size; } BookInputStream bis = sub.getTextFile().getInputStream(); byte[] b = new byte[dumpsize]; try { bis.seek(pos); bis.readFully(b, 0, b.length); } finally { bis.close(); } long page = BookInputStream.getPage(pos); long pos2 = pos + dumpsize; long start = pos - (pos & 0x0f); long end = pos2; if ((end % 16) > 0) { end = end + (16 - (end % 16)); } StringBuilder buf = new StringBuilder(); int idx = 0; long i = 0L; int j, k; int offset, high, low; for (i=start; i<end; i+=16) { if (pos + idx >= page * BookInputStream.PAGE_SIZE) { page++; } buf.append(_toHexString(page)).append(':'); offset = (int)(i%BookInputStream.PAGE_SIZE); buf.append(_toHexString(offset)).append(' '); k = 0; for (j=0; j<16; j++) { if (j == 8) { buf.append(' '); } buf.append(' '); if (i+j >= pos && i+j < pos2) { buf.append(_toHexString(b[idx+k])); k++; } else { buf.append(" "); } } buf.append(" "); for (j=0; j<16; j+=2) { if (i+j >= pos && i+j < pos2) { high = b[idx++] & 0xff; if (i+j+1 >= pos && i+j+1 < pos2) { low = b[idx++] & 0xff; if (high > 0x20 && high < 0x7f && low > 0x20 && low < 0x7f) { buf.append(ByteUtil.jisx0208ToString(b, idx-2, 2)); } else if (high > 0x20 && high < 0x7f && low > 0xa0 && low < 0xff) { buf.append(ByteUtil.gb2312ToString(b, idx-2, 2)); } else if (high > 0xa0 && high < 0xff && low > 0x20 && low < 0x7f) { buf.append("??"); } else { buf.append(".."); } } else { buf.append(". "); } } else { buf.append(' '); if (i+j+1 >= pos && i+j+1 < pos2) { idx++; buf.append('.'); } else { buf.append(' '); } } } System.out.println(buf.toString()); System.out.flush(); buf.delete(0, buf.length()); } } }
EBDump { public void dump(final int subindex, final long pos, final int size) throws EBException { int dumpsize; SubBook sub = _book.getSubBook(subindex); if (sub == null) { return; } if (size <= 0) { dumpsize = BookInputStream.PAGE_SIZE; } else { dumpsize = size; } BookInputStream bis = sub.getTextFile().getInputStream(); byte[] b = new byte[dumpsize]; try { bis.seek(pos); bis.readFully(b, 0, b.length); } finally { bis.close(); } long page = BookInputStream.getPage(pos); long pos2 = pos + dumpsize; long start = pos - (pos & 0x0f); long end = pos2; if ((end % 16) > 0) { end = end + (16 - (end % 16)); } StringBuilder buf = new StringBuilder(); int idx = 0; long i = 0L; int j, k; int offset, high, low; for (i=start; i<end; i+=16) { if (pos + idx >= page * BookInputStream.PAGE_SIZE) { page++; } buf.append(_toHexString(page)).append(':'); offset = (int)(i%BookInputStream.PAGE_SIZE); buf.append(_toHexString(offset)).append(' '); k = 0; for (j=0; j<16; j++) { if (j == 8) { buf.append(' '); } buf.append(' '); if (i+j >= pos && i+j < pos2) { buf.append(_toHexString(b[idx+k])); k++; } else { buf.append(" "); } } buf.append(" "); for (j=0; j<16; j+=2) { if (i+j >= pos && i+j < pos2) { high = b[idx++] & 0xff; if (i+j+1 >= pos && i+j+1 < pos2) { low = b[idx++] & 0xff; if (high > 0x20 && high < 0x7f && low > 0x20 && low < 0x7f) { buf.append(ByteUtil.jisx0208ToString(b, idx-2, 2)); } else if (high > 0x20 && high < 0x7f && low > 0xa0 && low < 0xff) { buf.append(ByteUtil.gb2312ToString(b, idx-2, 2)); } else if (high > 0xa0 && high < 0xff && low > 0x20 && low < 0x7f) { buf.append("??"); } else { buf.append(".."); } } else { buf.append(". "); } } else { buf.append(' '); if (i+j+1 >= pos && i+j+1 < pos2) { idx++; buf.append('.'); } else { buf.append(' '); } } } System.out.println(buf.toString()); System.out.flush(); buf.delete(0, buf.length()); } } EBDump(final String path); }
EBDump { public void dump(final int subindex, final long pos, final int size) throws EBException { int dumpsize; SubBook sub = _book.getSubBook(subindex); if (sub == null) { return; } if (size <= 0) { dumpsize = BookInputStream.PAGE_SIZE; } else { dumpsize = size; } BookInputStream bis = sub.getTextFile().getInputStream(); byte[] b = new byte[dumpsize]; try { bis.seek(pos); bis.readFully(b, 0, b.length); } finally { bis.close(); } long page = BookInputStream.getPage(pos); long pos2 = pos + dumpsize; long start = pos - (pos & 0x0f); long end = pos2; if ((end % 16) > 0) { end = end + (16 - (end % 16)); } StringBuilder buf = new StringBuilder(); int idx = 0; long i = 0L; int j, k; int offset, high, low; for (i=start; i<end; i+=16) { if (pos + idx >= page * BookInputStream.PAGE_SIZE) { page++; } buf.append(_toHexString(page)).append(':'); offset = (int)(i%BookInputStream.PAGE_SIZE); buf.append(_toHexString(offset)).append(' '); k = 0; for (j=0; j<16; j++) { if (j == 8) { buf.append(' '); } buf.append(' '); if (i+j >= pos && i+j < pos2) { buf.append(_toHexString(b[idx+k])); k++; } else { buf.append(" "); } } buf.append(" "); for (j=0; j<16; j+=2) { if (i+j >= pos && i+j < pos2) { high = b[idx++] & 0xff; if (i+j+1 >= pos && i+j+1 < pos2) { low = b[idx++] & 0xff; if (high > 0x20 && high < 0x7f && low > 0x20 && low < 0x7f) { buf.append(ByteUtil.jisx0208ToString(b, idx-2, 2)); } else if (high > 0x20 && high < 0x7f && low > 0xa0 && low < 0xff) { buf.append(ByteUtil.gb2312ToString(b, idx-2, 2)); } else if (high > 0xa0 && high < 0xff && low > 0x20 && low < 0x7f) { buf.append("??"); } else { buf.append(".."); } } else { buf.append(". "); } } else { buf.append(' '); if (i+j+1 >= pos && i+j+1 < pos2) { idx++; buf.append('.'); } else { buf.append(' '); } } } System.out.println(buf.toString()); System.out.flush(); buf.delete(0, buf.length()); } } EBDump(final String path); static void main(final String[] args); void dump(final int subindex, final long pos, final int size); }
EBDump { public void dump(final int subindex, final long pos, final int size) throws EBException { int dumpsize; SubBook sub = _book.getSubBook(subindex); if (sub == null) { return; } if (size <= 0) { dumpsize = BookInputStream.PAGE_SIZE; } else { dumpsize = size; } BookInputStream bis = sub.getTextFile().getInputStream(); byte[] b = new byte[dumpsize]; try { bis.seek(pos); bis.readFully(b, 0, b.length); } finally { bis.close(); } long page = BookInputStream.getPage(pos); long pos2 = pos + dumpsize; long start = pos - (pos & 0x0f); long end = pos2; if ((end % 16) > 0) { end = end + (16 - (end % 16)); } StringBuilder buf = new StringBuilder(); int idx = 0; long i = 0L; int j, k; int offset, high, low; for (i=start; i<end; i+=16) { if (pos + idx >= page * BookInputStream.PAGE_SIZE) { page++; } buf.append(_toHexString(page)).append(':'); offset = (int)(i%BookInputStream.PAGE_SIZE); buf.append(_toHexString(offset)).append(' '); k = 0; for (j=0; j<16; j++) { if (j == 8) { buf.append(' '); } buf.append(' '); if (i+j >= pos && i+j < pos2) { buf.append(_toHexString(b[idx+k])); k++; } else { buf.append(" "); } } buf.append(" "); for (j=0; j<16; j+=2) { if (i+j >= pos && i+j < pos2) { high = b[idx++] & 0xff; if (i+j+1 >= pos && i+j+1 < pos2) { low = b[idx++] & 0xff; if (high > 0x20 && high < 0x7f && low > 0x20 && low < 0x7f) { buf.append(ByteUtil.jisx0208ToString(b, idx-2, 2)); } else if (high > 0x20 && high < 0x7f && low > 0xa0 && low < 0xff) { buf.append(ByteUtil.gb2312ToString(b, idx-2, 2)); } else if (high > 0xa0 && high < 0xff && low > 0x20 && low < 0x7f) { buf.append("??"); } else { buf.append(".."); } } else { buf.append(". "); } } else { buf.append(' '); if (i+j+1 >= pos && i+j+1 < pos2) { idx++; buf.append('.'); } else { buf.append(' '); } } } System.out.println(buf.toString()); System.out.flush(); buf.delete(0, buf.length()); } } EBDump(final String path); static void main(final String[] args); void dump(final int subindex, final long pos, final int size);  }