@Override public CompressionInputStream createInputStream(InputStream in, Decompressor decompressor) throws IOException { return new DecompressorStream(in, decompressor, conf.getInt(IO_FILE_BUFFER_SIZE_KEY, IO_FILE_BUFFER_SIZE_DEFAULT)); }
@Override public int read() throws IOException { checkStream(); return (read(oneByte, 0, oneByte.length) == -1) ? -1 : (oneByte[0] & 0xff); }
@Override public int read(byte[] b, int off, int len) throws IOException { checkStream(); if ((off | len | (off + len) | (b.length - (off + len))) < 0) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return 0; } return decompress(b, off, len); }
@Override public int available() throws IOException { checkStream(); return (eof) ? 0 : 1; }
@Override public void resetState() throws IOException { originalBlockSize = 0; noUncompressedBytes = 0; super.resetState(); }
int m = getCompressedData(); if (m == -1) { int m = getCompressedData(); if (m == -1) { throw new EOFException("Unexpected end of input stream");
protected int getCompressedData() throws IOException { checkStream(); // note that the _caller_ is now required to call setInput() or throw return in.read(buffer, 0, buffer.length); }
@Override public void resetState() throws IOException { originalBlockSize = 0; noUncompressedBytes = 0; super.resetState(); }
int decompress(byte[] b, int off, int len) throws IOException { int n = 0; while ((n = decompressor.decompress(b, off, len)) == 0) { if (decompressor.finished() || decompressor.needsDictionary()) { eof = true; return -1; } if (decompressor.needsInput()) { getCompressedData(); } } return n; }
@Override public long skip(long n) throws IOException { // Sanity checks if (n < 0) { throw new IllegalArgumentException("negative skip length"); } checkStream(); // Read 'n' bytes int skipped = 0; while (skipped < n) { int len = Math.min(((int)n - skipped), skipBytes.length); len = read(skipBytes, 0, len); if (len == -1) { eof = true; break; } skipped += len; } return skipped; }
@Override public CompressionInputStream createInputStream(InputStream in, Decompressor decompressor) throws IOException { if (decompressor == null) { decompressor = createDecompressor(); // always succeeds (or throws) } return new DecompressorStream(in, decompressor, conf.getInt(IO_FILE_BUFFER_SIZE_KEY, IO_FILE_BUFFER_SIZE_DEFAULT)); }
@Override public int read(byte[] b, int off, int len) throws IOException { checkStream(); if ((off | len | (off + len) | (b.length - (off + len))) < 0) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return 0; } return decompress(b, off, len); }
@Override public int available() throws IOException { checkStream(); return (eof) ? 0 : 1; }
@Override public void resetState() throws IOException { originalBlockSize = 0; noUncompressedBytes = 0; super.resetState(); }
protected int decompress(byte[] b, int off, int len) throws IOException { int n = 0; while ((n = decompressor.decompress(b, off, len)) == 0) { if (decompressor.finished() || decompressor.needsDictionary()) { eof = true; return -1; } if (decompressor.needsInput()) { getCompressedData(); } } return n; }
@Override public int read() throws IOException { checkStream(); return (read(oneByte, 0, oneByte.length) == -1) ? -1 : (oneByte[0] & 0xff); }
/** * Create a {@link CompressionInputStream} that will read from the given * {@link InputStream} with the given {@link Decompressor}, and return a * stream for uncompressed data. * * @param in the stream to read compressed bytes from * @param decompressor decompressor to use * @return a stream to read uncompressed bytes from * @throws IOException */ @Override public CompressionInputStream createInputStream(InputStream in, Decompressor decompressor) throws IOException { return Bzip2Factory.isNativeBzip2Loaded(conf) ? new DecompressorStream(in, decompressor, conf.getInt(IO_FILE_BUFFER_SIZE_KEY, IO_FILE_BUFFER_SIZE_DEFAULT)) : new BZip2CompressionInputStream( in, 0L, Long.MAX_VALUE, READ_MODE.BYBLOCK); }
public int read(byte[] b, int off, int len) throws IOException { checkStream(); if ((off | len | (off + len) | (b.length - (off + len))) < 0) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return 0; } return decompress(b, off, len); }
@Override public int available() throws IOException { checkStream(); return (eof) ? 0 : 1; }
@Override public void resetState() throws IOException { originalBlockSize = 0; noUncompressedBytes = 0; super.resetState(); }