@Override public int read() throws IOException { if (closed) { return -1; } if (!ensureBuffer()) { return -1; } return buffer[position++] & 0xFF; }
@Override public int read() throws IOException { if (closed) { return -1; } if (!ensureBuffer()) { return -1; } return buffer[position++] & 0xFF; }
@Override public int read(byte[] output, int offset, int length) throws IOException { SnappyInternalUtils.checkNotNull(output, "output is null"); SnappyInternalUtils.checkPositionIndexes(offset, offset + length, output.length); if (closed) { throw new IOException("Stream is closed"); } if (length == 0) { return 0; } if (!ensureBuffer()) { return -1; } int size = min(length, available()); System.arraycopy(buffer, position, output, offset, size); position += size; return size; }
@Override public int read(byte[] output, int offset, int length) throws IOException { SnappyInternalUtils.checkNotNull(output, "output is null"); SnappyInternalUtils.checkPositionIndexes(offset, offset + length, output.length); if (closed) { throw new IOException("Stream is closed"); } if (length == 0) { return 0; } if (!ensureBuffer()) { return -1; } int size = min(length, available()); System.arraycopy(buffer, position, output, offset, size); position += size; return size; }