From 0e435c7d172d35149811787061b13e89fb912922 Mon Sep 17 00:00:00 2001 From: adam Date: Sat, 17 Mar 2007 08:49:45 +0000 Subject: [PATCH] factor out Fountain.ByteArray darcs-hash:20070317084945-5007d-5b83c591d453f90523b345fb847732479df3a2a4.gz --- src/org/ibex/io/Fountain.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/org/ibex/io/Fountain.java b/src/org/ibex/io/Fountain.java index ddf66e4..8e2561c 100644 --- a/src/org/ibex/io/Fountain.java +++ b/src/org/ibex/io/Fountain.java @@ -31,6 +31,16 @@ 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); } @@ -38,12 +48,9 @@ public interface Fountain { 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 { -- 1.7.10.4