MCPcopy Create free account
hub / github.com/antlr/codebuff / skipUpTo

Method skipUpTo

corpus/java/training/guava/io/ByteStreams.java:768–790  ·  view source on GitHub ↗

Discards up to n bytes of data from the input stream. This method will block until either the full amount has been skipped or until the end of the stream is reached, whichever happens first. Returns the total number of bytes skipped.

(InputStream in, final long n)

Source from the content-addressed store, hash-verified

766 * happens first. Returns the total number of bytes skipped.
767 */
768 static long skipUpTo(InputStream in, final long n) throws IOException {
769 long totalSkipped = 0;
770 byte[] buf = createBuffer();
771
772 while (totalSkipped < n) {
773 long remaining = n - totalSkipped;
774 long skipped = skipSafely(in, remaining);
775
776 if (skipped == 0) {
777 // Do a buffered read since skipSafely could return 0 repeatedly, for example if
778 // in.available() always returns 0 (the default).
779 int skip = (int) Math.min(remaining, buf.length);
780 if ((skipped = in.read(buf, 0, skip)) == -1) {
781 // Reached EOF
782 break;
783 }
784 }
785
786 totalSkipped += skipped;
787 }
788
789 return totalSkipped;
790 }
791
792 /**
793 * Attempts to skip up to {@code n} bytes from the given input stream, but not more than

Callers 3

sliceStreamMethod · 0.95
skipFullyMethod · 0.95
countBySkippingMethod · 0.45

Calls 4

createBufferMethod · 0.95
skipSafelyMethod · 0.95
minMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected