Moves ns characters in the source string. Unlike the Reader#skip(long) overridden method, this method may skip negative skip distances: this rewinds the input so that characters may be read again. When the end of the source string has been reached, the input cannot be rewound. @para
(long ns)
| 239 | * @see #reset() |
| 240 | */ |
| 241 | @Override |
| 242 | public long skip(long ns) throws IOException { |
| 243 | synchronized (lock) { |
| 244 | if (isClosed()) { |
| 245 | throw new IOException("StringReader already closed"); //$NON-NLS-1$ |
| 246 | } |
| 247 | |
| 248 | int minSkip = -pos; |
| 249 | int maxSkip = count - pos; |
| 250 | |
| 251 | if (maxSkip == 0 || ns > maxSkip) { |
| 252 | ns = maxSkip; // no rewinding if we're at the end |
| 253 | } else if (ns < minSkip) { |
| 254 | ns = minSkip; |
| 255 | } |
| 256 | |
| 257 | pos += ns; |
| 258 | return ns; |
| 259 | } |
| 260 | } |
| 261 | } |