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

org.apache.commons.compress.compressors.brotli.BrotliCompressorInputStream Maven / Gradle / Ivy

There is a newer version: 6.5.21
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.commons.compress.compressors.brotli;

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

import org.apache.commons.compress.compressors.CompressorInputStream;

/**
 * {@link CompressorInputStream} implementation to decode Brotli encoded stream.
 * Library relies on Google brotli
 * 
 * @since 1.14
 */
public class BrotliCompressorInputStream extends CompressorInputStream {
    
    private final org.brotli.dec.BrotliInputStream decIS;

    public BrotliCompressorInputStream(final InputStream in) throws IOException {
        this.decIS = new org.brotli.dec.BrotliInputStream(in);
    }

    @Override
    public int available() throws IOException {
        return decIS.available();
    }

    @Override
    public void close() throws IOException {
        decIS.close();
    }

    @Override
    public int read(final byte[] b) throws IOException {
        return decIS.read(b);
    }

    @Override
    public long skip(final long n) throws IOException {
        return decIS.skip(n);
    }

    @Override
    public void mark(final int readlimit) {
        decIS.mark(readlimit);
    }

    @Override
    public boolean markSupported() {
        return decIS.markSupported();
    }

    @Override
    public int read() throws IOException {
        final int ret = decIS.read();
        count(ret == -1 ? 0 : 1);
        return ret;
    }

    @Override
    public int read(final byte[] buf, final int off, final int len) throws IOException {
        final int ret = decIS.read(buf, off, len);
        count(ret);
        return ret;
    }

    @Override
    public String toString() {
        return decIS.toString();
    }

    @Override
    public void reset() throws IOException {
        decIS.reset();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy