+ public static class SubFountain implements Fountain {
+ private final Fountain f;
+ private final int start;
+ private final int len;
+ public SubFountain(Fountain f, int start) { this(f, start, -1); }
+ public SubFountain(Fountain f, int start, int len) {
+ this.f = f;
+ this.start = start;
+ this.len = len;
+ }
+ public Stream getStream() {
+ Stream s = f.getStream();
+ // FIXME: this is really fragile and IMAP needs it
+ int remain = start;
+ while(remain > 0) {
+ long result = s.skip(start);
+ Log.error("skip", result + " / " + start);
+ if (result == -1) return s;
+ remain -= result;
+ }
+ if (len != -1) s.setLimit(len);
+ return s;
+ }
+ public long getLength() {
+ if (len == -1) return f.getLength()-start;
+ return Math.min(f.getLength()-start, len);
+ }
+ public int getNumLines() { return Stream.countLines(getStream()); }
+ }
+