Example usage for org.apache.hadoop.io.compress Compressor reset

List of usage examples for org.apache.hadoop.io.compress Compressor reset

Introduction

In this page you can find the example usage for org.apache.hadoop.io.compress Compressor reset.

Prototype

public void reset();

Source Link

Document

Resets compressor so that a new set of input data can be processed.

Usage

From source file:com.jeffy.hdfs.compression.FileCompressor.java

License:Apache License

/**
 * @param args/* ww  w .ja v  a  2 s.  c  om*/
 * ??????
 * ????
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {
    Configuration conf = new Configuration();
    //??
    CompressionCodecFactory factory = new CompressionCodecFactory(conf);
    // For example for the 'GzipCodec' codec class name the alias are 'gzip' and 'gzipcodec'.
    CompressionCodec codec = factory.getCodecByName(args[0]);
    if (codec == null) {//???
        System.err.println("Comperssion codec not found for " + args[0]);
        System.exit(1);
    }
    String ext = codec.getDefaultExtension();
    Compressor compressor = null;
    try {
        //?CodecPool?Compressor
        compressor = CodecPool.getCompressor(codec);
        for (int i = 1; i < args.length; i++) {
            String filename = args[i] + ext;
            System.out.println("Compression the file " + filename);
            try (FileSystem outFs = FileSystem.get(URI.create(filename), conf);
                    FileSystem inFs = FileSystem.get(URI.create(args[i]), conf);
                    InputStream in = inFs.open(new Path(args[i]))) {//
                //Compressor?
                CompressionOutputStream out = codec.createOutputStream(outFs.create(new Path(filename)),
                        compressor);
                //?????
                IOUtils.copy(in, out);
                out.finish();//?finish()?flush()???
                compressor.reset(); //???????java.io.IOException: write beyond end of stream
            }
        }
    } finally {//?Compressor??
        CodecPool.returnCompressor(compressor);
    }
}

From source file:data.intelligence.platform.yarn.etl.io.CodecPool.java

License:Apache License

/**
 * Return the {@link Compressor} to the pool.
 * /*from   www .  ja  v  a  2 s. c o m*/
 * @param compressor
 *            the <code>Compressor</code> to be returned to the pool
 */
public static void returnCompressor(Compressor compressor) {
    if (compressor == null) {
        return;
    }
    compressor.reset();
    payback(COMPRESSOR_POOL, compressor);
}

From source file:org.apache.tajo.storage.compress.CodecPool.java

License:Apache License

/**
 * Return the {@link Compressor} to the pool.
 *
 * @param compressor/*from  w w  w.  j a  v a2 s .c  om*/
 *          the <code>Compressor</code> to be returned to the pool
 */
public static void returnCompressor(Compressor compressor) {
    if (compressor == null) {
        return;
    }
    // if the compressor can't be reused, don't pool it.
    if (compressor.getClass().isAnnotationPresent(DoNotPool.class)) {
        return;
    }
    compressor.reset();
    payback(COMPRESSOR_POOL, compressor);
}

From source file:org.mrgeo.vector.mrsvector.VectorTileWritable.java

License:Apache License

public static VectorTileWritable toWritable(final VectorTile vector, final CompressionCodec codec,
        final Compressor compressor) throws IOException {
    compressor.reset();

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final CompressionOutputStream cos = codec.createOutputStream(baos, compressor);

    vector.toProtobuf(cos);/*from  w  w w .ja  va  2s .  c om*/

    return new VectorTileWritable(baos.toByteArray());
}