Search in sources :

Example 1 with Compression

use of com.baidu.hugegraph.loader.source.file.Compression in project incubator-hugegraph-toolchain by apache.

the class FileLineFetcher method createCompressReader.

private static Reader createCompressReader(InputStream stream, FileSource source) throws Exception {
    Compression compression = source.compression();
    String charset = source.charset();
    switch(compression) {
        case NONE:
            return new InputStreamReader(stream, charset);
        case SNAPPY_RAW:
            Configuration config = new Configuration();
            CompressionCodec codec = ReflectionUtils.newInstance(SnappyCodec.class, config);
            CompressionInputStream sis = codec.createInputStream(stream, codec.createDecompressor());
            return new InputStreamReader(sis, charset);
        case GZIP:
        case BZ2:
        case XZ:
        case LZMA:
        case SNAPPY_FRAMED:
        case Z:
        case DEFLATE:
        case LZ4_BLOCK:
        case LZ4_FRAMED:
            CompressorStreamFactory factory = new CompressorStreamFactory();
            CompressorInputStream cis = factory.createCompressorInputStream(compression.string(), stream);
            return new InputStreamReader(cis, charset);
        default:
            throw new LoadException("Unsupported compression format '%s'", compression);
    }
}
Also used : Compression(com.baidu.hugegraph.loader.source.file.Compression) InputStreamReader(java.io.InputStreamReader) Configuration(org.apache.hadoop.conf.Configuration) CompressionInputStream(org.apache.hadoop.io.compress.CompressionInputStream) CompressorStreamFactory(org.apache.commons.compress.compressors.CompressorStreamFactory) CompressionCodec(org.apache.hadoop.io.compress.CompressionCodec) CompressorInputStream(org.apache.commons.compress.compressors.CompressorInputStream) LoadException(com.baidu.hugegraph.loader.exception.LoadException)

Aggregations

LoadException (com.baidu.hugegraph.loader.exception.LoadException)1 Compression (com.baidu.hugegraph.loader.source.file.Compression)1 InputStreamReader (java.io.InputStreamReader)1 CompressorInputStream (org.apache.commons.compress.compressors.CompressorInputStream)1 CompressorStreamFactory (org.apache.commons.compress.compressors.CompressorStreamFactory)1 Configuration (org.apache.hadoop.conf.Configuration)1 CompressionCodec (org.apache.hadoop.io.compress.CompressionCodec)1 CompressionInputStream (org.apache.hadoop.io.compress.CompressionInputStream)1