Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / java / io / ByteArrayOutputStream.js
1 Clazz.load (["java.io.OutputStream"], "java.io.ByteArrayOutputStream", ["java.lang.IllegalArgumentException", "$.IndexOutOfBoundsException", "$.OutOfMemoryError"], function () {
2 c$ = Clazz.decorateAsClass (function () {
3 this.buf = null;
4 this.count = 0;
5 Clazz.instantialize (this, arguments);
6 }, java.io, "ByteArrayOutputStream", java.io.OutputStream);
7 Clazz.makeConstructor (c$, 
8 function () {
9 this.construct (32);
10 });
11 Clazz.makeConstructor (c$, 
12 function (size) {
13 Clazz.superConstructor (this, java.io.ByteArrayOutputStream, []);
14 if (size < 0) {
15 throw  new IllegalArgumentException ("Negative initial size: " + size);
16 }this.buf =  Clazz.newByteArray (size, 0);
17 }, "~N");
18 Clazz.defineMethod (c$, "ensureCapacity", 
19  function (minCapacity) {
20 if (minCapacity - this.buf.length > 0) this.grow (minCapacity);
21 }, "~N");
22 Clazz.defineMethod (c$, "grow", 
23  function (minCapacity) {
24 var oldCapacity = this.buf.length;
25 var newCapacity = oldCapacity << 1;
26 if (newCapacity - minCapacity < 0) newCapacity = minCapacity;
27 if (newCapacity < 0) {
28 if (minCapacity < 0) throw  new OutOfMemoryError ();
29 newCapacity = minCapacity;
30 }this.buf = java.io.ByteArrayOutputStream.arrayCopyByte (this.buf, newCapacity);
31 }, "~N");
32 c$.arrayCopyByte = Clazz.defineMethod (c$, "arrayCopyByte", 
33  function (array, newLength) {
34 var t =  Clazz.newByteArray (newLength, 0);
35 System.arraycopy (array, 0, t, 0, array.length < newLength ? array.length : newLength);
36 return t;
37 }, "~A,~N");
38 Clazz.overrideMethod (c$, "writeByteAsInt", 
39 function (b) {
40 this.ensureCapacity (this.count + 1);
41 this.buf[this.count] = b;
42 this.count += 1;
43 }, "~N");
44 Clazz.defineMethod (c$, "write", 
45 function (b, off, len) {
46 if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) - b.length > 0)) {
47 throw  new IndexOutOfBoundsException ();
48 }this.ensureCapacity (this.count + len);
49 System.arraycopy (b, off, this.buf, this.count, len);
50 this.count += len;
51 }, "~A,~N,~N");
52 Clazz.defineMethod (c$, "writeTo", 
53 function (out) {
54 out.write (this.buf, 0, this.count);
55 }, "java.io.OutputStream");
56 Clazz.defineMethod (c$, "reset", 
57 function () {
58 this.count = 0;
59 });
60 Clazz.defineMethod (c$, "toByteArray", 
61 function () {
62 return (this.count == this.buf.length ? this.buf : java.io.ByteArrayOutputStream.arrayCopyByte (this.buf, this.count));
63 });
64 Clazz.defineMethod (c$, "size", 
65 function () {
66 return this.count;
67 });
68 Clazz.overrideMethod (c$, "toString", 
69 function () {
70 return  String.instantialize (this.buf, 0, this.count);
71 });
72 Clazz.overrideMethod (c$, "close", 
73 function () {
74 });
75 });