KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jofti > util > ByteBufferArrayInputStream


1 package com.jofti.util;
2
3 import java.io.InputStream JavaDoc;
4 import java.nio.ByteBuffer JavaDoc;
5
6
7
8 public class ByteBufferArrayInputStream extends InputStream JavaDoc {
9
10     protected ByteBuffer JavaDoc buf = null;
11
12
13
14     public ByteBufferArrayInputStream(ByteBuffer JavaDoc buf) {
15         this.buf = buf;
16
17     }
18
19     
20     
21     public final void resetData(ByteBuffer JavaDoc buf) {
22         this.buf = buf;
23     }
24     
25     public final int available() {
26         return buf.remaining();
27     }
28
29     public final int read() {
30         return buf.get();
31     }
32
33     public final int read(byte[] b, int off, int len) {
34        
35
36         if (len > buf.remaining())
37             len = (buf.remaining());
38
39         buf.get(b,off,len);
40        
41         return len;
42     }
43
44     public final long skip(long n) {
45         if (n >buf.remaining())
46             n = buf.remaining();
47         if (n < 0)
48             return 0;
49         buf.position(buf.position()+(int)n);
50         return n;
51     }
52
53 }
54
55
Popular Tags