src/java.base/share/classes/java/io/ObjectInputStream.java

Print this page
rev 11155 : 8067870: Fix java.io.ObjectInputStream.PeekInputStream#skip
Reviewed-by: King Julien


2328             int n = 0;
2329             while (n < len) {
2330                 int count = read(b, off + n, len - n);
2331                 if (count < 0) {
2332                     throw new EOFException();
2333                 }
2334                 n += count;
2335             }
2336         }
2337 
2338         public long skip(long n) throws IOException {
2339             if (n <= 0) {
2340                 return 0;
2341             }
2342             int skipped = 0;
2343             if (peekb >= 0) {
2344                 peekb = -1;
2345                 skipped++;
2346                 n--;
2347             }
2348             return skipped + skip(n);
2349         }
2350 
2351         public int available() throws IOException {
2352             return in.available() + ((peekb >= 0) ? 1 : 0);
2353         }
2354 
2355         public void close() throws IOException {
2356             in.close();
2357         }
2358     }
2359 
2360     /**
2361      * Input stream with two modes: in default mode, inputs data written in the
2362      * same format as DataOutputStream; in "block data" mode, inputs data
2363      * bracketed by block data markers (see object serialization specification
2364      * for details).  Buffering depends on block data mode: when in default
2365      * mode, no data is buffered in advance; when in block data mode, all data
2366      * for the current data block is read in at once (and buffered).
2367      */
2368     private class BlockDataInputStream




2328             int n = 0;
2329             while (n < len) {
2330                 int count = read(b, off + n, len - n);
2331                 if (count < 0) {
2332                     throw new EOFException();
2333                 }
2334                 n += count;
2335             }
2336         }
2337 
2338         public long skip(long n) throws IOException {
2339             if (n <= 0) {
2340                 return 0;
2341             }
2342             int skipped = 0;
2343             if (peekb >= 0) {
2344                 peekb = -1;
2345                 skipped++;
2346                 n--;
2347             }
2348             return skipped + in.skip(n);
2349         }
2350 
2351         public int available() throws IOException {
2352             return in.available() + ((peekb >= 0) ? 1 : 0);
2353         }
2354 
2355         public void close() throws IOException {
2356             in.close();
2357         }
2358     }
2359 
2360     /**
2361      * Input stream with two modes: in default mode, inputs data written in the
2362      * same format as DataOutputStream; in "block data" mode, inputs data
2363      * bracketed by block data markers (see object serialization specification
2364      * for details).  Buffering depends on block data mode: when in default
2365      * mode, no data is buffered in advance; when in block data mode, all data
2366      * for the current data block is read in at once (and buffered).
2367      */
2368     private class BlockDataInputStream