/** * @param is the input stream to decompress * @throws IOException if the header is malformed */ public UncompressInputStream(InputStream is) throws IOException { super(is); parse_header(); }
@Override public long skip(long num) throws IOException { byte[] tmp = new byte[(int) num]; int got = read(tmp, 0, (int) num); if (got > 0) return (long) got; else return 0L; }
static public void uncompress( String fileInName, FileOutputStream out) throws IOException { long start = System.currentTimeMillis(); int total = 0; try (InputStream in = new UncompressInputStream( new FileInputStream(fileInName))) { byte[] buffer = new byte[100000]; while (true) { int bytesRead = in.read(buffer); if (bytesRead == -1) break; out.write(buffer, 0, bytesRead); total += bytesRead; } } if (debugTiming) { long end = System.currentTimeMillis(); System.err.println("Decompressed " + total + " bytes"); System.err.println("Time: " + (end - start) / 1000. + " seconds"); } }
static public void uncompress( String fileInName, FileOutputStream out) throws IOException { long start = System.currentTimeMillis(); InputStream in = new UncompressInputStream( new FileInputStream(fileInName)); int total = 0; byte[] buffer = new byte[100000]; while (true) { int bytesRead = in.read(buffer); if (bytesRead == -1) break; out.write(buffer, 0, bytesRead); total += bytesRead; } in.close(); out.close(); if (debugTiming) { long end = System.currentTimeMillis(); System.err.println("Decompressed " + total + " bytes"); System.err.println("Time: " + (end - start) / 1000. + " seconds"); } }
static public void uncompress( String fileInName, FileOutputStream out) throws IOException { long start = System.currentTimeMillis(); InputStream in = new UncompressInputStream( new FileInputStream(fileInName)); int total = 0; byte[] buffer = new byte[100000]; while (true) { int bytesRead = in.read(buffer); if (bytesRead == -1) break; out.write(buffer, 0, bytesRead); total += bytesRead; } in.close(); out.close(); if (debugTiming) { long end = System.currentTimeMillis(); System.err.println("Decompressed " + total + " bytes"); System.err.println("Time: " + (end - start) / 1000. + " seconds"); } }
@Override public int read() throws IOException { int b = read(one, 0, 1); if (b == 1) return (one[0] & 0xff); else return -1; }
/** * @param is the input stream to decompress * @throws IOException if the header is malformed */ public UncompressInputStream(InputStream is) throws IOException { super(is); parse_header(); }
/** test */ public static void main(String args[]) throws Exception { if (args.length != 1) { System.err.println("Usage: UncompressInputStream <file>"); System.exit(1); } InputStream in = new UncompressInputStream(new FileInputStream(args[0])); byte[] buf = new byte[100000]; int tot = 0; long beg = System.currentTimeMillis(); while (true) { int got = in.read(buf); if (got < 0) break; System.out.write(buf, 0, got); tot += got; } long end = System.currentTimeMillis(); System.err.println("Decompressed " + tot + " bytes"); System.err.println("Time: " + (end - beg) / 1000. + " seconds"); } }
@Override public int read() throws IOException { int b = read(one, 0, 1); if (b == 1) return (one[0] & 0xff); else return -1; }
/** * @param is the input stream to decompress * @throws IOException if the header is malformed */ public UncompressInputStream(InputStream is) throws IOException { super(is); parse_header(); }
/** test */ public static void main(String args[]) throws Exception { if (args.length != 1) { System.err.println("Usage: UncompressInputStream <file>"); System.exit(1); } InputStream in = new UncompressInputStream(new FileInputStream(args[0])); byte[] buf = new byte[100000]; int tot = 0; long beg = System.currentTimeMillis(); while (true) { int got = in.read(buf); if (got < 0) break; System.out.write(buf, 0, got); tot += got; } long end = System.currentTimeMillis(); System.err.println("Decompressed " + tot + " bytes"); System.err.println("Time: " + (end - beg) / 1000. + " seconds"); } }
@Override public long skip(long num) throws IOException { byte[] tmp = new byte[(int) num]; int got = read(tmp, 0, (int) num); if (got > 0) return (long) got; else return 0L; }
/** test */ public static void main(String args[]) throws Exception { if (args.length != 1) { System.err.println("Usage: UncompressInputStream <file>"); System.exit(1); } try (InputStream in = new UncompressInputStream(new FileInputStream(args[0]))) { byte[] buf = new byte[100000]; int tot = 0; long beg = System.currentTimeMillis(); while (true) { int got = in.read(buf); if (got < 0) break; System.out.write(buf, 0, got); tot += got; } long end = System.currentTimeMillis(); System.err.println("Decompressed " + tot + " bytes"); System.err.println("Time: " + (end - beg) / 1000. + " seconds"); } } }
@Override public int read() throws IOException { int b = read(one, 0, 1); if (b == 1) return (one[0] & 0xff); else return -1; }
private static InputStream openInputStream(File file) throws IOException { String fileName = file.getName().toLowerCase(); InputStream is = new BufferedInputStream(new FileInputStream(file)); if (fileName.endsWith(".z")) { is = new UncompressInputStream(is); } else if (fileName.endsWith(".zip")) { ZipInputStream zin = new ZipInputStream(is); ZipEntry ze = zin.getNextEntry(); if (ze != null) { is = zin; } } else if (fileName.endsWith(".bz2")) { is = new CBZip2InputStream(is, true); } else if (fileName.endsWith(".gzip") || fileName.endsWith(".gz")) { is = new GZIPInputStream(is); } return is; }
@Override public long skip(long num) throws IOException { byte[] tmp = new byte[(int) num]; int got = read(tmp, 0, (int) num); if (got > 0) return (long) got; else return 0L; }
in = new UncompressInputStream(new FileInputStream(filename)); copy(in, fout, 100000); if (debugCompress) System.out.println("uncompressed " + filename + " to " + uncompressedFile);