X-Git-Url: http://git.megacz.com/?p=org.ibex.io.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fio%2FFountain.java;h=8e2561c7938bc4b2c497cb48eaf0234b1796a939;hp=74fb58ebb12587b003432623bd1cebc0c26aad95;hb=0e435c7d172d35149811787061b13e89fb912922;hpb=6f988f279bd8178805390f629553e31587135041 diff --git a/src/org/ibex/io/Fountain.java b/src/org/ibex/io/Fountain.java index 74fb58e..8e2561c 100644 --- a/src/org/ibex/io/Fountain.java +++ b/src/org/ibex/io/Fountain.java @@ -9,34 +9,20 @@ import java.net.*; import java.util.*; import java.util.zip.*; import org.ibex.util.*; +import java.sql.*; /** a source of streams */ public interface Fountain { public Stream getStream(); - public int getLength(); - public int getNumLines(); - /* - public static interface Transformer { - public Fountain transform(Fountain in); - - public static class Lift implements Fountain.Transformer { - private final Stream.Transformer func; - public Lift(Stream.Transformer func) { this.func = func; } - public Fountain transform(final Fountain in) { - return new Fountain() { - public Stream getStream() { - return func.transform(in.getStream()); } }; - } - } - } - */ + public long getLength(); + public int getNumLines(); public static class File implements Fountain { private final java.io.File file; public File(java.io.File file) { this.file = file; } public Stream getStream() { return new Stream(file); } - public int getLength() { return (int)file.length(); } + public long getLength() { return (int)file.length(); } public int getNumLines() { return Stream.countLines(getStream()); } } @@ -45,19 +31,26 @@ public interface Fountain { private final byte[] bytes; private final int off; private final int len; + protected ByteArray(String s) { + try { + byte[] bytes = s.getBytes("UTF-8"); + this.bytes = bytes; + this.off = 0; + this.len = bytes.length; + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + } public ByteArray(byte[] bytes) { this(bytes, 0, bytes.length); } public ByteArray(byte[] bytes, int off, int len) { this.bytes = bytes; this.off=off; this.len=len; } public Stream getStream() { return new Stream(bytes, off, len); } - public int getLength() { return len; } + public long getLength() { return len; } public int getNumLines() { return Stream.countLines(getStream()); } } - public static class StringFountain implements Fountain { - String s; - public StringFountain(String s) { this.s = s; } - public Stream getStream() { return new Stream(s); } - public int getLength() { return s.length(); } // FIXME ENCODING ISSUES!!!!! - public int getNumLines() { return Stream.countLines(getStream()); } + + public static class StringFountain extends ByteArray { + public StringFountain(String s) { super(s); } } public static class Concatenate implements Fountain {