public void write(final FileChannel in) throws IOException { MappedByteBuffer src = in.map(MapMode.READ_ONLY, 0, in.size()); write(src); }
@Override public synchronized int write(final ByteBuffer src) throws IOException { int r = src.remaining(); if (r <= 0) { return r; } writeCompressedBlock(); // will flush _outputBuffer if (src.hasArray()) { // direct compression from backing array write(src.array(), src.arrayOffset(), src.limit() - src.arrayOffset()); } else { // need to copy to heap array first while (src.hasRemaining()) { int toRead = Math.min(src.remaining(), _outputBuffer.length); src.get(_outputBuffer, 0, toRead); _position = toRead; writeCompressedBlock(); } } return r; }
@Override public synchronized int write(final ByteBuffer src) throws IOException { int r = src.remaining(); if (r <= 0) { return r; } writeCompressedBlock(); // will flush _outputBuffer if (src.hasArray()) { // direct compression from backing array write(src.array(), src.arrayOffset(), src.limit() - src.arrayOffset()); } else { // need to copy to heap array first while (src.hasRemaining()) { int toRead = Math.min(src.remaining(), _outputBuffer.length); src.get(_outputBuffer, 0, toRead); _position = toRead; writeCompressedBlock(); } } return r; }
public void write(final FileChannel in) throws IOException { MappedByteBuffer src = in.map(MapMode.READ_ONLY, 0, in.size()); write(src); }
@Override public synchronized int write(final ByteBuffer src) throws IOException { int r = src.remaining(); if (r <= 0) { return r; } writeCompressedBlock(); // will flush _outputBuffer if (src.hasArray()) { // direct compression from backing array write(src.array(), src.arrayOffset(), src.limit() - src.arrayOffset()); } else { // need to copy to heap array first while (src.hasRemaining()) { int toRead = Math.min(src.remaining(), _outputBuffer.length); src.get(_outputBuffer, 0, toRead); _position = toRead; writeCompressedBlock(); } } return r; }
public void write(final FileChannel in) throws IOException { MappedByteBuffer src = in.map(MapMode.READ_ONLY, 0, in.size()); write(src); }
public static void compress(InputStream in, OutputStream out) throws IOException { LZFOutputStream compressor = null; boolean success = true; try { compressor = new LZFOutputStream(out); byte[] buf = ThreadLocalByteBuffer.getBuffer(); int len; while ((len = in.read(buf)) != -1) { compressor.write(buf, 0, len); } compressor.close(); } catch (IOException e) { success = false; throw new IllegalStateException(e.getMessage(), e); } finally { if (!success && (compressor != null)) { compressor.close(); } } }