/** * Constructor taking an InputStream and its bit arrangement. * @param in the InputStream * @param byteOrder the bit arrangement across byte boundaries, * either BIG_ENDIAN (aaaaabbb bb000000) or LITTLE_ENDIAN (bbbaaaaa 000000bb) */ public BitInputStream(final InputStream in, final ByteOrder byteOrder) { this.in = new CountingInputStream(in); this.byteOrder = byteOrder; }
/** {@inheritDoc} */ @Override public void close() throws IOException { in.close(); }
@Override public int read(final byte[] b, final int off, final int len) throws IOException { final int r = in.read(b, off, len); if (r >= 0) { count(r); } return r; } /**
/** * @since 1.17 */ @Override public long getCompressedCount() { return countingStream.getBytesRead() - unreadBytes; }
counter = new CountingInputStream(new FileInputStream(f)); } catch (FileNotFoundException e) { throw new RuntimeException(String.format("archive '%s' does not exists", mCurrentTask.path)); percentage = (short) (((double) counter.getBytesRead() / total) * 100); if (percentage != old_percentage) { mBuilder.setProgress(100, percentage, false) } finally { try { counter.close(); } catch (IOException ignore) { }
@Override public int read(final byte[] b) throws IOException { return read(b, 0, b.length); } @Override
counter = new CountingInputStream(new FileInputStream(inFile)); is = openArchiveStream(counter); isTar = mCurrentTask.archiver.equals(archiveAlgorithm.tar); outputStream = null; percentage = (short) (((double) counter.getBytesRead() / total) * 100); if (percentage != old_percentage) { mBuilder.setProgress(100, percentage, false)
final boolean decompressConcatenated) throws IOException { countingStream = new CountingInputStream(inputStream); if (countingStream.markSupported()) { in = countingStream; } else {
/** * Returns an estimate of the number of bits that can be read from * this input stream without blocking by the next invocation of a * method for this input stream. * @throws IOException if the underlying stream throws one when calling available * @return estimate of the number of bits that can be read without blocking * @since 1.16 */ public long bitsAvailable() throws IOException { return bitsCachedSize + ((long) Byte.SIZE) * in.available(); }
/** * @since 1.17 */ @Override public long getCompressedCount() { return in.getBytesRead(); }
private long processBitsGreater57(final int count) throws IOException { final long bitsOut; int overflowBits = 0; long overflow = 0L; // bitsCachedSize >= 57 and left-shifting it 8 bits would cause an overflow int bitsToAddCount = count - bitsCachedSize; overflowBits = Byte.SIZE - bitsToAddCount; final long nextByte = in.read(); if (nextByte < 0) { return nextByte; } if (byteOrder == ByteOrder.LITTLE_ENDIAN) { long bitsToAdd = nextByte & MASKS[bitsToAddCount]; bitsCached |= (bitsToAdd << bitsCachedSize); overflow = (nextByte >>> bitsToAddCount) & MASKS[overflowBits]; } else { bitsCached <<= bitsToAddCount; long bitsToAdd = (nextByte >>> (overflowBits)) & MASKS[bitsToAddCount]; bitsCached |= bitsToAdd; overflow = nextByte & MASKS[overflowBits]; } bitsOut = bitsCached & MASKS[count]; bitsCached = overflow; bitsCachedSize = overflowBits; return bitsOut; }
/** * @since 1.17 */ @Override public long getCompressedCount() { return in.getBytesRead(); }
/** * Creates a new LZ77 input stream. * * @param is * An InputStream to read compressed data from * @param windowSize * Size of the window kept for back-references, must be bigger than the biggest offset expected. * * @throws IOException if reading fails */ public AbstractLZ77CompressorInputStream(final InputStream is, int windowSize) throws IOException { this.in = new CountingInputStream(is); this.windowSize = windowSize; buf = new byte[3 * windowSize]; writeIndex = readIndex = 0; bytesRemaining = 0; }
/** * Fills the cache up to 56 bits * @param count * @return return true, when EOF * @throws IOException */ private boolean ensureCache(final int count) throws IOException { while (bitsCachedSize < count && bitsCachedSize < 57) { final long nextByte = in.read(); if (nextByte < 0) { return true; } if (byteOrder == ByteOrder.LITTLE_ENDIAN) { bitsCached |= (nextByte << bitsCachedSize); } else { bitsCached <<= Byte.SIZE; bitsCached |= nextByte; } bitsCachedSize += Byte.SIZE; } return false; }
@Override public int read() throws IOException { final int r = in.read(); if (r >= 0) { count(1); } return r; } @Override
@Override public void close() throws IOException { in.close(); }
/** * @since 1.17 */ @Override public long getCompressedCount() { return countingStream.getBytesRead(); }
public BrotliCompressorInputStream(final InputStream in) throws IOException { decIS = new BrotliInputStream(countingStream = new CountingInputStream(in)); }
private int readOneByte() throws IOException { final int b = in.read(); if (b != -1) { count(1); return b & 0xFF; } return -1; }
@Override public int read(final byte[] b, final int off, final int len) throws IOException { final int r = in.read(b, off, len); if (r >= 0) { count(r); } return r; } /**