1 36 package org.columba.ristretto.coder; 37 38 import java.io.FilterInputStream ; 39 import java.io.IOException ; 40 import java.io.InputStream ; 41 42 48 public class CRLFFilterInputStream extends FilterInputStream { 49 50 protected byte[] buffer = new byte[1024]; 51 protected int pos = 0; 52 protected int count = -1; 53 54 59 public CRLFFilterInputStream( InputStream in ) { 60 super( in ); 61 } 62 63 64 67 public int read() throws IOException { 68 int next = in.read(); 69 while( next == '\r' || next == '\n') { 70 next = in.read(); 71 } 72 if( next == -1 ) return -1; 73 74 return next; 75 } 76 77 80 public int read(byte[] arg0, int arg1, int arg2) throws IOException { 81 int next; 82 for( int i=0; i<arg2; i++) { 83 next = read(); 84 if( next == -1 ) { 85 if( i == 0 ) { 86 return -1; 87 } else { 88 return i; 89 } 90 } 91 arg0[arg1+i] = (byte) next; 92 } 93 return arg2; 94 } 95 96 97 } 98 | Popular Tags |