MCPcopy Create free account
hub / github.com/davidgiven/luje / skip

Method skip

lib/java/io/FileInputStream.java:297–332  ·  view source on GitHub ↗

Skips count number of bytes in this stream. Subsequent read()'s will not return these bytes unless reset() is used. This method may perform multiple reads to read count bytes. @param count the number of bytes to skip. @return the number of bytes actually s

(long count)

Source from the content-addressed store, hash-verified

295 * IOException occurs.
296 */
297 @Override
298 public long skip(long count) throws IOException {
299 openCheck();
300
301 if (count == 0) {
302 return 0;
303 }
304 if (count < 0) {
305 // luni.AC=Number of bytes to skip cannot be negative
306 throw new IOException(Messages.getString("luni.AC")); //$NON-NLS-1$
307 }
308
309 // stdin requires special handling
310 if (fd == FileDescriptor.in) {
311 // Read and discard count bytes in 8k chunks
312 long skipped = 0, numRead;
313 int chunk = count < 8192 ? (int) count : 8192;
314 byte[] buffer = new byte[chunk];
315 for (long i = count / chunk; i >= 0; i--) {
316 numRead = fileSystem.ttyRead(buffer, 0, chunk);
317 skipped += numRead;
318 if (numRead < chunk) {
319 return skipped;
320 }
321 }
322 return skipped;
323 }
324
325 synchronized (repositioningLock) {
326 final long currentPosition = fileSystem.seek(fd.descriptor, 0L,
327 IFileSystem.SEEK_CUR);
328 final long newPosition = fileSystem.seek(fd.descriptor,
329 currentPosition + count, IFileSystem.SEEK_SET);
330 return newPosition - currentPosition;
331 }
332 }
333
334 private synchronized void openCheck() throws IOException {
335 if (fd.descriptor < 0) {

Callers

nothing calls this directly

Calls 4

openCheckMethod · 0.95
getStringMethod · 0.95
ttyReadMethod · 0.65
seekMethod · 0.65

Tested by

no test coverage detected