@Test public void testSkip() throws IOException { final Reader reader = new CharSequenceReader("FooBar"); assertEquals(3, reader.skip(3)); checkRead(reader, "Bar"); assertEquals(-1, reader.skip(3)); reader.reset(); assertEquals(2, reader.skip(2)); assertEquals(4, reader.skip(10)); assertEquals(-1, reader.skip(1)); reader.close(); assertEquals(6, reader.skip(20)); assertEquals(-1, reader.read()); }
@Override public long skip(final long n) { if (n < 0) { throw new IllegalArgumentException( "Number of characters to skip is less than zero: " + n); } if (idx >= charSequence.length()) { return EOF; } final int dest = (int)Math.min(charSequence.length(), idx + n); final int count = dest - idx; idx = dest; return count; }
CharSequenceReader extends Reader implements Serializable { @Override public long skip(final long n) { if (n < 0) { throw new IllegalArgumentException( "Number of characters to skip is less than zero: " + n); } if (idx >= charSequence.length()) { return EOF; } final int dest = (int)Math.min(charSequence.length(), idx + n); final int count = dest - idx; idx = dest; return count; } }
CharSequenceReader extends Reader implements Serializable { @Override public long skip(final long n) { if (n < 0) { throw new IllegalArgumentException( "Number of characters to skip is less than zero: " + n); } if (idx >= charSequence.length()) { return EOF; } final int dest = (int)Math.min(charSequence.length(), idx + n); final int count = dest - idx; idx = dest; return count; } CharSequenceReader(final CharSequence charSequence); }
CharSequenceReader extends Reader implements Serializable { @Override public long skip(final long n) { if (n < 0) { throw new IllegalArgumentException( "Number of characters to skip is less than zero: " + n); } if (idx >= charSequence.length()) { return EOF; } final int dest = (int)Math.min(charSequence.length(), idx + n); final int count = dest - idx; idx = dest; return count; } CharSequenceReader(final CharSequence charSequence); @Override void close(); @Override void mark(final int readAheadLimit); @Override boolean markSupported(); @Override int read(); @Override int read(final char[] array, final int offset, final int length); @Override void reset(); @Override long skip(final long n); @Override String toString(); }
CharSequenceReader extends Reader implements Serializable { @Override public long skip(final long n) { if (n < 0) { throw new IllegalArgumentException( "Number of characters to skip is less than zero: " + n); } if (idx >= charSequence.length()) { return EOF; } final int dest = (int)Math.min(charSequence.length(), idx + n); final int count = dest - idx; idx = dest; return count; } CharSequenceReader(final CharSequence charSequence); @Override void close(); @Override void mark(final int readAheadLimit); @Override boolean markSupported(); @Override int read(); @Override int read(final char[] array, final int offset, final int length); @Override void reset(); @Override long skip(final long n); @Override String toString();  }