1 22 23 package gnu.mail.util; 24 25 import java.io.BufferedInputStream ; 26 import java.io.FilterInputStream ; 27 import java.io.IOException ; 28 import java.io.InputStream ; 29 30 import javax.mail.Session ; 31 32 44 public class ReadFilterInputStream 45 extends FilterInputStream 46 { 47 51 public ReadFilterInputStream (InputStream in) { 52 super (in); 53 } 54 55 60 public int read (byte[] b) 61 throws IOException 62 { 63 return read (b, 0, b.length); 64 } 65 66 77 public int read (byte[] b, 78 int off, 79 int len) 80 throws IOException 81 { 82 final int EOS = -1; 83 int i = 0; 84 int n; 85 while (i < len && 86 (n = read ()) >= 0) { 87 88 b [off + i] = (byte) n; 89 ++ i; 90 91 } 92 93 int result; 94 if (i > 0) { 95 96 result = i; 97 98 } 99 else { 100 101 result = EOS; 102 103 } 104 105 return result; 106 } 107 } 108 109 | Popular Tags |