@Override public void commit() { if (isHeadersCommitted) return; isHeadersCommitted = true; // constructor writes to underlying OutputStream causing headers to be written. // so we swap compressed OutputStream in when we are ready to write. lzf = new LZFOutputStream(delegate); delegate = lzf; }
@Override public void write(RevObject o, OutputStream out) throws IOException { // compress the stream LZFOutputStream deflatedOutputStream = new LZFOutputStream(out); deflatedOutputStream.setFinishBlockOnFlush(true); factory.write(o, deflatedOutputStream); deflatedOutputStream.flush(); }
public void write(final FileChannel in) throws IOException { MappedByteBuffer src = in.map(MapMode.READ_ONLY, 0, in.size()); write(src); }
@Override public void write(final int singleByte) throws IOException { checkNotClosed(); if (_position >= _outputBuffer.length) { writeCompressedBlock(); } _outputBuffer[_position++] = (byte) singleByte; }
@Override public boolean put(ObjectId objectId, InputStream raw) { Preconditions.checkNotNull(objectId); Preconditions.checkNotNull(raw); Preconditions.checkArgument(!objectId.isNull(), "ObjectId is NULL"); ByteArrayOutputStream rawOut = new ByteArrayOutputStream(); LZFOutputStream cOut = new LZFOutputStream(rawOut); try { ByteStreams.copy(raw, cOut); cOut.flush(); cOut.close(); } catch (IOException e) { throw Throwables.propagate(e); } final byte[] rawData = rawOut.toByteArray(); final boolean inserted = putInternal(objectId, rawData); return inserted; }
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(); } } }
private byte[] toBytes(RevObject object) { ObjectWriter<RevObject> writer = serializers.createObjectWriter(object.getType()); ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); LZFOutputStream cOut = new LZFOutputStream(byteStream); try { writer.write(object, cOut); } catch (IOException e) { throw new RuntimeException(e); } try { cOut.close(); } catch (IOException e) { throw Throwables.propagate(e); } return byteStream.toByteArray(); }
@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; }
context.proceed(); } finally { if (lzfOutputStream.getLzf() != null) lzfOutputStream.getLzf().flush(); context.setOutputStream(old);
protected void writeObject(RevObject object, OutputStream target) { ObjectWriter<RevObject> writer = serializationFactory.createObjectWriter(object.getType()); LZFOutputStream cOut = new LZFOutputStream(target); try { writer.write(object, cOut); } catch (IOException e) { throw Throwables.propagate(e); } finally { try { cOut.flush(); cOut.close(); } catch (Exception e) { throw Throwables.propagate(e); } } int size = ((ByteArrayOutputStream) target).size(); //System.err.printf("%d,%s,%s\n", size, object.getId(), object.getType()); }
@Override public void write(final int singleByte) throws IOException { checkNotClosed(); if (_position >= _outputBuffer.length) { writeCompressedBlock(); } _outputBuffer[_position++] = (byte) singleByte; }
@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; }
private DataOutputStream createOutStream(Path tmpFile) throws IOException { OutputStream outStream = Files.newOutputStream(tmpFile, StandardOpenOption.APPEND); outStream = new BufferedOutputStream(outStream, 16 * 1024); if (this.compress) { outStream = new LZFOutputStream(outStream); } return new DataOutputStream(outStream); }
@Override public void write(RevObject o, OutputStream out) throws IOException { // compress the stream LZFOutputStream deflatedOutputStream = new LZFOutputStream(out); deflatedOutputStream.setFinishBlockOnFlush(true); factory.write(o, deflatedOutputStream); deflatedOutputStream.flush(); }
@Override public void write(final int singleByte) throws IOException { checkNotClosed(); if (_position >= _outputBuffer.length) { writeCompressedBlock(); } _outputBuffer[_position++] = (byte) singleByte; }
@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); }
private DataOutputStream createOutStream(Path tmpFile) throws IOException { OutputStream outStream = Files.newOutputStream(tmpFile, StandardOpenOption.APPEND); outStream = new BufferedOutputStream(outStream, 16 * 1024); if (this.compress) { outStream = new LZFOutputStream(outStream); } return new DataOutputStream(outStream); }
/** * Method that can be used to force completion of the current block, * which means that all buffered data will be compressed into an * LZF block. This typically results in lower compression ratio * as larger blocks compress better; but may be necessary for * network connections to ensure timely sending of data. */ public LZFOutputStream finishBlock() throws IOException { checkNotClosed(); if (_position > 0) { writeCompressedBlock(); } return this; }
public void write(final FileChannel in) throws IOException { MappedByteBuffer src = in.map(MapMode.READ_ONLY, 0, in.size()); write(src); }