Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / java / io / BufferedWriter.js
1 Clazz.load(["java.io.Writer"],"java.io.BufferedWriter",["java.io.IOException","java.lang.IllegalArgumentException","$.IndexOutOfBoundsException","$.StringIndexOutOfBoundsException"],function(){
2 c$=Clazz.decorateAsClass(function(){
3 this.out=null;
4 this.buf=null;
5 this.pos=0;
6 this.lineSeparator="\r\n";
7 Clazz.instantialize(this,arguments);
8 },java.io,"BufferedWriter",java.io.Writer);
9 Clazz.makeConstructor(c$,
10 function(out){
11 Clazz.superConstructor(this,java.io.BufferedWriter,[out]);
12 this.out=out;
13 this.buf=Clazz.newArray(8192,'\0');
14 },"java.io.Writer");
15 Clazz.makeConstructor(c$,
16 function(out,size){
17 Clazz.superConstructor(this,java.io.BufferedWriter,[out]);
18 if(size>0){
19 this.out=out;
20 this.buf=Clazz.newArray(size,'\0');
21 }else{
22 throw new IllegalArgumentException(("K0058"));
23 }},"java.io.Writer,~N");
24 Clazz.defineMethod(c$,"close",
25 function(){
26 {
27 if(this.isOpen()){
28 this.flush();
29 this.out.close();
30 this.buf=null;
31 this.out=null;
32 }}});
33 Clazz.defineMethod(c$,"flush",
34 function(){
35 {
36 if(this.isOpen()){
37 if(this.pos>0){
38 this.out.write(this.buf,0,this.pos);
39 }this.pos=0;
40 this.out.flush();
41 }else{
42 throw new java.io.IOException(("K005d"));
43 }}});
44 Clazz.defineMethod(c$,"isOpen",
45 ($fz=function(){
46 return this.out!=null;
47 },$fz.isPrivate=true,$fz));
48 Clazz.defineMethod(c$,"newLine",
49 function(){
50 this.write("\r\n",0,"\r\n".length);
51 });
52 Clazz.defineMethod(c$,"write",
53 function(cbuf,offset,count){
54 {
55 if(!this.isOpen()){
56 throw new java.io.IOException(("K005d"));
57 }if(offset<0||offset>cbuf.length-count||count<0){
58 throw new IndexOutOfBoundsException();
59 }if(this.pos==0&&count>=this.buf.length){
60 this.out.write(cbuf,offset,count);
61 return;
62 }var available=this.buf.length-this.pos;
63 if(count<available){
64 available=count;
65 }if(available>0){
66 System.arraycopy(cbuf,offset,this.buf,this.pos,available);
67 this.pos+=available;
68 }if(this.pos==this.buf.length){
69 this.out.write(this.buf,0,this.buf.length);
70 this.pos=0;
71 if(count>available){
72 offset+=available;
73 available=count-available;
74 if(available>=this.buf.length){
75 this.out.write(cbuf,offset,available);
76 return;
77 }System.arraycopy(cbuf,offset,this.buf,this.pos,available);
78 this.pos+=available;
79 }}}},"~A,~N,~N");
80 Clazz.defineMethod(c$,"write",
81 function(oneChar){
82 {
83 if(this.isOpen()){
84 if(this.pos>=this.buf.length){
85 this.out.write(this.buf,0,this.buf.length);
86 this.pos=0;
87 }this.buf[this.pos++]=String.fromCharCode(oneChar);
88 }else{
89 throw new java.io.IOException(("K005d"));
90 }}},"~N");
91 Clazz.defineMethod(c$,"write",
92 function(str,offset,count){
93 {
94 if(!this.isOpen()){
95 throw new java.io.IOException(("K005d"));
96 }if(count<=0){
97 return;
98 }if(offset>str.length-count||offset<0){
99 throw new StringIndexOutOfBoundsException();
100 }if(this.pos==0&&count>=this.buf.length){
101 var chars=Clazz.newArray(count,'\0');
102 str.getChars(offset,offset+count,chars,0);
103 this.out.write(chars,0,count);
104 return;
105 }var available=this.buf.length-this.pos;
106 if(count<available){
107 available=count;
108 }if(available>0){
109 str.getChars(offset,offset+available,this.buf,this.pos);
110 this.pos+=available;
111 }if(this.pos==this.buf.length){
112 this.out.write(this.buf,0,this.buf.length);
113 this.pos=0;
114 if(count>available){
115 offset+=available;
116 available=count-available;
117 if(available>=this.buf.length){
118 var chars=Clazz.newArray(count,'\0');
119 str.getChars(offset,offset+available,chars,0);
120 this.out.write(chars,0,available);
121 return;
122 }str.getChars(offset,offset+available,this.buf,this.pos);
123 this.pos+=available;
124 }}}},"~S,~N,~N");
125 });