author | dholmes |
Wed, 06 Nov 2019 21:18:42 -0500 | |
changeset 58956 | 9a0a5e70eeb2 |
parent 52860 | 8dd8965df7f6 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
52860
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
52860
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
24 |
/** |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
25 |
* @test |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
26 |
* @bug 4016710 6516099 |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
27 |
* @summary check for correct implementation of InputStream.skip{NBytes} |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
28 |
*/ |
2 | 29 |
|
52860
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
30 |
import java.io.EOFException; |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
31 |
import java.io.InputStream; |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
32 |
import java.io.IOException; |
2 | 33 |
|
52860
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
34 |
public class Skip { |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
35 |
private static final int EOF = -1; |
2 | 36 |
|
52860
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
37 |
private static void dotest(InputStream in, int curpos, long total, |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
38 |
long toskip, long expected) throws Exception { |
2 | 39 |
try { |
40 |
System.err.println("\n\nCurrently at pos = " + curpos + |
|
41 |
"\nTotal bytes in the Stream = " + total + |
|
42 |
"\nNumber of bytes to skip = " + toskip + |
|
43 |
"\nNumber of bytes that should be skipped = " + |
|
44 |
expected); |
|
45 |
||
46 |
long skipped = in.skip(toskip); |
|
47 |
||
48 |
System.err.println("actual number skipped: "+ skipped); |
|
49 |
||
50 |
if ((skipped < 0) || (skipped > expected)) { |
|
52860
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
51 |
throw new RuntimeException("Unexpected byte count skipped"); |
2 | 52 |
} |
53 |
} catch (IOException e) { |
|
52860
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
54 |
System.err.println("IOException is thrown: " + e); |
2 | 55 |
} catch (Throwable e) { |
52860
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
56 |
throw new RuntimeException("Unexpected " + e + " is thrown!"); |
2 | 57 |
} |
52860
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
58 |
} |
2 | 59 |
|
52860
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
60 |
private static void dotestExact(MyInputStream in, long curpos, long total, |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
61 |
long toskip, boolean expectIOE, boolean expectEOFE) { |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
62 |
|
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
63 |
System.err.println("\n\nCurrently at pos = " + curpos + |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
64 |
"\nTotal bytes in the Stream = " + total + |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
65 |
"\nNumber of bytes to skip = " + toskip); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
66 |
|
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
67 |
try { |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
68 |
long pos = in.position(); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
69 |
assert pos == curpos : pos + " != " + curpos; |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
70 |
in.skipNBytes(toskip); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
71 |
if (in.position() != pos + (toskip < 0 ? 0 : toskip)) { |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
72 |
throw new RuntimeException((in.position() - pos) + |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
73 |
" bytes skipped; expected " + toskip); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
74 |
} |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
75 |
} catch (EOFException eofe) { |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
76 |
if (!expectEOFE) { |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
77 |
throw new RuntimeException("Unexpected EOFException", eofe); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
78 |
} |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
79 |
System.err.println("Caught expected EOFException"); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
80 |
} catch (IOException ioe) { |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
81 |
if (!expectIOE) { |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
82 |
throw new RuntimeException("Unexpected IOException", ioe); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
83 |
} |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
84 |
System.err.println("Caught expected IOException"); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
85 |
} |
2 | 86 |
} |
87 |
||
88 |
public static void main( String argv[] ) throws Exception { |
|
89 |
MyInputStream in = new MyInputStream(11); |
|
90 |
||
52860
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
91 |
// test for negative skip |
2 | 92 |
dotest(in, 0, 11, -23, 0); |
93 |
||
52860
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
94 |
// check for skip beyond EOF starting from before EOF |
2 | 95 |
dotest(in, 0, 11, 20, 11); |
96 |
||
52860
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
97 |
// check for skip after EOF |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
98 |
dotest(in, EOF, 11, 20, 0); |
2 | 99 |
|
100 |
in = new MyInputStream(9000); |
|
52860
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
101 |
|
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
102 |
// check for skip equal to the read chunk size in InputStream.java |
2 | 103 |
dotest(in, 0, 9000, 2048, 2048); |
104 |
||
52860
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
105 |
// check for skip larger than the read chunk size in InputStream.java |
2 | 106 |
dotest(in, 2048, 9000, 5000, 5000); |
107 |
||
52860
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
108 |
// check for skip beyond EOF starting from before EOF |
2 | 109 |
dotest(in, 7048, 9000, 5000, 1952); |
110 |
||
111 |
in = new MyInputStream(5000); |
|
112 |
||
52860
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
113 |
// check for multiple chunk reads |
2 | 114 |
dotest(in, 0, 5000, 6000, 5000); |
115 |
||
116 |
/* |
|
117 |
* check for skip larger than Integer.MAX_VALUE |
|
118 |
* (Takes about 2 hrs on a sparc ultra-1) |
|
119 |
* long total = (long)Integer.MAX_VALUE + (long)10; |
|
120 |
* long toskip = total - (long)6; |
|
121 |
* in = new MyInputStream(total); |
|
122 |
* dotest(in, 0, total, toskip, toskip); |
|
123 |
*/ |
|
124 |
||
52860
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
125 |
// tests for skipping an exact number of bytes |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
126 |
|
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
127 |
final long streamLength = Long.MAX_VALUE; |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
128 |
in = new MyInputStream(streamLength); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
129 |
|
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
130 |
// negative skip: OK |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
131 |
dotestExact(in, 0, streamLength, -1, false, false); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
132 |
|
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
133 |
// negative skip at EOF: OK |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
134 |
in.position(streamLength); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
135 |
dotestExact(in, streamLength, streamLength, -1, false, false); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
136 |
in.position(0); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
137 |
|
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
138 |
// zero skip: OK |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
139 |
dotestExact(in, 0, streamLength, 0, false, false); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
140 |
|
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
141 |
// zero skip at EOF: OK |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
142 |
in.position(streamLength); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
143 |
dotestExact(in, streamLength, streamLength, 0, false, false); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
144 |
|
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
145 |
// skip(1) at EOF: EOFE |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
146 |
dotestExact(in, streamLength, streamLength, 1, false, true); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
147 |
in.position(0); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
148 |
|
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
149 |
final long n = 31; // skip count |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
150 |
long pos = 0; |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
151 |
|
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
152 |
// skip(n) returns negative value: IOE |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
153 |
in.setState(-1, 100); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
154 |
dotestExact(in, pos, streamLength, n, true, false); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
155 |
|
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
156 |
// skip(n) returns n + 1: IOE |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
157 |
in.setState(n + 1, 100); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
158 |
dotestExact(in, pos, streamLength, n, true, false); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
159 |
pos += n + 1; |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
160 |
|
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
161 |
// skip(n) returns n/2 but only n/4 subsequent reads succeed: EOFE |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
162 |
in.setState(n/2, n/2 + n/4); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
163 |
dotestExact(in, pos, streamLength, n, false, true); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
164 |
pos += n/2 + n/4; |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
165 |
|
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
166 |
// skip(n) returns n/2 but n - n/2 subsequent reads succeed: OK |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
167 |
in.setState(n/2, n); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
168 |
dotestExact(in, pos, streamLength, n, false, false); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
169 |
pos += n; |
2 | 170 |
} |
171 |
} |
|
172 |
||
173 |
class MyInputStream extends InputStream { |
|
52860
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
174 |
private static final int EOF = -1; |
2 | 175 |
|
52860
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
176 |
private final long endoffile; |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
177 |
|
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
178 |
private long readctr = 0; |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
179 |
|
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
180 |
private boolean isStateSet = false; |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
181 |
private long skipReturn; |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
182 |
private long readLimit; |
2 | 183 |
|
184 |
public MyInputStream(long endoffile) { |
|
185 |
this.endoffile = endoffile; |
|
186 |
} |
|
187 |
||
52860
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
188 |
/** |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
189 |
* Limits the behavior of skip() and read(). |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
190 |
* |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
191 |
* @param skipReturn the value to be returned by skip() |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
192 |
* @param maxReads the maximum number of reads past the current position |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
193 |
* before EOF is reached |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
194 |
*/ |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
195 |
public void setState(long skipReturn, long maxReads) { |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
196 |
this.skipReturn = skipReturn; |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
197 |
this.readLimit = readctr + maxReads; |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
198 |
isStateSet = true; |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
199 |
} |
2 | 200 |
|
52860
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
201 |
public int read() { |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
202 |
if (readctr == endoffile || |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
203 |
(isStateSet && readctr >= readLimit)) { |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
204 |
return EOF; |
2 | 205 |
} |
206 |
else { |
|
207 |
readctr++; |
|
208 |
return 0; |
|
209 |
} |
|
210 |
} |
|
211 |
||
212 |
public int available() { return 0; } |
|
52860
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
213 |
|
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
214 |
public long position() { return readctr; } |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
215 |
|
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
216 |
public void position(long pos) { |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
217 |
readctr = pos < 0 ? 0 : Math.min(pos, endoffile); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
218 |
} |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
219 |
|
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
220 |
public long skip(long n) throws IOException { |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
221 |
if (isStateSet) { |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
222 |
return skipReturn < 0 ? skipReturn : super.skip(skipReturn); |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
223 |
} |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
224 |
|
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
225 |
// InputStream skip implementation. |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
226 |
return super.skip(n); // readctr is implicitly incremented |
8dd8965df7f6
6516099: InputStream.skipFully(int k) to skip exactly k bytes
bpb
parents:
47216
diff
changeset
|
227 |
} |
2 | 228 |
} |