MCPcopy Index your code
hub / github.com/antlr/codebuff / skipUpTo

Method skipUpTo

output/java_guava/1.4.17/ByteStreams.java:800–818  ·  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

798
799
800 static long skipUpTo(InputStream in, final long n) throws IOException {
801 long totalSkipped = 0;
802 byte[] buf = createBuffer();
803 while (totalSkipped < n) {
804 long remaining = n - totalSkipped;
805 long skipped = skipSafely(in, remaining);
806 if (skipped == 0) {
807 // Do a buffered read since skipSafely could return 0 repeatedly, for example if
808 // in.available() always returns 0 (the default).
809 int skip = (int) Math.min(remaining, buf.length);
810 if ((skipped = in.read(buf, 0, skip)) == -1) {
811 // Reached EOF
812 break;
813 }
814 }
815 totalSkipped += skipped;
816 }
817 return totalSkipped;
818 }
819
820 /**
821 * 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