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