From 688634ae5a5aaf663159032e67d2132ea61c5d5f Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sun, 4 May 2014 17:37:41 +0200 Subject: Implement "save" and "load" --- src/rejava/io/Reader.java | 20 ++++++++++++++++ src/rejava/io/StringReader.java | 51 +++++++++++++++++++++++++++++++++++++++++ src/rejava/io/StringWriter.java | 29 +++++++++++++++++++++++ src/rejava/io/Writer.java | 16 +++++++++++++ src/rejava/io/package-info.java | 6 +++++ src/rejava/io/rejavaio.gwt.xml | 3 +++ 6 files changed, 125 insertions(+) create mode 100644 src/rejava/io/Reader.java create mode 100644 src/rejava/io/StringReader.java create mode 100644 src/rejava/io/StringWriter.java create mode 100644 src/rejava/io/Writer.java create mode 100644 src/rejava/io/package-info.java create mode 100644 src/rejava/io/rejavaio.gwt.xml (limited to 'src/rejava') 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 @@ +package rejava.io; + +/** + * A minimal version of java.io.Reader. + * (http://hg.openjdk.java.net/jdk7/jdk7/jdk + * /file/9b8c96f96a0f/src/share/classes/java/io/Reader.java) + * + * @author Pacien TRAN-GIRARD + */ +public abstract class Reader { + + public abstract int read(); + + public abstract int read(final char[] cbuf, final int off, final int len); + + public void close() { + return; + } + +} \ 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 @@ +package rejava.io; + +/** + * A minimal subset of java.io.StringReader. + * (http://hg.openjdk.java.net/jdk7/jdk7 + * /jdk/file/9b8c96f96a0f/src/share/classes/java/io/StringReader.java) + * + * @author Pacien TRAN-GIRARD + */ +public class StringReader extends Reader { + + private final String str; + private int index; + + public StringReader(final String str) { + this.str = str; + } + + @Override + public int read() { + if (this.str == null) { + return -1; + } + if (this.index >= this.str.length()) { + return -1; + } + this.index++; + return this.str.charAt(this.index); + } + + @Override + public int read(final char[] cbuf, final int off, final int len) { + if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) > cbuf.length) || ((off + len) < 0)) { + throw new IndexOutOfBoundsException(); + } + if (len == 0) { + return 0; + } + if (this.str == null) { + return -1; + } + if (this.index >= this.str.length()) { + return -1; + } + final int n = Math.min(this.str.length() - this.index, len); + this.str.getChars(this.index, this.index + n, cbuf, off); + this.index += n; + return n; + } + +} \ 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 @@ +package rejava.io; + +/** + * A minimal subset of java.io.StringReader. + * (http://hg.openjdk.java.net/jdk7/jdk7/jdk/file + * /9b8c96f96a0f/src/share/classes/java/io/StringWriter.java) + * + * @author Pacien TRAN-GIRARD + */ +public class StringWriter extends Writer { + + private final StringBuilder buf = new StringBuilder(); + + @Override + public void write(final String str) { + this.buf.append(str); + } + + @Override + public void write(final char c) { + this.buf.append(c); + } + + @Override + public String toString() { + return this.buf.toString(); + } + +} \ 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 @@ +package rejava.io; + +/** + * A minimal version of java.io.Writer. + * (http://hg.openjdk.java.net/jdk7/jdk7/jdk + * /file/9b8c96f96a0f/src/share/classes/java/io/Writer.java) + * + * @author Pacien TRAN-GIRARD + */ +public abstract class Writer { + + public abstract void write(String str); + + public abstract void write(char c); + +} \ 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 @@ +/** + * A lighter version of some Java IO classes that can be converted to JavaScript. + * Made to port org.json.simple to GWT. + */ +package rejava.io; + 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 @@ + + + \ No newline at end of file -- cgit v1.2.3