org.xerial.snappy.SnappyOutputStream Java Examples

The following examples show how to use org.xerial.snappy.SnappyOutputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CompressionFactory.java    From galaxy-sdk-java with Apache License 2.0 6 votes vote down vote up
public static DataOutputStream getConpressedOutputStream(MessageCompressionType type, OutputStream outputStream) throws IOException {
  switch (type) {
    case NONE:
      return new DataOutputStream(outputStream);
    case SNAPPY:
      return new DataOutputStream(new SnappyOutputStream(outputStream));
    case GZIP:
      try {
        return new DataOutputStream(new GZIPOutputStream(outputStream));
      } catch (IOException e) {
        LOG.error("Create Gzip OuputStream failed", e);
        throw e;
      }
    default:
      throw new RuntimeException("Unsupported Compression type: " + type);
  }
}
 
Example #2
Source File: SnappyUtils.java    From vertexium with Apache License 2.0 6 votes vote down vote up
public static boolean testSnappySupport() {
    try {
        String testString = "Hello World";

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        SnappyOutputStream out = new SnappyOutputStream(baos);
        out.write(testString.getBytes());
        out.close();
        byte[] bytes = baos.toByteArray();

        ByteArrayInputStream bain = new ByteArrayInputStream(bytes);
        SnappyInputStream in = new SnappyInputStream(bain);
        String result = new String(IOUtils.toBytes(in));
        if (!result.equals(testString)) {
            throw new VertexiumException("uncompressed string did not match compressed string");
        }
        return true;
    } catch (Throwable ex) {
        LOGGER.error("Could not verify support for snappy compression", ex);
        return false;
    }
}
 
Example #3
Source File: RocksDBStore.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Override
public BlobHolder filterPut(byte[] valueToFilter, String tag) {
  if (valueToFilter.length < filterSize) {
    return new Tagged(valueToFilter, tag);
  }
  final Path file = Paths.get(UUID.randomUUID().toString() + ".blob");
  final Path path = base.resolve(file);

  logger.debug("Value size {} bytes larger than limit {} bytes - storing actual data at {}",
    valueToFilter.length, filterSize, path);

  try (final SnappyOutputStream snappyOutputStream = new SnappyOutputStream(Files.newOutputStream(path))){
    snappyOutputStream.write(valueToFilter);
    return new Blob(file, tag);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
Example #4
Source File: CubeImplTest.java    From cubedb with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void save(String saveFileName) throws IOException {
  Kryo kryo = CubeUtils.getKryoWithRegistrations();
  OutputStream zip = new SnappyOutputStream(new FileOutputStream(saveFileName));
  Output output = new Output(zip);
  kryo.writeClassAndObject(output, partitions);
  // zip.closeEntry();
  output.close();
  // zip.close();
}
 
Example #5
Source File: SnappyCompressionInputStreamTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private SnappyInputStream createSnappyInputStream() throws IOException {
  // Create an in-memory ZIP output stream for use by the input stream (to avoid exceptions)
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  SnappyOutputStream sos = new SnappyOutputStream( baos );
  byte[] testBytes = "Test".getBytes();
  sos.write( testBytes );
  ByteArrayInputStream in = new ByteArrayInputStream( baos.toByteArray() );
  sos.close();

  return new SnappyInputStream( in );
}
 
Example #6
Source File: SnappyCompressionProviderTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private SnappyInputStream createSnappyInputStream() throws IOException {
  // Create an in-memory ZIP output stream for use by the input stream (to avoid exceptions)
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  SnappyOutputStream sos = new SnappyOutputStream( baos );
  byte[] testBytes = "Test".getBytes();
  sos.write( testBytes );
  ByteArrayInputStream in = new ByteArrayInputStream( baos.toByteArray() );
  sos.close();

  return new SnappyInputStream( in );
}
 
Example #7
Source File: TezUtils.java    From tez with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a Configuration to compressed ByteString using Protocol buffer
 *
 * @param conf
 *          : Configuration to be converted
 * @return PB ByteString (compressed)
 * @throws java.io.IOException
 */
public static ByteString createByteStringFromConf(Configuration conf) throws IOException {
  Objects.requireNonNull(conf, "Configuration must be specified");
  ByteString.Output os = ByteString.newOutput();
  SnappyOutputStream compressOs = new SnappyOutputStream(os);
  try {
    writeConfInPB(compressOs, conf);
  } finally {
    if (compressOs != null) {
      compressOs.close();
    }
  }
  return os.toByteString();
}
 
Example #8
Source File: SerializableUtils.java    From eagle with Apache License 2.0 5 votes vote down vote up
/**
 * Serializes the argument into an array of bytes, and returns it.
 *
 * @throws IllegalArgumentException if there are errors when serializing
 */
public static byte[] serializeToCompressedByteArray(Object value) {
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        try (ObjectOutputStream oos = new ObjectOutputStream(new SnappyOutputStream(buffer))) {
            oos.writeObject(value);
        }
        return buffer.toByteArray();
    } catch (IOException exn) {
        throw new IllegalArgumentException(
            "unable to serialize " + value,
            exn);
    }
}
 
Example #9
Source File: SerializableUtils.java    From eagle with Apache License 2.0 5 votes vote down vote up
/**
 * Serializes the argument into an array of bytes, and returns it.
 *
 * @throws IllegalArgumentException if there are errors when serializing
 */
public static byte[] serializeToCompressedByteArray(Object value) {
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        try (ObjectOutputStream oos = new ObjectOutputStream(new SnappyOutputStream(buffer))) {
            oos.writeObject(value);
        }
        return buffer.toByteArray();
    } catch (IOException exn) {
        throw new IllegalArgumentException(
            "unable to serialize " + value,
            exn);
    }
}
 
Example #10
Source File: GcsSinkTask.java    From aiven-kafka-connect-gcs with GNU Affero General Public License v3.0 5 votes vote down vote up
private OutputStream getCompressedStream(final OutputStream outputStream) throws IOException {
    Objects.requireNonNull(outputStream, "outputStream cannot be null");

    switch (config.getCompressionType()) {
        case ZSTD:
            return new ZstdOutputStream(outputStream);
        case GZIP:
            return new GZIPOutputStream(outputStream);
        case SNAPPY:
            return new SnappyOutputStream(outputStream);
        default:
            return outputStream;
    }
}
 
Example #11
Source File: SerializableUtils.java    From beam with Apache License 2.0 5 votes vote down vote up
/**
 * Serializes the argument into an array of bytes, and returns it.
 *
 * @throws IllegalArgumentException if there are errors when serializing
 */
public static byte[] serializeToByteArray(Serializable value) {
  try {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    try (ObjectOutputStream oos = new ObjectOutputStream(new SnappyOutputStream(buffer))) {
      oos.writeObject(value);
    }
    return buffer.toByteArray();
  } catch (IOException exn) {
    throw new IllegalArgumentException("unable to serialize " + value, exn);
  }
}
 
Example #12
Source File: NamespaceServiceImpl.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private OutputStream wrapIfNeeded(OutputStream o) throws IOException {
  switch (splitCompression) {
    case UNCOMPRESSED:
      return o;
    case SNAPPY:
      return new SnappyOutputStream(o);
    default:
      throw new IllegalArgumentException(String.format("Unsupported compression type: %s", splitCompression));
  }
}
 
Example #13
Source File: KafkaCompressionCodecFactory.java    From joyqueue with Apache License 2.0 5 votes vote down vote up
public static OutputStream apply(KafkaCompressionCodec codec, OutputStream stream, byte messageVersion) throws IOException {
    switch (codec) {
        case GZIPCompressionCodec:
            return new GZIPOutputStream(stream);
        case SnappyCompressionCodec:
            return new SnappyOutputStream(stream);
        case LZ4CompressionCodec:
            return new KafkaLZ4BlockOutputStream(stream);
        default:
            throw new RuntimeException(String.format("unknown codec: %s", codec));
    }
}
 
Example #14
Source File: KafkaCompressionCodecFactory.java    From joyqueue with Apache License 2.0 5 votes vote down vote up
public static OutputStream apply(KafkaCompressionCodec codec, OutputStream stream, byte messageMagic) throws IOException {
    switch (codec) {
        case GZIPCompressionCodec:
            return new GZIPOutputStream(stream);
        case SnappyCompressionCodec:
            return new SnappyOutputStream(stream);
        case LZ4CompressionCodec:
            return new KafkaLZ4BlockOutputStream(stream);
        default:
            throw new UnknownCodecException(String.format("unknown codec: %s", codec));
    }
}
 
Example #15
Source File: KafkaCompressionCodecFactory.java    From joyqueue with Apache License 2.0 5 votes vote down vote up
public static OutputStream apply(KafkaCompressionCodec codec, OutputStream stream, byte messageVersion) throws IOException {
    switch (codec) {
        case GZIPCompressionCodec:
            return new GZIPOutputStream(stream);
        case SnappyCompressionCodec:
            return new SnappyOutputStream(stream);
        case LZ4CompressionCodec:
            return new KafkaLZ4BlockOutputStream(stream);
        default:
            throw new RuntimeException(String.format("unknown codec: %s", codec));
    }
}
 
Example #16
Source File: SnappyCompressionInputStreamTest.java    From hop with Apache License 2.0 5 votes vote down vote up
private SnappyInputStream createSnappyInputStream() throws IOException {
  // Create an in-memory ZIP output stream for use by the input stream (to avoid exceptions)
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  SnappyOutputStream sos = new SnappyOutputStream( baos );
  byte[] testBytes = "Test".getBytes();
  sos.write( testBytes );
  ByteArrayInputStream in = new ByteArrayInputStream( baos.toByteArray() );
  sos.close();

  return new SnappyInputStream( in );
}
 
Example #17
Source File: SnappyCompressionProviderTest.java    From hop with Apache License 2.0 5 votes vote down vote up
private SnappyInputStream createSnappyInputStream() throws IOException {
  // Create an in-memory ZIP output stream for use by the input stream (to avoid exceptions)
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  SnappyOutputStream sos = new SnappyOutputStream( baos );
  byte[] testBytes = "Test".getBytes();
  sos.write( testBytes );
  ByteArrayInputStream in = new ByteArrayInputStream( baos.toByteArray() );
  sos.close();

  return new SnappyInputStream( in );
}
 
Example #18
Source File: SnappyRunner.java    From x-pipe with Apache License 2.0 4 votes vote down vote up
@Override
protected OutputStream getCompressOutputStream(OutputStream outputStream) {
    return new SnappyOutputStream(outputStream);
}
 
Example #19
Source File: PhysicalPlanReader.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
public OutputStream compress(OutputStream output) {
  return new SnappyOutputStream(output);
}
 
Example #20
Source File: SnappyCompression.java    From luxun with Apache License 2.0 4 votes vote down vote up
public SnappyCompression(InputStream inputStream, OutputStream outputStream) throws IOException {
	super(inputStream != null ? new SnappyInputStream(inputStream) : null, //
               outputStream != null ? new SnappyOutputStream(outputStream) : null);
}
 
Example #21
Source File: SnappyCompressionOutputStream.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public void close() throws IOException {
  SnappyOutputStream zos = (SnappyOutputStream) delegate;
  zos.flush();
  zos.close();
}
 
Example #22
Source File: SnappyCompressionOutputStream.java    From hop with Apache License 2.0 4 votes vote down vote up
@Override
public void close() throws IOException {
  SnappyOutputStream zos = (SnappyOutputStream) delegate;
  zos.flush();
  zos.close();
}