1 19 20 package com.maverick.util; 21 22 import java.io.*; 23 import java.io.InputStream ; 24 25 class EOLProcessorInputStream extends InputStream { 26 27 EOLProcessor processor; 28 InputStream in; 29 DynamicBuffer buf = new DynamicBuffer(); 30 byte[] tmp = new byte[32768]; 31 32 public EOLProcessorInputStream(int inputStyle, 33 int outputStyle, 34 InputStream in) throws IOException { 35 this.in = in; 36 processor = new EOLProcessor(inputStyle, 37 outputStyle, 38 buf.getOutputStream()); 39 } 40 41 49 public int read() throws IOException { 50 fillBuffer(1); 51 return buf.getInputStream().read(); 52 } 53 54 public int available() throws IOException { 55 return in.available(); 56 } 57 58 public int read(byte[] b, int off, int len) throws IOException { 59 fillBuffer(len); 60 return buf.getInputStream().read(b, off, len); 61 } 62 63 private void fillBuffer(int count) throws IOException { 64 65 while(buf.available() < count) { 66 int read = in.read(tmp); 67 if(read == -1) { 68 buf.close(); 69 return; 70 } 71 processor.processBytes(tmp, 0, read); 72 } 73 } 74 75 public void close() throws IOException { 76 in.close(); 77 } 78 } 79 | Popular Tags |