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