@Override public final void close() throws IOException { if (closed) { return; } try { flush(); out.close(); } finally { closed = true; releaseDirectByteBuffer(directInputBuffer); releaseDirectByteBuffer(outputBuffer); } }
@Override public final void flush() throws IOException { if (closed) { throw new IOException("Stream is closed"); } flushBuffer(); }
writeBlock(out, outputBuffer, true, crc32c); writeBlock(out, buffer, false, crc32c);
break; case COMPRESSION_FORMAT_SNAPPY_FRAMED: compressionOut = new SnappyFramedOutputStream(bufferedOut); mimeTypeRef = "application/x-snappy-framed"; break;
/** * Compresses and writes out any buffered data. This does nothing if there * is no currently buffered data. * * @throws IOException */ private void flushBuffer() throws IOException { if (buffer.position() > 0) { buffer.flip(); writeCompressed(buffer); buffer.clear(); } }
break; case COMPRESSION_FORMAT_SNAPPY_FRAMED: compressionOut = new SnappyFramedOutputStream(bufferedOut); mimeTypeRef.set("application/x-snappy-framed"); break;
@Override protected OutputStream decorateWithCompression(NonClosingOutpusStreamDecorator stream) throws IOException { return new SnappyFramedOutputStream(stream, COMPRESSION_BLOCK_SIZE, MIN_COMPRESSION_RATIO); }
@Override public void write(int b) throws IOException { if (closed) { throw new IOException("Stream is closed"); } if (buffer.remaining() <= 0) { flushBuffer(); } buffer.put((byte) b); }
@Override protected OutputStream decorateWithCompression(NonClosingOutpusStreamDecorator stream) throws IOException { return new SnappyFramedOutputStream(stream, COMPRESSION_BLOCK_SIZE, MIN_COMPRESSION_RATIO); }
@Override public void write(byte[] input, int offset, int length) throws IOException { if (closed) { throw new IOException("Stream is closed"); } if (input == null) { throw new NullPointerException(); } else if ((offset < 0) || (offset > input.length) || (length < 0) || ((offset + length) > input.length) || ((offset + length) < 0)) { throw new IndexOutOfBoundsException(); } while (length > 0) { if (buffer.remaining() <= 0) { flushBuffer(); } final int toPut = Math.min(length, buffer.remaining()); buffer.put(input, offset, toPut); offset += toPut; length -= toPut; } }
@Override protected OutputStream decorateWithCompression(NonClosingOutpusStreamDecorator stream) throws IOException { return new SnappyFramedOutputStream(stream, COMPRESSION_BLOCK_SIZE, MIN_COMPRESSION_RATIO); }
flushBuffer(); while ((read = rbc.read(buffer)) != -1) { if (buffer.remaining() == 0) { flushBuffer();
public static OutputStream getOutputStream(OutputStream outputStream, Compression compression) throws IOException { if (compression != null) { switch (compression) { case SNAPPY: return new SnappyFramedOutputStream(outputStream); case NONE: return outputStream; default: throw new IllegalArgumentException("Unsupported compression codec: " + compression); } } return outputStream; } }
public static OutputStream getOutputStream(OutputStream outputStream, Compression compression) throws IOException { if (compression != null) { switch (compression) { case SNAPPY: return new SnappyFramedOutputStream(outputStream); case NONE: return outputStream; default: throw new IllegalArgumentException("Unsupported compression codec: " + compression); } } return outputStream; } }
public ProtobufRecordStreamWriter(TableSchema schema, OutputStream out, CompressOption option) throws IOException { columns = schema.getColumns().toArray(new Column[0]); OutputStream tmpOut; if (option != null) { if (option.algorithm.equals(CompressOption.CompressAlgorithm.ODPS_ZLIB)) { def = new Deflater(); def.setLevel(option.level); def.setStrategy(option.strategy); tmpOut = new DeflaterOutputStream(out, def); } else if (option.algorithm.equals(CompressOption.CompressAlgorithm.ODPS_SNAPPY)) { tmpOut = new SnappyFramedOutputStream(out); } else if (option.algorithm.equals(CompressOption.CompressAlgorithm.ODPS_RAW)) { tmpOut = out; } else { throw new IOException("invalid compression option."); } } else { tmpOut = out; } bou = new CountingOutputStream(tmpOut); this.out = CodedOutputStream.newInstance(bou); }
break; case COMPRESSION_FORMAT_SNAPPY_FRAMED: compressionOut = new SnappyFramedOutputStream(bufferedOut); mimeTypeRef.set("application/x-snappy-framed"); break;