]> gcc.gnu.org Git - gcc.git/blob - libjava/java/io/InputStream.java
ZipFile.java: Compute the offset of the ZipEntry data correctly.
[gcc.git] / libjava / java / io / InputStream.java
1 /* Copyright (C) 1998, 1999 Cygnus Solutions
2
3 This file is part of libgcj.
4
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
7 details. */
8
9 package java.io;
10
11 /**
12 * @author Warren Levy <warrenl@cygnus.com>
13 * @date October 2, 1998.
14 */
15 /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
16 * "The Java Language Specification", ISBN 0-201-63451-1
17 * plus online API docs for JDK 1.2 beta from http://www.javasoft.com.
18 * Status: Believed complete and correct.
19 */
20
21 public abstract class InputStream
22 {
23 public InputStream()
24 {
25 }
26
27 public int available() throws IOException
28 {
29 return 0;
30 }
31
32 public void close() throws IOException
33 {
34 // Do nothing
35 }
36
37 public void mark(int readlimit)
38 {
39 // Do nothing
40 }
41
42 public boolean markSupported()
43 {
44 return false;
45 }
46
47 public abstract int read() throws IOException;
48
49 public int read(byte[] b) throws IOException
50 {
51 return read(b, 0, b.length);
52 }
53
54 public int read(byte[] b, int off, int len) throws IOException
55 {
56 if (off < 0 || len < 0 || off + len > b.length)
57 throw new IndexOutOfBoundsException();
58 if (b.length == 0)
59 return 0;
60
61 int i, ch;
62
63 for (i = 0; i < len; ++i)
64 try
65 {
66 if ((ch = read()) < 0)
67 return i == 0 ? -1 : i; // EOF
68 b[off + i] = (byte) ch;
69 }
70 catch (IOException ex)
71 {
72 // Only reading the first byte should cause an IOException.
73 if (i == 0)
74 throw ex;
75 return i;
76 }
77
78 return i;
79 }
80
81 public void reset() throws IOException
82 {
83 throw new IOException("mark/reset not supported");
84 }
85
86 public long skip(long n) throws IOException
87 {
88 // Throw away n bytes by reading them into a temp byte[].
89 // Limit the temp array to 2Kb so we don't grab too much memory.
90 final int buflen = n > 2048 ? 2048 : (int) n;
91 byte[] tmpbuf = new byte[buflen];
92 final long origN = n;
93
94 while (n > 0L)
95 {
96 int numread = read(tmpbuf, 0, n > buflen ? buflen : (int) n);
97 if (numread <= 0)
98 break;
99 n -= numread;
100 }
101
102 return origN - n;
103 }
104 }
This page took 0.039869 seconds and 5 git commands to generate.