001/*
002 * This file is part of lzo-java, an implementation of LZO in Java.
003 * https://github.com/shevek/lzo-java
004 *
005 * The Java portion of this library is:
006 * Copyright (C) 2011 Shevek <shevek@anarres.org>
007 * All Rights Reserved.
008 *
009 * This file is based on a file from hadoop-gpl-compression.
010 *
011 * This library is free software; you can redistribute it and/or
012 * modify it under the terms of the GNU General Public License 
013 * as published by the Free Software Foundation; either version 
014 * 2 of the License, or (at your option) any later version.
015 *
016 * This library is distributed in the hope that it will be useful, 
017 * but WITHOUT ANY WARRANTY; without even the implied warranty
018 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
019 * See the GNU General Public License for more details.
020 *
021 * You should have received a copy of the GNU General Public
022 * License along with the LZO library; see the file COPYING.
023 * If not, see <http://www.gnu.org/licenses/> or write to the
024 * Free Software Foundation, Inc., 51 Franklin Street, Fifth
025 * Floor, Boston, MA 02110-1301, USA.
026 */
027package org.anarres.lzo.hadoop.codec;
028
029import java.io.IOException;
030import java.io.InputStream;
031import java.io.OutputStream;
032import org.apache.hadoop.conf.Configuration;
033import org.apache.hadoop.io.compress.CompressionCodec;
034import org.apache.hadoop.io.compress.CompressionInputStream;
035import org.apache.hadoop.io.compress.CompressionOutputStream;
036import org.apache.hadoop.io.compress.Compressor;
037import org.apache.hadoop.io.compress.Decompressor;
038
039/**
040 * A {@link CompressionCodec} for a streaming
041 * <b>lzo</b> compression/decompression pair compatible with lzop.
042 * http://www.lzop.org/
043 */
044public class LzopCodec extends LzoCodec {
045
046    @Override
047    public CompressionOutputStream createOutputStream(OutputStream out, Compressor compressor) throws IOException {
048        Configuration conf = getConf();
049        LzoCompressor.CompressionStrategy strategy = LzoCodec.getCompressionStrategy(conf);
050        int bufferSize = LzoCodec.getBufferSize(conf);
051        return new LzopOutputStream(out, strategy, bufferSize);
052    }
053
054    @Override
055    public CompressionInputStream createInputStream(InputStream in, Decompressor decompressor) throws IOException {
056        // Ensure native-lzo library is loaded & initialized
057        return new LzopInputStream(in);
058    }
059
060    @Override
061    public Decompressor createDecompressor() {
062        return null;
063    }
064
065    @Override
066    public String getDefaultExtension() {
067        return ".lzo";
068    }
069}