JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / java / io / BufferedOutputStream.js
1 Clazz.load(["java.io.FilterOutputStream"],"java.io.BufferedOutputStream",["java.lang.ArrayIndexOutOfBoundsException","$.IllegalArgumentException","$.NullPointerException"],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,"BufferedOutputStream",java.io.FilterOutputStream);\r
7 Clazz.makeConstructor(c$,\r
8 function(out){\r
9 Clazz.superConstructor(this,java.io.BufferedOutputStream,[out]);\r
10 this.buf=Clazz.newArray(8192,0);\r
11 },"java.io.OutputStream");\r
12 Clazz.makeConstructor(c$,\r
13 function(out,size){\r
14 Clazz.superConstructor(this,java.io.BufferedOutputStream,[out]);\r
15 if(size<=0){\r
16 throw new IllegalArgumentException(("K0058"));\r
17 }this.buf=Clazz.newArray(size,0);\r
18 },"java.io.OutputStream,~N");\r
19 Clazz.overrideMethod(c$,"flush",\r
20 function(){\r
21 if(this.count>0){\r
22 this.out.write(this.buf,0,this.count);\r
23 }this.count=0;\r
24 this.out.flush();\r
25 });\r
26 Clazz.defineMethod(c$,"write",\r
27 function(buffer,offset,length){\r
28 if(buffer==null){\r
29 throw new NullPointerException(("K0047"));\r
30 }if(offset<0||offset>buffer.length-length||length<0){\r
31 throw new ArrayIndexOutOfBoundsException(("K002f"));\r
32 }if(this.count==0&&length>=this.buf.length){\r
33 this.out.write(buffer,offset,length);\r
34 return;\r
35 }var available=this.buf.length-this.count;\r
36 if(length<available){\r
37 available=length;\r
38 }if(available>0){\r
39 System.arraycopy(buffer,offset,this.buf,this.count,available);\r
40 this.count+=available;\r
41 }if(this.count==this.buf.length){\r
42 this.out.write(this.buf,0,this.buf.length);\r
43 this.count=0;\r
44 if(length>available){\r
45 offset+=available;\r
46 available=length-available;\r
47 if(available>=this.buf.length){\r
48 this.out.write(buffer,offset,available);\r
49 }else{\r
50 System.arraycopy(buffer,offset,this.buf,this.count,available);\r
51 this.count+=available;\r
52 }}}},"~A,~N,~N");\r
53 Clazz.defineMethod(c$,"write",\r
54 function(oneByte){\r
55 if(this.count==this.buf.length){\r
56 this.out.write(this.buf,0,this.count);\r
57 this.count=0;\r
58 }this.buf[this.count++]=oneByte;\r
59 },"~N");\r
60 });\r