aboutsummaryrefslogtreecommitdiff
path: root/src/rejava/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/rejava/io')
-rw-r--r--src/rejava/io/Reader.java20
-rw-r--r--src/rejava/io/StringReader.java51
-rw-r--r--src/rejava/io/StringWriter.java29
-rw-r--r--src/rejava/io/Writer.java16
-rw-r--r--src/rejava/io/package-info.java6
-rw-r--r--src/rejava/io/rejavaio.gwt.xml3
6 files changed, 125 insertions, 0 deletions
diff --git a/src/rejava/io/Reader.java b/src/rejava/io/Reader.java
new file mode 100644
index 0000000..f0a6bfa
--- /dev/null
+++ b/src/rejava/io/Reader.java
@@ -0,0 +1,20 @@
1package rejava.io;
2
3/**
4 * A minimal version of java.io.Reader.
5 * (http://hg.openjdk.java.net/jdk7/jdk7/jdk
6 * /file/9b8c96f96a0f/src/share/classes/java/io/Reader.java)
7 *
8 * @author Pacien TRAN-GIRARD
9 */
10public abstract class Reader {
11
12 public abstract int read();
13
14 public abstract int read(final char[] cbuf, final int off, final int len);
15
16 public void close() {
17 return;
18 }
19
20} \ No newline at end of file
diff --git a/src/rejava/io/StringReader.java b/src/rejava/io/StringReader.java
new file mode 100644
index 0000000..dc39769
--- /dev/null
+++ b/src/rejava/io/StringReader.java
@@ -0,0 +1,51 @@
1package rejava.io;
2
3/**
4 * A minimal subset of java.io.StringReader.
5 * (http://hg.openjdk.java.net/jdk7/jdk7
6 * /jdk/file/9b8c96f96a0f/src/share/classes/java/io/StringReader.java)
7 *
8 * @author Pacien TRAN-GIRARD
9 */
10public class StringReader extends Reader {
11
12 private final String str;
13 private int index;
14
15 public StringReader(final String str) {
16 this.str = str;
17 }
18
19 @Override
20 public int read() {
21 if (this.str == null) {
22 return -1;
23 }
24 if (this.index >= this.str.length()) {
25 return -1;
26 }
27 this.index++;
28 return this.str.charAt(this.index);
29 }
30
31 @Override
32 public int read(final char[] cbuf, final int off, final int len) {
33 if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) > cbuf.length) || ((off + len) < 0)) {
34 throw new IndexOutOfBoundsException();
35 }
36 if (len == 0) {
37 return 0;
38 }
39 if (this.str == null) {
40 return -1;
41 }
42 if (this.index >= this.str.length()) {
43 return -1;
44 }
45 final int n = Math.min(this.str.length() - this.index, len);
46 this.str.getChars(this.index, this.index + n, cbuf, off);
47 this.index += n;
48 return n;
49 }
50
51} \ No newline at end of file
diff --git a/src/rejava/io/StringWriter.java b/src/rejava/io/StringWriter.java
new file mode 100644
index 0000000..cee4c97
--- /dev/null
+++ b/src/rejava/io/StringWriter.java
@@ -0,0 +1,29 @@
1package rejava.io;
2
3/**
4 * A minimal subset of java.io.StringReader.
5 * (http://hg.openjdk.java.net/jdk7/jdk7/jdk/file
6 * /9b8c96f96a0f/src/share/classes/java/io/StringWriter.java)
7 *
8 * @author Pacien TRAN-GIRARD
9 */
10public class StringWriter extends Writer {
11
12 private final StringBuilder buf = new StringBuilder();
13
14 @Override
15 public void write(final String str) {
16 this.buf.append(str);
17 }
18
19 @Override
20 public void write(final char c) {
21 this.buf.append(c);
22 }
23
24 @Override
25 public String toString() {
26 return this.buf.toString();
27 }
28
29} \ No newline at end of file
diff --git a/src/rejava/io/Writer.java b/src/rejava/io/Writer.java
new file mode 100644
index 0000000..469924b
--- /dev/null
+++ b/src/rejava/io/Writer.java
@@ -0,0 +1,16 @@
1package rejava.io;
2
3/**
4 * A minimal version of java.io.Writer.
5 * (http://hg.openjdk.java.net/jdk7/jdk7/jdk
6 * /file/9b8c96f96a0f/src/share/classes/java/io/Writer.java)
7 *
8 * @author Pacien TRAN-GIRARD
9 */
10public abstract class Writer {
11
12 public abstract void write(String str);
13
14 public abstract void write(char c);
15
16} \ No newline at end of file
diff --git a/src/rejava/io/package-info.java b/src/rejava/io/package-info.java
new file mode 100644
index 0000000..82c78ef
--- /dev/null
+++ b/src/rejava/io/package-info.java
@@ -0,0 +1,6 @@
1/**
2 * A lighter version of some Java IO classes that can be converted to JavaScript.
3 * Made to port org.json.simple to GWT.
4 */
5package rejava.io;
6
diff --git a/src/rejava/io/rejavaio.gwt.xml b/src/rejava/io/rejavaio.gwt.xml
new file mode 100644
index 0000000..34ca1b2
--- /dev/null
+++ b/src/rejava/io/rejavaio.gwt.xml
@@ -0,0 +1,3 @@
1<module rename-to="rejavaio">
2 <source path=""/>
3</module> \ No newline at end of file