@Override ByteBuffer decompress(ByteBuffer data) throws IOException { if (compressionBuffer == null) { compressionBuffer = new NonCopyingByteArrayOutputStream( data.remaining()); } if (inflater == null) { inflater = new Inflater(nowrap); } InputStream uncompressed = new InflaterInputStream( new ByteArrayInputStream(data.array(), data.position() + data.arrayOffset(), data.remaining()), inflater); int read; byte[] buff = new byte[2048]; try { while (true) { read = uncompressed.read(buff); if (read < 0) break; compressionBuffer.write(buff, 0, read); } } catch (EOFException e) { // sometimes InflaterInputStream.read // throws this instead of returning -1 } ByteBuffer result = compressionBuffer.getByteArrayAsByteBuffer(); inflater.reset(); compressionBuffer.reset(); return result; }
/** Expert: Append a pre-encoded datum to the file. No validation is * performed to check that the encoding conforms to the file's schema. * Appending non-conforming data may result in an unreadable file. */ public void appendEncoded(ByteBuffer datum) throws IOException { assertOpen(); int start = datum.position(); buffer.write(datum.array(), start, datum.limit()-start); blockCount++; if (buffer.size() >= syncInterval) writeBlock(); }
private void resetBufferTo(int size) throws IOException { bufOut.flush(); byte[] data = buffer.toByteArray(); buffer.reset(); buffer.write(data, 0, size); }
private void resetBufferTo(int size) throws IOException { bufOut.flush(); byte[] data = buffer.toByteArray(); buffer.reset(); buffer.write(data, 0, size); }
private void resetBufferTo(int size) throws IOException { bufOut.flush(); byte[] data = buffer.toByteArray(); buffer.reset(); buffer.write(data, 0, size); }
private void resetBufferTo(int size) throws IOException { bufOut.flush(); byte[] data = buffer.toByteArray(); buffer.reset(); buffer.write(data, 0, size); }