Java Code Examples for java.util.zip.DeflaterOutputStream#close()

The following examples show how to use java.util.zip.DeflaterOutputStream#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StandardEncrypter.java    From fastods with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Deflate as LibreOffice.
 *
 * @param data the data to DEFLATE
 * @return the DEFLATEd data
 * @throws IOException if a I/O error occurs
 */
public byte[] compress(final byte[] data) throws IOException {
    final ByteArrayOutputStream os = new ByteArrayOutputStream();
    final Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION, true);
    final DeflaterOutputStream dos = new DeflaterOutputStream(os, deflater);

    final InputStream is = new ByteArrayInputStream(data);
    final byte[] buffer = new byte[BUFFER_SIZE];
    int count = is.read(buffer);
    while (count != -1) {
        dos.write(buffer, 0, count);
        count = is.read(buffer);
    }
    dos.close();
    return os.toByteArray();
}
 
Example 2
Source File: IDATChunk.java    From BiglyBT with GNU General Public License v2.0 6 votes vote down vote up
@Override
public byte[] getContentPayload() {
	byte[] payload = new byte[(width+1)*height];
	for(int i = 0; i<height ; i++) {
		int offset = i * (width+1);
		//NO filter on this line
		payload[offset++] = 0;
		for(int j = 0 ; j<width ; j++) {
			payload[offset+j] = (byte)(127);
		}
	}

	Deflater deflater = new Deflater( Deflater.DEFAULT_COMPRESSION );
    ByteArrayOutputStream outBytes = new ByteArrayOutputStream((width+1)*height);

    DeflaterOutputStream compBytes = new DeflaterOutputStream( outBytes, deflater );
    try {
    	compBytes.write(payload);
    	compBytes.close();
    } catch(Exception e) {
    	e.printStackTrace();
    }
    byte[] compPayload = outBytes.toByteArray();

	return compPayload;
}
 
Example 3
Source File: UtilAll.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public static byte[] compress(final byte[] src, final int level) throws IOException {
    byte[] result = src;
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(src.length);
    java.util.zip.Deflater defeater = new java.util.zip.Deflater(level);
    DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream, defeater);
    try {
        deflaterOutputStream.write(src);
        deflaterOutputStream.finish();
        deflaterOutputStream.close();
        result = byteArrayOutputStream.toByteArray();
    } catch (IOException e) {
        defeater.end();
        throw e;
    } finally {
        try {
            byteArrayOutputStream.close();
        } catch (IOException ignored) {
        }

        defeater.end();
    }

    return result;
}
 
Example 4
Source File: UtilAll.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static byte[] compress(final byte[] src, final int level) throws IOException {
    byte[] result = src;
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(src.length);
    java.util.zip.Deflater defeater = new java.util.zip.Deflater(level);
    DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream, defeater);
    try {
        deflaterOutputStream.write(src);
        deflaterOutputStream.finish();
        deflaterOutputStream.close();
        result = byteArrayOutputStream.toByteArray();
    } catch (IOException e) {
        defeater.end();
        throw e;
    } finally {
        try {
            byteArrayOutputStream.close();
        } catch (IOException ignored) {
        }

        defeater.end();
    }

    return result;
}
 
Example 5
Source File: MixAll.java    From jmqtt with Apache License 2.0 6 votes vote down vote up
public static byte[] compress(final byte[] src,final int level) throws IOException {
    byte[] result = src;
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(src.length);
    Deflater deflater = new Deflater(level);
    DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream,deflater);
    try{
        deflaterOutputStream.write(src);
        deflaterOutputStream.flush();
        deflaterOutputStream.close();
        result = byteArrayOutputStream.toByteArray();
    }catch (IOException e){
        deflater.end();
        throw e;
    }finally {
        try {
            byteArrayOutputStream.close();
        } catch (IOException ignored) {
        }
        deflater.end();
    }
    return result;
}
 
Example 6
Source File: UtilAll.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public static byte[] compress(final byte[] src, final int level) throws IOException {
    byte[] result = src;
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(src.length);
    java.util.zip.Deflater defeater = new java.util.zip.Deflater(level);
    DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream, defeater);
    try {
        deflaterOutputStream.write(src);
        deflaterOutputStream.finish();
        deflaterOutputStream.close();
        result = byteArrayOutputStream.toByteArray();
    } catch (IOException e) {
        defeater.end();
        throw e;
    } finally {
        try {
            byteArrayOutputStream.close();
        } catch (IOException ignored) {
        }

        defeater.end();
    }

    return result;
}
 
Example 7
Source File: DeflateUncompressorTest.java    From archive-patcher with Apache License 2.0 6 votes vote down vote up
@Test
public void testNowrap() throws IOException {
  // Recompress with nowrap set to false.
  Deflater deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, false /* nowrap */);
  ByteArrayOutputStream compressedContentBuffer = new ByteArrayOutputStream();
  DeflaterOutputStream deflateOut = new DeflaterOutputStream(compressedContentBuffer, deflater);
  deflateOut.write(CONTENT);
  deflateOut.finish();
  deflateOut.close();
  deflater.end();
  compressedContent = compressedContentBuffer.toByteArray();
  compressedContentIn = new ByteArrayInputStream(compressedContent);

  // Now expect wrapped content in the uncompressor, and uncompressing should "just work".
  uncompressor.setNowrap(false);
  uncompressor.uncompress(compressedContentIn, uncompressedContentOut);
  assertTrue(Arrays.equals(CONTENT, uncompressedContentOut.toByteArray()));
}
 
Example 8
Source File: UtilAll.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
/**
 * 压缩
 * @param src ;
 * @param level ;
 * @return ;
 * @throws IOException ;
 */
public static byte[] compress(final byte[] src, final int level) throws IOException {
    byte[] result = src;
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(src.length);
    java.util.zip.Deflater defeater = new java.util.zip.Deflater(level);
    DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream, defeater);
    try {
        deflaterOutputStream.write(src);
        deflaterOutputStream.finish();
        deflaterOutputStream.close();
        result = byteArrayOutputStream.toByteArray();
    } catch (IOException e) {
        defeater.end();
        throw e;
    } finally {
        try {
            byteArrayOutputStream.close();
        } catch (IOException ignored) {
        }

        defeater.end();
    }

    return result;
}
 
Example 9
Source File: PNGImageWriter.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private byte[] deflate(byte[] b) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DeflaterOutputStream dos = new DeflaterOutputStream(baos);
    dos.write(b);
    dos.close();
    return baos.toByteArray();
}
 
Example 10
Source File: DigestUtils.java    From JobX with Apache License 2.0 5 votes vote down vote up
public static String compressData(String data) {
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        DeflaterOutputStream zos = new DeflaterOutputStream(bos);
        zos.write(data.getBytes());
        zos.close();
        return new String(getenBASE64inCodec(bos.toByteArray()));
    } catch (Exception ex) {
        ex.printStackTrace();
        return "ZIP_ERR";
    }
}
 
Example 11
Source File: CdmrGridController.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private long sendData(Array data, OutputStream out, boolean deflate) throws IOException, InvalidRangeException {

    // length of data uncompressed
    long uncompressedLength = data.getSizeBytes();
    long size = 0;


    if (deflate) {
      // write to an internal buffer, so we can find out the size
      ByteArrayOutputStream bout = new ByteArrayOutputStream();
      DeflaterOutputStream dout = new DeflaterOutputStream(bout);
      IospHelper.copyToOutputStream(data, dout);

      // write internal buffer to output stream
      dout.close();
      int deflatedSize = bout.size();
      size += NcStream.writeVInt(out, deflatedSize);
      bout.writeTo(out);
      size += deflatedSize;
      float ratio = ((float) uncompressedLength) / deflatedSize;
      if (showRes)
        System.out.printf("  org/compress= %d/%d = %f%n", uncompressedLength, deflatedSize, ratio);

    } else {
      size += NcStream.writeVInt(out, (int) uncompressedLength);
      size += IospHelper.copyToOutputStream(data, out);
    }

    return size;
  }
 
Example 12
Source File: DigestUtils.java    From opencron with Apache License 2.0 5 votes vote down vote up
public static String compressData(String data, String charset) {
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        DeflaterOutputStream zos = new DeflaterOutputStream(bos);
        zos.write(data.getBytes());
        zos.close();
        return new String(getenBASE64inCodec(bos.toByteArray(), charset));
    } catch (Exception ex) {
        ex.printStackTrace();
        return "ZIP_ERR";
    }
}
 
Example 13
Source File: ReadParams.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
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();
}
 
Example 14
Source File: WriteParams.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception{
    /* initialise stuff here */
    File fn = new File("x.WriteBounds");
    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 for different output streams */
    FileOutputStream fos = new FileOutputStream(fn);
    doTest(fos);
    doTest1(fos);
    fos.close();

    ObjectOutputStream oos = new ObjectOutputStream(new MyOutputStream());
    doTest(oos);
    doTest1(oos);
    oos.close();

    BufferedOutputStream bos =
        new BufferedOutputStream(new MyOutputStream());
    doTest(bos);
    doTest1(bos);
    bos.close();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    doTest(baos);
    doTest1(baos);
    baos.close();

    DataOutputStream dos = new DataOutputStream(new MyOutputStream());
    doTest(dos);
    doTest1(dos);
    dos.close();

    PipedInputStream pis = new PipedInputStream();
    PipedOutputStream pos = new PipedOutputStream();
    pos.connect(pis);
    doTest(pos);
    doTest1(pos);
    pos.close();

    DeflaterOutputStream dfos = new DeflaterOutputStream(new MyOutputStream());
    doTest(dfos);
    doTest1(dfos);
    dfos.close();

    /* cleanup */
    fn.delete();

}
 
Example 15
Source File: ReadParams.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
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();
}
 
Example 16
Source File: PdfStream.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
   * Compresses the stream.
* @param compressionLevel the compression level (0 = best speed, 9 = best compression, -1 is default)
* @since	2.1.3
   */
  public void flateCompress(int compressionLevel) {
      if (!Document.compress)
          return;
      // check if the flateCompress-method has already been
      if (compressed) {
          return;
      }
  	this.compressionLevel = compressionLevel;
      if (inputStream != null) {
          compressed = true;
          return;
      }
      // check if a filter already exists
      PdfObject filter = PdfReader.getPdfObject(get(PdfName.FILTER));
      if (filter != null) {
          if (filter.isName()) {
              if (PdfName.FLATEDECODE.equals(filter))
                  return;
          }
          else if (filter.isArray()) {
              if (((PdfArray) filter).contains(PdfName.FLATEDECODE))
                  return;
          }
          else {
              throw new RuntimeException("Stream could not be compressed: filter is not a name or array.");
          }
      }
      try {
          // compress
          ByteArrayOutputStream stream = new ByteArrayOutputStream();
          Deflater deflater = new Deflater(compressionLevel);
          DeflaterOutputStream zip = new DeflaterOutputStream(stream, deflater);
          if (streamBytes != null)
              streamBytes.writeTo(zip);
          else
              zip.write(bytes);
          zip.close();
          deflater.end();
          // update the object
          streamBytes = stream;
          bytes = null;
          put(PdfName.LENGTH, new PdfNumber(streamBytes.size()));
          if (filter == null) {
              put(PdfName.FILTER, PdfName.FLATEDECODE);
          }
          else {
              PdfArray filters = new PdfArray(filter);
              filters.add(PdfName.FLATEDECODE);
              put(PdfName.FILTER, filters);
          }
          compressed = true;
      }
      catch(IOException ioe) {
          throw new ExceptionConverter(ioe);
      }
  }
 
Example 17
Source File: WriteParams.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception{
    /* initialise stuff here */
    File fn = new File("x.WriteBounds");
    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 for different output streams */
    FileOutputStream fos = new FileOutputStream(fn);
    doTest(fos);
    doTest1(fos);
    fos.close();

    ObjectOutputStream oos = new ObjectOutputStream(new MyOutputStream());
    doTest(oos);
    doTest1(oos);
    oos.close();

    BufferedOutputStream bos =
        new BufferedOutputStream(new MyOutputStream());
    doTest(bos);
    doTest1(bos);
    bos.close();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    doTest(baos);
    doTest1(baos);
    baos.close();

    DataOutputStream dos = new DataOutputStream(new MyOutputStream());
    doTest(dos);
    doTest1(dos);
    dos.close();

    PipedInputStream pis = new PipedInputStream();
    PipedOutputStream pos = new PipedOutputStream();
    pos.connect(pis);
    doTest(pos);
    doTest1(pos);
    pos.close();

    DeflaterOutputStream dfos = new DeflaterOutputStream(new MyOutputStream());
    doTest(dfos);
    doTest1(dfos);
    dfos.close();

    /* cleanup */
    fn.delete();

}
 
Example 18
Source File: WriteParams.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception{
    /* initialise stuff here */
    File fn = new File("x.WriteBounds");
    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 for different output streams */
    FileOutputStream fos = new FileOutputStream(fn);
    doTest(fos);
    doTest1(fos);
    fos.close();

    ObjectOutputStream oos = new ObjectOutputStream(new MyOutputStream());
    doTest(oos);
    doTest1(oos);
    oos.close();

    BufferedOutputStream bos =
        new BufferedOutputStream(new MyOutputStream());
    doTest(bos);
    doTest1(bos);
    bos.close();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    doTest(baos);
    doTest1(baos);
    baos.close();

    DataOutputStream dos = new DataOutputStream(new MyOutputStream());
    doTest(dos);
    doTest1(dos);
    dos.close();

    PipedInputStream pis = new PipedInputStream();
    PipedOutputStream pos = new PipedOutputStream();
    pos.connect(pis);
    doTest(pos);
    doTest1(pos);
    pos.close();

    DeflaterOutputStream dfos = new DeflaterOutputStream(new MyOutputStream());
    doTest(dfos);
    doTest1(dfos);
    dfos.close();

    /* cleanup */
    fn.delete();

}
 
Example 19
Source File: WriteParams.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception{
    /* initialise stuff here */
    File fn = new File("x.WriteBounds");
    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 for different output streams */
    FileOutputStream fos = new FileOutputStream(fn);
    doTest(fos);
    doTest1(fos);
    fos.close();

    ObjectOutputStream oos = new ObjectOutputStream(new MyOutputStream());
    doTest(oos);
    doTest1(oos);
    oos.close();

    BufferedOutputStream bos =
        new BufferedOutputStream(new MyOutputStream());
    doTest(bos);
    doTest1(bos);
    bos.close();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    doTest(baos);
    doTest1(baos);
    baos.close();

    DataOutputStream dos = new DataOutputStream(new MyOutputStream());
    doTest(dos);
    doTest1(dos);
    dos.close();

    PipedInputStream pis = new PipedInputStream();
    PipedOutputStream pos = new PipedOutputStream();
    pos.connect(pis);
    doTest(pos);
    doTest1(pos);
    pos.close();

    DeflaterOutputStream dfos = new DeflaterOutputStream(new MyOutputStream());
    doTest(dfos);
    doTest1(dfos);
    dfos.close();

    /* cleanup */
    fn.delete();

}
 
Example 20
Source File: ReadParams.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
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();
}