All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xiaomi.infra.galaxy.api.io.CompressionStreamAdaptor Maven / Gradle / Ivy

There is a newer version: 1.3.2
Show newest version
package com.xiaomi.infra.galaxy.api.io;

import com.xiaomi.infra.galaxy.io.thrift.Compression;
import org.xerial.snappy.SnappyFramedInputStream;
import org.xerial.snappy.SnappyFramedOutputStream;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class CompressionStreamAdaptor {
  public static InputStream getInputStream(InputStream inputStream, Compression compression)
      throws IOException {
    if (compression != null) {
      switch (compression) {
      case SNAPPY:
        return new SnappyFramedInputStream(inputStream);
      case NONE:
        return inputStream;
      default:
        throw new IllegalArgumentException("Unsupported compression codec: " + compression);
      }
    }
    return inputStream;
  }

  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;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy