@Override public RevObject read(ObjectId id, InputStream rawData) throws IOException { // decompress the stream LZFInputStream inflatedInputeStream = new LZFInputStream(CHUNK_DECODER, rawData); return factory.read(id, inflatedInputeStream); }
public static void decompress(InputStream in, OutputStream out) throws IOException { LZFInputStream decompressor = null; try { decompressor = new LZFInputStream(in); byte[] buf = ThreadLocalByteBuffer.getBuffer(); int len; while ((len = decompressor.read(buf)) != -1) { out.write(buf, 0, len); } } finally { if (decompressor != null) { decompressor.close(); } } }
@Override public int read() throws IOException { if (!readyBuffer()) { return -1; } return _decodedBytes[_bufferPosition++] & 255; }
LZFInputStream lzfIn = new LZFInputStream(counter); try { lzfIn.readAndWrite(out); } finally { _close(lzfIn);
/** * Fill the uncompressed bytes buffer by reading the underlying inputStream. * * @throws IOException * * @return True if there is now at least one byte to read in the buffer; false * if there is no more content to read */ protected boolean readyBuffer() throws IOException { if (_bufferPosition < _bufferLength) { return true; } if (_inputStreamClosed) { return false; } _bufferLength = _decoder.decodeChunk(_inputStream, _inputBuffer, _decodedBytes); if (_bufferLength < 0) { close(); return false; } _bufferPosition = 0; return (_bufferPosition < _bufferLength); } }
@Override public int read(final byte[] buffer) throws IOException { return read(buffer, 0, buffer.length); }
LZFInputStream lzfIn = new LZFInputStream(counter); try { lzfIn.readAndWrite(out); LZFInputStream lzfIn = new LZFInputStream(new BufferBackedInputStream(fullBuffer)); try { lzfIn.readAndWrite(out); } finally { _close(lzfIn);
/** * Fill the uncompressed bytes buffer by reading the underlying inputStream. * * @throws IOException * * @return True if there is now at least one byte to read in the buffer; false * if there is no more content to read */ protected boolean readyBuffer() throws IOException { if (_bufferPosition < _bufferLength) { return true; } if (_inputStreamClosed) { return false; } _bufferLength = _decoder.decodeChunk(_inputStream, _inputBuffer, _decodedBytes); if (_bufferLength < 0) { close(); return false; } _bufferPosition = 0; return (_bufferPosition < _bufferLength); } }
@Override public int read(final byte[] buffer) throws IOException { return read(buffer, 0, buffer.length); }
@Override public RevObject read(ObjectId id, InputStream rawData) throws IOException { // decompress the stream LZFInputStream inflatedInputeStream = new LZFInputStream(CHUNK_DECODER, rawData); return factory.read(id, inflatedInputeStream); }
/** * Fill the uncompressed bytes buffer by reading the underlying inputStream. * * @throws IOException * * @return True if there is now at least one byte to read in the buffer; false * if there is no more content to read */ protected boolean readyBuffer() throws IOException { if (_bufferPosition < _bufferLength) { return true; } if (_inputStreamClosed) { return false; } _bufferLength = _decoder.decodeChunk(_inputStream, _inputBuffer, _decodedBytes); if (_bufferLength < 0) { close(); return false; } _bufferPosition = 0; return (_bufferPosition < _bufferLength); } }
@Override public int read() throws IOException { if (!readyBuffer()) { return -1; } return _decodedBytes[_bufferPosition++] & 255; }
@Override public int read(final byte[] buffer) throws IOException { return read(buffer, 0, buffer.length); }
@Nullable private InputStream getRaw(final ObjectId id, boolean failIfNotFound) throws IllegalArgumentException { InputStream in = getRawInternal(id, failIfNotFound); if (null == in) { return null; } try { return new LZFInputStream(in); } catch (IOException e) { throw Throwables.propagate(e); } }
close(); return skipped;
@Override public int read() throws IOException { if (!readyBuffer()) { return -1; } return _decodedBytes[_bufferPosition++] & 255; }
private static InputStream wrapInputStream(InputStream inputStream) throws IOException { switch (GZTYPE) { case 0: // no compression return inputStream; case 1: // LZF return new LZFInputStream(inputStream); case 2: // Snappy return new SnappyInputStream(inputStream); default: throw new RuntimeException("Unknown compression type: " + GZTYPE); } }
close(); return skipped;
/** * Convenience method that will read and uncompress all data available, * and write it using given {@link OutputStream}. This avoids having to * make an intermediate copy of uncompressed data which would be needed * when doing the same manually. * * @param out OutputStream to use for writing content * * @return Number of bytes written (uncompressed) */ public int readAndWrite(OutputStream out) throws IOException { int total = 0; while (readyBuffer()) { int avail = _bufferLength - _bufferPosition; out.write(_decodedBytes, _bufferPosition, avail); _bufferPosition += avail; // to ensure it looks like we consumed it all total += avail; } return total; }
/** * Tries to efficiently allocate the response string if the "Content-Length" * header is set. */ private String readResponseStream(InputStream responseStream, HttpURLConnection connection) throws IOException { LOGGER.debug("Reading response stream"); InputStream decodedStream = responseStream; if (compression == Compression.LZF && "lzf".equals(connection.getHeaderField("Content-Encoding"))) { LOGGER.debug("Decoding lzf"); decodedStream = new LZFInputStream(responseStream); } int contentLength = connection.getContentLength(); if (contentLength == 0) { return ""; } else { return new String(ByteStreams.toByteArray(decodedStream), UTF_8); } }