1 7 8 package java.io; 9 10 28 public abstract class InputStream implements Closeable { 29 30 private static final int SKIP_BUFFER_SIZE = 2048; 32 private static byte[] skipBuffer; 34 35 49 public abstract int read() throws IOException ; 50 51 88 public int read(byte b[]) throws IOException { 89 return read(b, 0, b.length); 90 } 91 92 154 public int read(byte b[], int off, int len) throws IOException { 155 if (b == null) { 156 throw new NullPointerException (); 157 } else if ((off < 0) || (off > b.length) || (len < 0) || 158 ((off + len) > b.length) || ((off + len) < 0)) { 159 throw new IndexOutOfBoundsException (); 160 } else if (len == 0) { 161 return 0; 162 } 163 164 int c = read(); 165 if (c == -1) { 166 return -1; 167 } 168 b[off] = (byte)c; 169 170 int i = 1; 171 try { 172 for (; i < len ; i++) { 173 c = read(); 174 if (c == -1) { 175 break; 176 } 177 if (b != null) { 178 b[off + i] = (byte)c; 179 } 180 } 181 } catch (IOException ee) { 182 } 183 return i; 184 } 185 186 204 public long skip(long n) throws IOException { 205 206 long remaining = n; 207 int nr; 208 if (skipBuffer == null) 209 skipBuffer = new byte[SKIP_BUFFER_SIZE]; 210 211 byte[] localSkipBuffer = skipBuffer; 212 213 if (n <= 0) { 214 return 0; 215 } 216 217 while (remaining > 0) { 218 nr = read(localSkipBuffer, 0, 219 (int) Math.min(SKIP_BUFFER_SIZE, remaining)); 220 if (nr < 0) { 221 break; 222 } 223 remaining -= nr; 224 } 225 226 return n - remaining; 227 } 228 229 244 public int available() throws IOException { 245 return 0; 246 } 247 248 257 public void close() throws IOException {} 258 259 283 public synchronized void mark(int readlimit) {} 284 285 330 public synchronized void reset() throws IOException { 331 throw new IOException ("mark/reset not supported"); 332 } 333 334 346 public boolean markSupported() { 347 return false; 348 } 349 350 } 351 | Popular Tags |