org.xbib.io.compress.zlib.ZInputStream Maven / Gradle / Ivy
package org.xbib.io.compress.zlib;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
public class ZInputStream extends FilterInputStream {
protected ZStream z = new ZStream();
protected int flush = ZConstants.Z_NO_FLUSH;
protected byte[] buf;
protected byte[] buf1 = new byte[1];
protected boolean compress;
private int bufsize;
public ZInputStream(InputStream in) {
this(in, false);
}
public ZInputStream(InputStream in, boolean nowrap) {
super(in);
this.bufsize = 512;
this.buf = new byte[bufsize];
z.inflateInit(nowrap);
compress = false;
z.nextin = buf;
z.nextinindex = 0;
z.availin = 0;
}
public ZInputStream(InputStream in, int bufsize) {
super(in);
this.bufsize = bufsize;
this.buf = new byte[bufsize];
z.inflateInit(false);
compress = false;
z.nextin = buf;
z.nextinindex = 0;
z.availin = 0;
}
public void level(int level) {
z.deflateInit(level);
}
@Override
public int read() throws IOException {
if (read(buf1, 0, 1) == -1) {
return (-1);
}
return (buf1[0] & 0xFF);
}
private boolean nomoreinput = false;
@Override
public int read(byte[] b, int off, int len) throws IOException {
if (len == 0) {
return (0);
}
int err;
z.nextout = b;
z.nextoutindex = off;
z.availout = len;
do {
if ((z.availin == 0) && (!nomoreinput)) { // if buffer is empty and more input is avaiable, refill it
z.nextinindex = 0;
z.availin = in.read(buf, 0, bufsize);//(bufsize
© 2015 - 2025 Weber Informatics LLC | Privacy Policy