Java Source Code: tuning.distrib.rmi.CodecOutputStream


   1: package tuning.distrib.rmi;
   2: 
   3: import java.io.*;
   4: import java.net.*;
   5: import java.util.zip.*;
   6: 
   7: public class CodecOutputStream
   8:   extends FilterOutputStream
   9:	  {
  10:  Deflater compressor;
  11:
  12:  public CodecOutputStream(OutputStream out)
  13:	    {
  14:    super(out);
  15:    compressor = new Deflater(Deflater.BEST_SPEED);
  16:  }
  17:
  18:  public void write(int x)
  19:    throws IOException
  20:	    {
  21:    throw new IOException("CodeOutputStream.write(int) unsuppported");
  22:  }
  23:
  24:  public void write(byte[] b, int off, int len)
  25:    throws IOException
  26:	    {
  27:    int newlen = compressor.deflate(b, off, len);
  28:    out.write(len);
  29:    out.write(newlen);
  30:System.out.println("Writing " + newlen);
  31:    out.write(b, off, newlen);
  32:    out.flush();
  33:System.out.println("Flushed");
  34:  }
  35:}