summaryrefslogtreecommitdiff
path: root/altoslib/AltosStringInputStream.java
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2017-05-28 14:00:15 -0700
committerKeith Packard <keithp@keithp.com>2017-05-28 14:04:21 -0700
commitda914cd72411af8c36af05b13c11b9093c8a378c (patch)
tree9443f90fbf21315b609631c300bfb4acb3ac23da /altoslib/AltosStringInputStream.java
parent9e1295ff74d03f940fc68e6795bf30687162a440 (diff)
altoslib: Create data file open helper in AltosLib
Use InputStream everywhere, instead of Reader. Create private string input stream as java one is deprecated. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altoslib/AltosStringInputStream.java')
-rw-r--r--altoslib/AltosStringInputStream.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/altoslib/AltosStringInputStream.java b/altoslib/AltosStringInputStream.java
new file mode 100644
index 00000000..d574db24
--- /dev/null
+++ b/altoslib/AltosStringInputStream.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright © 2017 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ */
+
+package org.altusmetrum.altoslib_11;
+
+import java.util.*;
+import java.io.*;
+
+public class AltosStringInputStream extends InputStream {
+
+ String s;
+ int at;
+ int mark;
+
+ public int available() {
+ return s.length() - at;
+ }
+
+ public void mark(int read_limit) {
+ mark = at;
+ }
+
+ public boolean markSupported() {
+ return true;
+ }
+
+ public int read() {
+ if (at == s.length())
+ return -1;
+ return (int) s.charAt(at++);
+ }
+
+ public void reset() {
+ at = mark;
+ }
+
+ public long skip(long n) throws IOException {
+ if (n < 0) n = 0;
+
+ if (at + n > s.length())
+ n = s.length() - at;
+ at += n;
+ return n;
+ }
+
+ public AltosStringInputStream(String s) {
+ this.s = s;
+ this.at = 0;
+ }
+}