@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; }
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); }
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); }
private static OutputStream wrapOutputStream(OutputStream outputStream) throws IOException { switch (GZTYPE) { case 0: // no compression return outputStream; case 1: // LZF return new LZFOutputStream(outputStream); case 2: // Snappy return new SnappyOutputStream(outputStream); default: throw new RuntimeException("Unknown compression type: " + GZTYPE); } }
public byte[] compressStream(byte[] source) { OutputStream compressStream = null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); compressStream = new LZFOutputStream(baos); compressStream.write(source); compressStream.flush(); byte[] compressed = baos.toByteArray(); return compressed; } catch (IOException e) { throw new RuntimeException(e); } finally { try { if (compressStream != null) { compressStream.close(); } } catch (IOException e) { } } }
public static OutputStream compressingStream(OutputStream out, Compression comp) throws IOException { if (comp != null) { switch (comp) { case NONE: break; case LZF: return new LZFOutputStream(out); case GZIP: return new OptimizedGZIPOutputStream(out); default: // sanity check throw new IllegalArgumentException("Unrecognized compression type: "+comp); } } return out; }
@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; }
private ByteArrayOutputStream compress(byte[] bs) throws IOException { ByteArrayOutputStream c = new ByteArrayOutputStream(); OutputStream compressingOut = new LZFOutputStream(c); compressingOut.write(bs); compressingOut.close(); return c; } }
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 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 static @Nonnull OutputStream compressOutputStream(@Nonnull OutputStream out, @Nonnull CompressionType type) throws IOException { switch (type) { case GZIP: out = new GZIPOutputStream(out, BUFFER_SIZE); break; case LZF: out = new LZFOutputStream(out); break; case SNAPPY: out = new SnappyOutputStream(out); break; case BZIP2: out = new BZip2CompressorOutputStream(out); break; case LZMA: throw new UnsupportedOperationException( "Writing .lzma files is no longer supported. Use .xz format instead"); case XZ: out = new XZOutputStream(out, new LZMA2Options()); break; default: throw new IllegalStateException("Unknown compression type " + type); } return out; }
@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 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(); } } }
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()); }
break; case 3: os = new LZFOutputStream(out); break; case 4:
compressedOutput = new LZFOutputStream(output); long progress = 0L;
compressedOutput = new LZFOutputStream(output); long progress = 0L;
compressedOutput = new LZFOutputStream(output); long progress = 0L;
compressedOutput = new LZFOutputStream(Channels.newOutputStream(channel)); long progress = 0L;