home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / java / io / ByteArrayOutputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  1.8 KB  |  91 lines

  1. package java.io;
  2.  
  3. public class ByteArrayOutputStream extends OutputStream {
  4.    protected byte[] buf;
  5.    protected int count;
  6.    private boolean isClosed;
  7.  
  8.    private void ensureOpen() {
  9.    }
  10.  
  11.    public ByteArrayOutputStream() {
  12.       this(32);
  13.    }
  14.  
  15.    public ByteArrayOutputStream(int var1) {
  16.       this.isClosed = false;
  17.       if (var1 < 0) {
  18.          throw new IllegalArgumentException("Negative initial size: " + var1);
  19.       } else {
  20.          this.buf = new byte[var1];
  21.       }
  22.    }
  23.  
  24.    public synchronized void write(int var1) {
  25.       this.ensureOpen();
  26.       int var2 = this.count + 1;
  27.       if (var2 > this.buf.length) {
  28.          byte[] var3 = new byte[Math.max(this.buf.length << 1, var2)];
  29.          System.arraycopy(this.buf, 0, var3, 0, this.count);
  30.          this.buf = var3;
  31.       }
  32.  
  33.       this.buf[this.count] = (byte)var1;
  34.       this.count = var2;
  35.    }
  36.  
  37.    public synchronized void write(byte[] var1, int var2, int var3) {
  38.       this.ensureOpen();
  39.       if (var2 >= 0 && var2 <= var1.length && var3 >= 0 && var2 + var3 <= var1.length && var2 + var3 >= 0) {
  40.          if (var3 != 0) {
  41.             int var4 = this.count + var3;
  42.             if (var4 > this.buf.length) {
  43.                byte[] var5 = new byte[Math.max(this.buf.length << 1, var4)];
  44.                System.arraycopy(this.buf, 0, var5, 0, this.count);
  45.                this.buf = var5;
  46.             }
  47.  
  48.             System.arraycopy(var1, var2, this.buf, this.count, var3);
  49.             this.count = var4;
  50.          }
  51.       } else {
  52.          throw new IndexOutOfBoundsException();
  53.       }
  54.    }
  55.  
  56.    public synchronized void writeTo(OutputStream var1) throws IOException {
  57.       var1.write(this.buf, 0, this.count);
  58.    }
  59.  
  60.    public synchronized void reset() {
  61.       this.ensureOpen();
  62.       this.count = 0;
  63.    }
  64.  
  65.    public synchronized byte[] toByteArray() {
  66.       byte[] var1 = new byte[this.count];
  67.       System.arraycopy(this.buf, 0, var1, 0, this.count);
  68.       return var1;
  69.    }
  70.  
  71.    public int size() {
  72.       return this.count;
  73.    }
  74.  
  75.    public String toString() {
  76.       return new String(this.buf, 0, this.count);
  77.    }
  78.  
  79.    public String toString(String var1) throws UnsupportedEncodingException {
  80.       return new String(this.buf, 0, this.count, var1);
  81.    }
  82.  
  83.    public String toString(int var1) {
  84.       return new String(this.buf, var1, 0, this.count);
  85.    }
  86.  
  87.    public synchronized void close() throws IOException {
  88.       this.isClosed = true;
  89.    }
  90. }
  91.