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

Method skipUpTo

output/java_guava/1.4.19/ByteStreams.java:802–820  ·  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

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