Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / java / io / StringReader.js
1 Clazz.load (["java.io.Reader"], "java.io.StringReader", ["java.io.IOException", "java.lang.IllegalArgumentException", "$.IndexOutOfBoundsException"], function () {
2 c$ = Clazz.decorateAsClass (function () {
3 this.str = null;
4 this.length = 0;
5 this.next = 0;
6 this.$mark = 0;
7 Clazz.instantialize (this, arguments);
8 }, java.io, "StringReader", java.io.Reader);
9 Clazz.makeConstructor (c$, 
10 function (s) {
11 Clazz.superConstructor (this, java.io.StringReader, [s]);
12 this.str = s;
13 this.length = s.length;
14 }, "~S");
15 Clazz.defineMethod (c$, "ensureOpen", 
16  function () {
17 if (this.str == null) throw  new java.io.IOException ("Stream closed");
18 });
19 Clazz.overrideMethod (c$, "read", 
20 function (cbuf, off, len) {
21 {
22 this.ensureOpen ();
23 if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) > cbuf.length) || ((off + len) < 0)) {
24 throw  new IndexOutOfBoundsException ();
25 } else if (len == 0) {
26 return 0;
27 }if (this.next >= this.length) return -1;
28 var n = Math.min (this.length - this.next, len);
29 this.str.getChars (this.next, this.next + n, cbuf, off);
30 this.next += n;
31 return n;
32 }}, "~A,~N,~N");
33 Clazz.overrideMethod (c$, "skip", 
34 function (ns) {
35 {
36 this.ensureOpen ();
37 if (this.next >= this.length) return 0;
38 var n = Math.min (this.length - this.next, ns);
39 n = Math.max (-this.next, n);
40 this.next += n;
41 return n;
42 }}, "~N");
43 Clazz.overrideMethod (c$, "ready", 
44 function () {
45 {
46 this.ensureOpen ();
47 return true;
48 }});
49 Clazz.overrideMethod (c$, "markSupported", 
50 function () {
51 return true;
52 });
53 Clazz.overrideMethod (c$, "mark", 
54 function (readAheadLimit) {
55 if (readAheadLimit < 0) {
56 throw  new IllegalArgumentException ("Read-ahead limit < 0");
57 }{
58 this.ensureOpen ();
59 this.$mark = this.next;
60 }}, "~N");
61 Clazz.overrideMethod (c$, "reset", 
62 function () {
63 {
64 this.ensureOpen ();
65 this.next = this.$mark;
66 }});
67 Clazz.overrideMethod (c$, "close", 
68 function () {
69 this.str = null;
70 });
71 });