JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / JU / LimitedLineReader.js
1 Clazz.declarePackage ("JU");\r
2 c$ = Clazz.decorateAsClass (function () {\r
3 this.buf = null;\r
4 this.cchBuf = 0;\r
5 this.ichCurrent = 0;\r
6 Clazz.instantialize (this, arguments);\r
7 }, JU, "LimitedLineReader");\r
8 Clazz.makeConstructor (c$, \r
9 function (bufferedReader, readLimit) {\r
10 bufferedReader.mark (readLimit + 1);\r
11 this.buf =  Clazz.newCharArray (readLimit, '\0');\r
12 this.cchBuf = Math.max (bufferedReader.read (this.buf, 0, readLimit), 0);\r
13 this.ichCurrent = 0;\r
14 bufferedReader.reset ();\r
15 }, "java.io.BufferedReader,~N");\r
16 Clazz.defineMethod (c$, "getHeader", \r
17 function (n) {\r
18 return (n == 0 ?  String.instantialize (this.buf) :  String.instantialize (this.buf, 0, Math.min (this.cchBuf, n)));\r
19 }, "~N");\r
20 Clazz.defineMethod (c$, "readLineWithNewline", \r
21 function () {\r
22 while (this.ichCurrent < this.cchBuf) {\r
23 var ichBeginningOfLine = this.ichCurrent;\r
24 var ch = String.fromCharCode (0);\r
25 while (this.ichCurrent < this.cchBuf && (ch = this.buf[this.ichCurrent++]) != '\r' && ch != '\n') {\r
26 }\r
27 if (ch == '\r' && this.ichCurrent < this.cchBuf && this.buf[this.ichCurrent] == '\n') ++this.ichCurrent;\r
28 var cchLine = this.ichCurrent - ichBeginningOfLine;\r
29 if (this.buf[ichBeginningOfLine] == '#') continue;\r
30 return  String.instantialize (this.buf, ichBeginningOfLine, cchLine);\r
31 }\r
32 return "";\r
33 });\r