private void init(OutputStream outs) throws IOException { this.underlyingStream = outs; this.out = new BufferedFileOutputStream(outs); EncoderFactory efactory = new EncoderFactory(); this.vout = efactory.binaryEncoder(out, null); dout.setSchema(schema); buffer = new NonCopyingByteArrayOutputStream( Math.min((int)(syncInterval * 1.25), Integer.MAX_VALUE/2 -1)); this.bufOut = efactory.binaryEncoder(buffer, null); if (this.codec == null) { this.codec = CodecFactory.nullCodec().createInstance(); } this.isOpen = true; }
private void init(OutputStream outs) throws IOException { this.underlyingStream = outs; this.out = new BufferedFileOutputStream(outs); EncoderFactory efactory = new EncoderFactory(); this.vout = efactory.binaryEncoder(out, null); dout.setSchema(schema); buffer = new NonCopyingByteArrayOutputStream( Math.min((int)(syncInterval * 1.25), Integer.MAX_VALUE/2 -1)); this.bufOut = efactory.binaryEncoder(buffer, null); if (this.codec == null) { this.codec = CodecFactory.nullCodec().createInstance(); } this.isOpen = true; }
@Override ByteBuffer compress(ByteBuffer data) throws IOException { if (compressionBuffer == null) { compressionBuffer = new NonCopyingByteArrayOutputStream( data.remaining()); } if (deflater == null) { deflater = new Deflater(compressionLevel, nowrap); } // Pass output through deflate DeflaterOutputStream deflaterStream = new DeflaterOutputStream(compressionBuffer, deflater); deflaterStream.write(data.array(), data.position() + data.arrayOffset(), data.limit() + data.arrayOffset()); deflaterStream.finish(); ByteBuffer result = compressionBuffer.getByteArrayAsByteBuffer(); deflater.reset(); compressionBuffer.reset(); return result; }
@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; }
private void init(OutputStream outs) throws IOException { this.underlyingStream = outs; this.out = new BufferedFileOutputStream(outs); EncoderFactory efactory = new EncoderFactory(); this.vout = efactory.binaryEncoder(out, null); dout.setSchema(schema); buffer = new NonCopyingByteArrayOutputStream( Math.min((int)(syncInterval * 1.25), Integer.MAX_VALUE/2 -1)); this.bufOut = efactory.binaryEncoder(buffer, null); if (this.codec == null) { this.codec = CodecFactory.nullCodec().createInstance(); } this.isOpen = true; }
private void init(OutputStream outs) throws IOException { this.out = new BufferedFileOutputStream(outs); EncoderFactory efactory = new EncoderFactory(); this.vout = efactory.binaryEncoder(out, null); dout.setSchema(schema); buffer = new NonCopyingByteArrayOutputStream( Math.min((int)(syncInterval * 1.25), Integer.MAX_VALUE/2 -1)); this.bufOut = efactory.binaryEncoder(buffer, null); if (this.codec == null) { this.codec = CodecFactory.nullCodec().createInstance(); } this.isOpen = true; }
private void init(OutputStream outs) throws IOException { this.out = new BufferedFileOutputStream(outs); this.vout = new BinaryEncoder(out); dout.setSchema(schema); buffer = new NonCopyingByteArrayOutputStream( Math.min((int)(syncInterval * 1.25), Integer.MAX_VALUE/2 -1)); this.bufOut = new BinaryEncoder(buffer); if (this.codec == null) { this.codec = CodecFactory.nullCodec().createInstance(); } this.isOpen = true; }
private void init(OutputStream outs) throws IOException { this.out = new BufferedFileOutputStream(outs); this.vout = new BinaryEncoder(out); dout.setSchema(schema); buffer = new NonCopyingByteArrayOutputStream( Math.min((int)(syncInterval * 1.25), Integer.MAX_VALUE/2 -1)); this.bufOut = new BinaryEncoder(buffer); if (this.codec == null) { this.codec = CodecFactory.nullCodec().createInstance(); } this.isOpen = true; }