1 36 package org.columba.ristretto.io; 37 38 import java.io.IOException ; 39 import java.io.InputStream ; 40 41 47 public class SourceInputStream extends InputStream { 48 49 private Source source; 50 private int pos; 51 52 57 public SourceInputStream(Source source ) { 58 this.source = source; 59 pos = 0; 60 } 61 62 65 public int read() throws IOException { 66 if( pos >= source.length()) return -1; 67 return source.charAt(pos++); 68 } 69 70 73 public int read(byte[] arg0, int arg1, int arg2) throws IOException { 74 int next; 75 for( int i=0; i<arg2; i++) { 76 next = read(); 77 if( next == -1 ) { 78 if( i == 0 ) { 79 return -1; 80 } else { 81 return i; 82 } 83 } 84 arg0[arg1+i] = (byte) next; 85 } 86 return arg2; 87 } 88 89 92 public int available() throws IOException { 93 return source.length() - pos; 94 } 95 96 99 public void close() throws IOException { 100 source.close(); 101 } 102 103 } 104 | Popular Tags |