home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / java / io / ByteArrayOutputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  1.6 KB  |  70 lines

  1. package java.io;
  2.  
  3. public class ByteArrayOutputStream extends OutputStream {
  4.    protected byte[] buf;
  5.    protected int count;
  6.  
  7.    public ByteArrayOutputStream() {
  8.       this(32);
  9.    }
  10.  
  11.    public ByteArrayOutputStream(int var1) {
  12.       this.buf = new byte[var1];
  13.    }
  14.  
  15.    public synchronized void write(int var1) {
  16.       int var2 = this.count + 1;
  17.       if (var2 > this.buf.length) {
  18.          byte[] var3 = new byte[Math.max(this.buf.length << 1, var2)];
  19.          System.arraycopy(this.buf, 0, var3, 0, this.count);
  20.          this.buf = var3;
  21.       }
  22.  
  23.       this.buf[this.count] = (byte)var1;
  24.       this.count = var2;
  25.    }
  26.  
  27.    public synchronized void write(byte[] var1, int var2, int var3) {
  28.       int var4 = this.count + var3;
  29.       if (var4 > this.buf.length) {
  30.          byte[] var5 = new byte[Math.max(this.buf.length << 1, var4)];
  31.          System.arraycopy(this.buf, 0, var5, 0, this.count);
  32.          this.buf = var5;
  33.       }
  34.  
  35.       System.arraycopy(var1, var2, this.buf, this.count, var3);
  36.       this.count = var4;
  37.    }
  38.  
  39.    public synchronized void writeTo(OutputStream var1) throws IOException {
  40.       var1.write(this.buf, 0, this.count);
  41.    }
  42.  
  43.    public synchronized void reset() {
  44.       this.count = 0;
  45.    }
  46.  
  47.    public synchronized byte[] toByteArray() {
  48.       byte[] var1 = new byte[this.count];
  49.       System.arraycopy(this.buf, 0, var1, 0, this.count);
  50.       return var1;
  51.    }
  52.  
  53.    public int size() {
  54.       return this.count;
  55.    }
  56.  
  57.    public String toString() {
  58.       return new String(this.buf, 0, this.count);
  59.    }
  60.  
  61.    public String toString(String var1) throws UnsupportedEncodingException {
  62.       return new String(this.buf, 0, this.count, var1);
  63.    }
  64.  
  65.    /** @deprecated */
  66.    public String toString(int var1) {
  67.       return new String(this.buf, var1, 0, this.count);
  68.    }
  69. }
  70.