01: package com.jofti.util;
02:
03: import java.io.InputStream;
04: import java.nio.ByteBuffer;
05:
06: public class ByteBufferArrayInputStream extends InputStream {
07:
08: protected ByteBuffer buf = null;
09:
10: public ByteBufferArrayInputStream(ByteBuffer buf) {
11: this .buf = buf;
12:
13: }
14:
15: public final void resetData(ByteBuffer buf) {
16: this .buf = buf;
17: }
18:
19: public final int available() {
20: return buf.remaining();
21: }
22:
23: public final int read() {
24: return buf.get();
25: }
26:
27: public final int read(byte[] b, int off, int len) {
28:
29: if (len > buf.remaining())
30: len = (buf.remaining());
31:
32: buf.get(b, off, len);
33:
34: return len;
35: }
36:
37: public final long skip(long n) {
38: if (n > buf.remaining())
39: n = buf.remaining();
40: if (n < 0)
41: return 0;
42: buf.position(buf.position() + (int) n);
43: return n;
44: }
45:
46: }
|