1 36 package org.columba.ristretto.io; 37 38 import java.io.IOException ; 39 import java.io.InputStream ; 40 41 46 public class MemBufferInputStream extends InputStream { 47 48 private MemBuffer buffer; 49 50 private int pos; 51 52 57 public MemBufferInputStream(MemBuffer buffer) { 58 this.buffer = buffer; 59 } 60 61 64 public int read() throws IOException { 65 if( buffer.size() == pos) return -1; 66 else return buffer.get(pos++); 67 } 68 69 72 public int available() throws IOException { 73 return buffer.size() - pos; 74 } 75 78 public void close() throws IOException { 79 buffer = null; 80 } 81 84 public int read(byte[] b, int off, int len) throws IOException { 85 int result = buffer.get(pos, b, off, len); 86 pos += result; 87 if( result == 0 ) return -1; 88 else return result; 89 } 90 93 public long skip(long n) throws IOException { 94 return pos += n; 95 } 96 99 public MemBuffer getBuffer() { 100 return buffer; 101 } 102 } 103 | Popular Tags |