01: package de.regnis.q.sequence.line;
02:
03: import java.io.*;
04:
05: /**
06: * @author Marc Strapetz
07: */
08: public final class QSequenceLineRAByteData implements
09: QSequenceLineRAData {
10:
11: // Constants ==============================================================
12:
13: public static QSequenceLineRAByteData create(InputStream is)
14: throws IOException {
15: final ByteArrayOutputStream os = new ByteArrayOutputStream();
16: for (;;) {
17: final int b = is.read();
18: if (b == -1) {
19: break;
20: }
21:
22: os.write(b);
23: }
24:
25: return new QSequenceLineRAByteData(os.toByteArray());
26: }
27:
28: // Fields =================================================================
29:
30: private final byte[] bytes;
31:
32: // Setup ==================================================================
33:
34: public QSequenceLineRAByteData(byte[] bytes) {
35: this .bytes = bytes;
36: }
37:
38: // Implemented ============================================================
39:
40: public long length() {
41: return bytes.length;
42: }
43:
44: public void get(byte[] bytes, long offset, long length) {
45: System.arraycopy(this .bytes, (int) offset, bytes, 0,
46: (int) length);
47: }
48:
49: public InputStream read(long offset, long length) {
50: return new ByteArrayInputStream(bytes, (int) offset,
51: (int) length);
52: }
53: }
|