下面列出了java.util.zip.InflaterInputStream#close ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public byte[] inflate(InputStream stream) throws IOException {
InflaterInputStream inputStream = new InflaterInputStream(stream);
FastByteArrayOutputStream outputStream = ThreadCache.fbaos.get();
outputStream.reset();
int length;
byte[] result;
byte[] buffer = buf.get();
try {
while ((length = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, length);
}
} finally {
result = outputStream.toByteArray();
outputStream.flush();
outputStream.close();
inputStream.close();
}
return result;
}
public static byte[] inflate(InputStream stream) throws IOException {
InflaterInputStream inputStream = new InflaterInputStream(stream);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
try {
while ((length = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, length);
}
} finally {
buffer = outputStream.toByteArray();
outputStream.flush();
outputStream.close();
inputStream.close();
}
return buffer;
}
/**
* 解压缩
* @param is 输入流
* @return byte[] 解压缩后的数据
*/
public static byte[] decompress(InputStream is) {
InflaterInputStream iis = new InflaterInputStream(is);
ByteArrayOutputStream o = new ByteArrayOutputStream(1024);
byte[] result = null;
try {
int i = 1024;
byte[] buf = new byte[i];
while ((i = iis.read(buf, 0, i)) > 0) {
o.write(buf, 0, i);
}
result = o.toByteArray();
o.close();
iis.close();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
/**
* A helper to FlateDecode.
*
* @param in the input data
* @param strict <CODE>true</CODE> to read a correct stream. <CODE>false</CODE> to try to read a
* corrupted stream
* @return the decoded data
*/
public static byte[] FlateDecode(byte in[], boolean strict) {
ByteArrayInputStream stream = new ByteArrayInputStream(in);
InflaterInputStream zip = new InflaterInputStream(stream);
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte b[] = new byte[strict ? 4092 : 1];
try {
int n;
while ((n = zip.read(b)) >= 0) {
out.write(b, 0, n);
}
zip.close();
out.close();
return out.toByteArray();
} catch (Exception e) {
if (strict) {
return null;
}
return out.toByteArray();
}
}
/** A helper to FlateDecode.
* @param in the input data
* @param strict <CODE>true</CODE> to read a correct stream. <CODE>false</CODE>
* to try to read a corrupted stream
* @return the decoded data
*/
public static byte[] FlateDecode(byte in[], boolean strict) {
ByteArrayInputStream stream = new ByteArrayInputStream(in);
InflaterInputStream zip = new InflaterInputStream(stream);
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte b[] = new byte[strict ? 4092 : 1];
try {
int n;
while ((n = zip.read(b)) >= 0) {
out.write(b, 0, n);
}
zip.close();
out.close();
return out.toByteArray();
}
catch (Exception e) {
if (strict)
return null;
return out.toByteArray();
}
}
@Override
public byte[] inflate(InputStream stream) throws IOException {
InflaterInputStream inputStream = new InflaterInputStream(stream);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
try {
while ((length = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, length);
}
} finally {
buffer = outputStream.toByteArray();
outputStream.flush();
outputStream.close();
inputStream.close();
}
return buffer;
}
public static byte[] inflate(InputStream stream) throws IOException {
InflaterInputStream inputStream = new InflaterInputStream(stream);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, length);
}
buffer = outputStream.toByteArray();
outputStream.flush();
outputStream.close();
inputStream.close();
return buffer;
}
@Override
synchronized public byte[] inflate(InputStream stream) throws IOException {
InflaterInputStream inputStream = new InflaterInputStream(stream);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(BUFFER_SIZE);
byte[] bufferOut;
int length;
try {
while ((length = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, length);
}
} finally {
outputStream.flush();
bufferOut = outputStream.toByteArray();
outputStream.close();
inputStream.close();
}
return bufferOut;
}
private byte[] inflate(byte[] compressedData) {
byte[] result = null;
if (compressedData != null) {
try {
ByteArrayInputStream source = new ByteArrayInputStream(compressedData);
DataInputStream headerIn = new DataInputStream(source);
int version = headerIn.readInt();
if (version > mCurrentBlobVersion) {
Log.w(TAG, "Saved payload from unrecognized version " + version);
return null;
}
InflaterInputStream in = new InflaterInputStream(source);
ByteArrayOutputStream inflated = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
int nRead;
while ((nRead = in.read(buffer)) > 0) {
inflated.write(buffer, 0, nRead);
}
in.close();
inflated.flush();
result = inflated.toByteArray();
if (DEBUG) {
Log.v(TAG, "Inflated " + compressedData.length + " bytes to " + result.length);
}
} catch (IOException e) {
// result is still null here
Log.w(TAG, "Unable to process restored payload: " + e.getMessage());
}
}
return result;
}
public static byte[] b(byte[] bArr) {
int i = 0;
if (bArr == null) {
return null;
}
InputStream byteArrayInputStream = new ByteArrayInputStream(bArr);
InflaterInputStream inflaterInputStream = new InflaterInputStream(byteArrayInputStream);
Object obj = new byte[0];
Object obj2 = new byte[1024];
while (true) {
try {
Object obj3;
int read = inflaterInputStream.read(obj2);
if (read > 0) {
i += read;
obj3 = new byte[i];
System.arraycopy(obj, 0, obj3, 0, obj.length);
System.arraycopy(obj2, 0, obj3, obj.length, read);
} else {
obj3 = obj;
}
if (read <= 0) {
try {
byteArrayInputStream.close();
inflaterInputStream.close();
return obj3;
} catch (IOException e) {
return null;
}
}
obj = obj3;
} catch (Exception e2) {
return null;
}
}
}
@Override
public Object apply(WarpScriptStack stack) throws WarpScriptException {
Object o = stack.pop();
if (!(o instanceof byte[])) {
throw new WarpScriptException(getName() + " operates on a byte array.");
}
byte[] data = (byte[]) o;
ByteArrayInputStream bin = new ByteArrayInputStream(data);
ByteArrayOutputStream decompressed = new ByteArrayOutputStream(data.length);
byte[] buf = new byte[1024];
try {
InflaterInputStream in = new InflaterInputStream(bin);
while(true) {
int len = in.read(buf);
if (len < 0) {
break;
}
decompressed.write(buf, 0, len);
}
in.close();
} catch (IOException ioe) {
throw new WarpScriptException(getName() + " encountered an error while decompressing.", ioe);
}
stack.push(decompressed.toByteArray());
return stack;
}
public static void main(String args[]) throws Exception{
/* initialise stuff */
File fn = new File("x.ReadBounds");
FileOutputStream fout = new FileOutputStream(fn);
for (int i = 0; i < 32; i++) {
fout.write(i);
}
fout.close();
byte b[] = new byte[64];
for(int i = 0; i < 64; i++) {
b[i] = 1;
}
/* test all input streams */
FileInputStream fis = new FileInputStream(fn);
doTest(fis);
doTest1(fis);
fis.close();
BufferedInputStream bis =
new BufferedInputStream(new MyInputStream(1024));
doTest(bis);
doTest1(bis);
bis.close();
ByteArrayInputStream bais = new ByteArrayInputStream(b);
doTest(bais);
doTest1(bais);
bais.close();
FileOutputStream fos = new FileOutputStream(fn);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeInt(12345);
oos.writeObject("Today");
oos.writeObject(new Integer(32));
oos.close();
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fn));
doTest(ois);
doTest1(ois);
ois.close();
DataInputStream dis = new DataInputStream(new MyInputStream(1024));
doTest(dis);
doTest1(dis);
dis.close();
LineNumberInputStream lis =
new LineNumberInputStream(new MyInputStream(1024));
doTest(lis);
doTest1(lis);
lis.close();
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream();
pos.connect(pis);
pos.write(b, 0, 64);
doTest(pis);
doTest1(pis);
pis.close();
PushbackInputStream pbis =
new PushbackInputStream(new MyInputStream(1024));
doTest(pbis);
doTest1(pbis);
pbis.close();
StringBufferInputStream sbis =
new StringBufferInputStream(new String(b));
doTest(sbis);
doTest1(sbis);
sbis.close();
SequenceInputStream sis =
new SequenceInputStream(new MyInputStream(1024),
new MyInputStream(1024));
doTest(sis);
doTest1(sis);
sis.close();
ZipInputStream zis = new ZipInputStream(new FileInputStream(fn));
doTest(zis);
doTest1(zis);
zis.close();
byte[] data = new byte[256];
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DeflaterOutputStream dos = new DeflaterOutputStream(bos);
dos.write(data, 0, data.length);
dos.close();
InflaterInputStream ifs = new InflaterInputStream
(new ByteArrayInputStream(bos.toByteArray()));
doTest(ifs);
doTest1(ifs);
ifs.close();
/* cleanup */
fn.delete();
}
public static void main(String args[]) throws Exception{
/* initialise stuff */
File fn = new File("x.ReadBounds");
FileOutputStream fout = new FileOutputStream(fn);
for (int i = 0; i < 32; i++) {
fout.write(i);
}
fout.close();
byte b[] = new byte[64];
for(int i = 0; i < 64; i++) {
b[i] = 1;
}
/* test all input streams */
FileInputStream fis = new FileInputStream(fn);
doTest(fis);
doTest1(fis);
fis.close();
BufferedInputStream bis =
new BufferedInputStream(new MyInputStream(1024));
doTest(bis);
doTest1(bis);
bis.close();
ByteArrayInputStream bais = new ByteArrayInputStream(b);
doTest(bais);
doTest1(bais);
bais.close();
FileOutputStream fos = new FileOutputStream(fn);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeInt(12345);
oos.writeObject("Today");
oos.writeObject(new Integer(32));
oos.close();
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fn));
doTest(ois);
doTest1(ois);
ois.close();
DataInputStream dis = new DataInputStream(new MyInputStream(1024));
doTest(dis);
doTest1(dis);
dis.close();
LineNumberInputStream lis =
new LineNumberInputStream(new MyInputStream(1024));
doTest(lis);
doTest1(lis);
lis.close();
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream();
pos.connect(pis);
pos.write(b, 0, 64);
doTest(pis);
doTest1(pis);
pis.close();
PushbackInputStream pbis =
new PushbackInputStream(new MyInputStream(1024));
doTest(pbis);
doTest1(pbis);
pbis.close();
StringBufferInputStream sbis =
new StringBufferInputStream(new String(b));
doTest(sbis);
doTest1(sbis);
sbis.close();
SequenceInputStream sis =
new SequenceInputStream(new MyInputStream(1024),
new MyInputStream(1024));
doTest(sis);
doTest1(sis);
sis.close();
ZipInputStream zis = new ZipInputStream(new FileInputStream(fn));
doTest(zis);
doTest1(zis);
zis.close();
byte[] data = new byte[256];
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DeflaterOutputStream dos = new DeflaterOutputStream(bos);
dos.write(data, 0, data.length);
dos.close();
InflaterInputStream ifs = new InflaterInputStream
(new ByteArrayInputStream(bos.toByteArray()));
doTest(ifs);
doTest1(ifs);
ifs.close();
/* cleanup */
fn.delete();
}
public static void main(String args[]) throws Exception{
/* initialise stuff */
File fn = new File("x.ReadBounds");
FileOutputStream fout = new FileOutputStream(fn);
for (int i = 0; i < 32; i++) {
fout.write(i);
}
fout.close();
byte b[] = new byte[64];
for(int i = 0; i < 64; i++) {
b[i] = 1;
}
/* test all input streams */
FileInputStream fis = new FileInputStream(fn);
doTest(fis);
doTest1(fis);
fis.close();
BufferedInputStream bis =
new BufferedInputStream(new MyInputStream(1024));
doTest(bis);
doTest1(bis);
bis.close();
ByteArrayInputStream bais = new ByteArrayInputStream(b);
doTest(bais);
doTest1(bais);
bais.close();
FileOutputStream fos = new FileOutputStream(fn);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeInt(12345);
oos.writeObject("Today");
oos.writeObject(new Integer(32));
oos.close();
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fn));
doTest(ois);
doTest1(ois);
ois.close();
DataInputStream dis = new DataInputStream(new MyInputStream(1024));
doTest(dis);
doTest1(dis);
dis.close();
LineNumberInputStream lis =
new LineNumberInputStream(new MyInputStream(1024));
doTest(lis);
doTest1(lis);
lis.close();
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream();
pos.connect(pis);
pos.write(b, 0, 64);
doTest(pis);
doTest1(pis);
pis.close();
PushbackInputStream pbis =
new PushbackInputStream(new MyInputStream(1024));
doTest(pbis);
doTest1(pbis);
pbis.close();
StringBufferInputStream sbis =
new StringBufferInputStream(new String(b));
doTest(sbis);
doTest1(sbis);
sbis.close();
SequenceInputStream sis =
new SequenceInputStream(new MyInputStream(1024),
new MyInputStream(1024));
doTest(sis);
doTest1(sis);
sis.close();
ZipInputStream zis = new ZipInputStream(new FileInputStream(fn));
doTest(zis);
doTest1(zis);
zis.close();
byte[] data = new byte[256];
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DeflaterOutputStream dos = new DeflaterOutputStream(bos);
dos.write(data, 0, data.length);
dos.close();
InflaterInputStream ifs = new InflaterInputStream
(new ByteArrayInputStream(bos.toByteArray()));
doTest(ifs);
doTest1(ifs);
ifs.close();
/* cleanup */
fn.delete();
}
public static void main(String args[]) throws Exception{
/* initialise stuff */
File fn = new File("x.ReadBounds");
FileOutputStream fout = new FileOutputStream(fn);
for (int i = 0; i < 32; i++) {
fout.write(i);
}
fout.close();
byte b[] = new byte[64];
for(int i = 0; i < 64; i++) {
b[i] = 1;
}
/* test all input streams */
FileInputStream fis = new FileInputStream(fn);
doTest(fis);
doTest1(fis);
fis.close();
BufferedInputStream bis =
new BufferedInputStream(new MyInputStream(1024));
doTest(bis);
doTest1(bis);
bis.close();
ByteArrayInputStream bais = new ByteArrayInputStream(b);
doTest(bais);
doTest1(bais);
bais.close();
FileOutputStream fos = new FileOutputStream(fn);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeInt(12345);
oos.writeObject("Today");
oos.writeObject(new Integer(32));
oos.close();
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fn));
doTest(ois);
doTest1(ois);
ois.close();
DataInputStream dis = new DataInputStream(new MyInputStream(1024));
doTest(dis);
doTest1(dis);
dis.close();
LineNumberInputStream lis =
new LineNumberInputStream(new MyInputStream(1024));
doTest(lis);
doTest1(lis);
lis.close();
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream();
pos.connect(pis);
pos.write(b, 0, 64);
doTest(pis);
doTest1(pis);
pis.close();
PushbackInputStream pbis =
new PushbackInputStream(new MyInputStream(1024));
doTest(pbis);
doTest1(pbis);
pbis.close();
StringBufferInputStream sbis =
new StringBufferInputStream(new String(b));
doTest(sbis);
doTest1(sbis);
sbis.close();
SequenceInputStream sis =
new SequenceInputStream(new MyInputStream(1024),
new MyInputStream(1024));
doTest(sis);
doTest1(sis);
sis.close();
ZipInputStream zis = new ZipInputStream(new FileInputStream(fn));
doTest(zis);
doTest1(zis);
zis.close();
byte[] data = new byte[256];
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DeflaterOutputStream dos = new DeflaterOutputStream(bos);
dos.write(data, 0, data.length);
dos.close();
InflaterInputStream ifs = new InflaterInputStream
(new ByteArrayInputStream(bos.toByteArray()));
doTest(ifs);
doTest1(ifs);
ifs.close();
/* cleanup */
fn.delete();
}
public static void main(String args[]) throws Exception{
/* initialise stuff */
File fn = new File("x.ReadBounds");
FileOutputStream fout = new FileOutputStream(fn);
for (int i = 0; i < 32; i++) {
fout.write(i);
}
fout.close();
byte b[] = new byte[64];
for(int i = 0; i < 64; i++) {
b[i] = 1;
}
/* test all input streams */
FileInputStream fis = new FileInputStream(fn);
doTest(fis);
doTest1(fis);
fis.close();
BufferedInputStream bis =
new BufferedInputStream(new MyInputStream(1024));
doTest(bis);
doTest1(bis);
bis.close();
ByteArrayInputStream bais = new ByteArrayInputStream(b);
doTest(bais);
doTest1(bais);
bais.close();
FileOutputStream fos = new FileOutputStream(fn);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeInt(12345);
oos.writeObject("Today");
oos.writeObject(new Integer(32));
oos.close();
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fn));
doTest(ois);
doTest1(ois);
ois.close();
DataInputStream dis = new DataInputStream(new MyInputStream(1024));
doTest(dis);
doTest1(dis);
dis.close();
LineNumberInputStream lis =
new LineNumberInputStream(new MyInputStream(1024));
doTest(lis);
doTest1(lis);
lis.close();
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream();
pos.connect(pis);
pos.write(b, 0, 64);
doTest(pis);
doTest1(pis);
pis.close();
PushbackInputStream pbis =
new PushbackInputStream(new MyInputStream(1024));
doTest(pbis);
doTest1(pbis);
pbis.close();
StringBufferInputStream sbis =
new StringBufferInputStream(new String(b));
doTest(sbis);
doTest1(sbis);
sbis.close();
SequenceInputStream sis =
new SequenceInputStream(new MyInputStream(1024),
new MyInputStream(1024));
doTest(sis);
doTest1(sis);
sis.close();
ZipInputStream zis = new ZipInputStream(new FileInputStream(fn));
doTest(zis);
doTest1(zis);
zis.close();
byte[] data = new byte[256];
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DeflaterOutputStream dos = new DeflaterOutputStream(bos);
dos.write(data, 0, data.length);
dos.close();
InflaterInputStream ifs = new InflaterInputStream
(new ByteArrayInputStream(bos.toByteArray()));
doTest(ifs);
doTest1(ifs);
ifs.close();
/* cleanup */
fn.delete();
}
public static void main(String args[]) throws Exception{
/* initialise stuff */
File fn = new File("x.ReadBounds");
FileOutputStream fout = new FileOutputStream(fn);
for (int i = 0; i < 32; i++) {
fout.write(i);
}
fout.close();
byte b[] = new byte[64];
for(int i = 0; i < 64; i++) {
b[i] = 1;
}
/* test all input streams */
FileInputStream fis = new FileInputStream(fn);
doTest(fis);
doTest1(fis);
fis.close();
BufferedInputStream bis =
new BufferedInputStream(new MyInputStream(1024));
doTest(bis);
doTest1(bis);
bis.close();
ByteArrayInputStream bais = new ByteArrayInputStream(b);
doTest(bais);
doTest1(bais);
bais.close();
FileOutputStream fos = new FileOutputStream(fn);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeInt(12345);
oos.writeObject("Today");
oos.writeObject(new Integer(32));
oos.close();
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fn));
doTest(ois);
doTest1(ois);
ois.close();
DataInputStream dis = new DataInputStream(new MyInputStream(1024));
doTest(dis);
doTest1(dis);
dis.close();
LineNumberInputStream lis =
new LineNumberInputStream(new MyInputStream(1024));
doTest(lis);
doTest1(lis);
lis.close();
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream();
pos.connect(pis);
pos.write(b, 0, 64);
doTest(pis);
doTest1(pis);
pis.close();
PushbackInputStream pbis =
new PushbackInputStream(new MyInputStream(1024));
doTest(pbis);
doTest1(pbis);
pbis.close();
StringBufferInputStream sbis =
new StringBufferInputStream(new String(b));
doTest(sbis);
doTest1(sbis);
sbis.close();
SequenceInputStream sis =
new SequenceInputStream(new MyInputStream(1024),
new MyInputStream(1024));
doTest(sis);
doTest1(sis);
sis.close();
ZipInputStream zis = new ZipInputStream(new FileInputStream(fn));
doTest(zis);
doTest1(zis);
zis.close();
byte[] data = new byte[256];
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DeflaterOutputStream dos = new DeflaterOutputStream(bos);
dos.write(data, 0, data.length);
dos.close();
InflaterInputStream ifs = new InflaterInputStream
(new ByteArrayInputStream(bos.toByteArray()));
doTest(ifs);
doTest1(ifs);
ifs.close();
/* cleanup */
fn.delete();
}
public static void main(String args[]) throws Exception{
/* initialise stuff */
File fn = new File("x.ReadBounds");
FileOutputStream fout = new FileOutputStream(fn);
for (int i = 0; i < 32; i++) {
fout.write(i);
}
fout.close();
byte b[] = new byte[64];
for(int i = 0; i < 64; i++) {
b[i] = 1;
}
/* test all input streams */
FileInputStream fis = new FileInputStream(fn);
doTest(fis);
doTest1(fis);
fis.close();
BufferedInputStream bis =
new BufferedInputStream(new MyInputStream(1024));
doTest(bis);
doTest1(bis);
bis.close();
ByteArrayInputStream bais = new ByteArrayInputStream(b);
doTest(bais);
doTest1(bais);
bais.close();
FileOutputStream fos = new FileOutputStream(fn);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeInt(12345);
oos.writeObject("Today");
oos.writeObject(new Integer(32));
oos.close();
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fn));
doTest(ois);
doTest1(ois);
ois.close();
DataInputStream dis = new DataInputStream(new MyInputStream(1024));
doTest(dis);
doTest1(dis);
dis.close();
LineNumberInputStream lis =
new LineNumberInputStream(new MyInputStream(1024));
doTest(lis);
doTest1(lis);
lis.close();
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream();
pos.connect(pis);
pos.write(b, 0, 64);
doTest(pis);
doTest1(pis);
pis.close();
PushbackInputStream pbis =
new PushbackInputStream(new MyInputStream(1024));
doTest(pbis);
doTest1(pbis);
pbis.close();
StringBufferInputStream sbis =
new StringBufferInputStream(new String(b));
doTest(sbis);
doTest1(sbis);
sbis.close();
SequenceInputStream sis =
new SequenceInputStream(new MyInputStream(1024),
new MyInputStream(1024));
doTest(sis);
doTest1(sis);
sis.close();
ZipInputStream zis = new ZipInputStream(new FileInputStream(fn));
doTest(zis);
doTest1(zis);
zis.close();
byte[] data = new byte[256];
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DeflaterOutputStream dos = new DeflaterOutputStream(bos);
dos.write(data, 0, data.length);
dos.close();
InflaterInputStream ifs = new InflaterInputStream
(new ByteArrayInputStream(bos.toByteArray()));
doTest(ifs);
doTest1(ifs);
ifs.close();
/* cleanup */
fn.delete();
}
public static void main(String args[]) throws Exception{
/* initialise stuff */
File fn = new File("x.ReadBounds");
FileOutputStream fout = new FileOutputStream(fn);
for (int i = 0; i < 32; i++) {
fout.write(i);
}
fout.close();
byte b[] = new byte[64];
for(int i = 0; i < 64; i++) {
b[i] = 1;
}
/* test all input streams */
FileInputStream fis = new FileInputStream(fn);
doTest(fis);
doTest1(fis);
fis.close();
BufferedInputStream bis =
new BufferedInputStream(new MyInputStream(1024));
doTest(bis);
doTest1(bis);
bis.close();
ByteArrayInputStream bais = new ByteArrayInputStream(b);
doTest(bais);
doTest1(bais);
bais.close();
FileOutputStream fos = new FileOutputStream(fn);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeInt(12345);
oos.writeObject("Today");
oos.writeObject(new Integer(32));
oos.close();
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fn));
doTest(ois);
doTest1(ois);
ois.close();
DataInputStream dis = new DataInputStream(new MyInputStream(1024));
doTest(dis);
doTest1(dis);
dis.close();
LineNumberInputStream lis =
new LineNumberInputStream(new MyInputStream(1024));
doTest(lis);
doTest1(lis);
lis.close();
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream();
pos.connect(pis);
pos.write(b, 0, 64);
doTest(pis);
doTest1(pis);
pis.close();
PushbackInputStream pbis =
new PushbackInputStream(new MyInputStream(1024));
doTest(pbis);
doTest1(pbis);
pbis.close();
StringBufferInputStream sbis =
new StringBufferInputStream(new String(b));
doTest(sbis);
doTest1(sbis);
sbis.close();
SequenceInputStream sis =
new SequenceInputStream(new MyInputStream(1024),
new MyInputStream(1024));
doTest(sis);
doTest1(sis);
sis.close();
ZipInputStream zis = new ZipInputStream(new FileInputStream(fn));
doTest(zis);
doTest1(zis);
zis.close();
byte[] data = new byte[256];
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DeflaterOutputStream dos = new DeflaterOutputStream(bos);
dos.write(data, 0, data.length);
dos.close();
InflaterInputStream ifs = new InflaterInputStream
(new ByteArrayInputStream(bos.toByteArray()));
doTest(ifs);
doTest1(ifs);
ifs.close();
/* cleanup */
fn.delete();
}
public static void main(String args[]) throws Exception{
/* initialise stuff */
File fn = new File("x.ReadBounds");
FileOutputStream fout = new FileOutputStream(fn);
for (int i = 0; i < 32; i++) {
fout.write(i);
}
fout.close();
byte b[] = new byte[64];
for(int i = 0; i < 64; i++) {
b[i] = 1;
}
/* test all input streams */
FileInputStream fis = new FileInputStream(fn);
doTest(fis);
doTest1(fis);
fis.close();
BufferedInputStream bis =
new BufferedInputStream(new MyInputStream(1024));
doTest(bis);
doTest1(bis);
bis.close();
ByteArrayInputStream bais = new ByteArrayInputStream(b);
doTest(bais);
doTest1(bais);
bais.close();
FileOutputStream fos = new FileOutputStream(fn);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeInt(12345);
oos.writeObject("Today");
oos.writeObject(new Integer(32));
oos.close();
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fn));
doTest(ois);
doTest1(ois);
ois.close();
DataInputStream dis = new DataInputStream(new MyInputStream(1024));
doTest(dis);
doTest1(dis);
dis.close();
LineNumberInputStream lis =
new LineNumberInputStream(new MyInputStream(1024));
doTest(lis);
doTest1(lis);
lis.close();
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream();
pos.connect(pis);
pos.write(b, 0, 64);
doTest(pis);
doTest1(pis);
pis.close();
PushbackInputStream pbis =
new PushbackInputStream(new MyInputStream(1024));
doTest(pbis);
doTest1(pbis);
pbis.close();
StringBufferInputStream sbis =
new StringBufferInputStream(new String(b));
doTest(sbis);
doTest1(sbis);
sbis.close();
SequenceInputStream sis =
new SequenceInputStream(new MyInputStream(1024),
new MyInputStream(1024));
doTest(sis);
doTest1(sis);
sis.close();
ZipInputStream zis = new ZipInputStream(new FileInputStream(fn));
doTest(zis);
doTest1(zis);
zis.close();
byte[] data = new byte[256];
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DeflaterOutputStream dos = new DeflaterOutputStream(bos);
dos.write(data, 0, data.length);
dos.close();
InflaterInputStream ifs = new InflaterInputStream
(new ByteArrayInputStream(bos.toByteArray()));
doTest(ifs);
doTest1(ifs);
ifs.close();
/* cleanup */
fn.delete();
}