Seeks to the specified position @param position @throws IllegalArgumentException if the position argument is wrong, i.e.: position < 0 or RandomReadingFile#length() <= position @throws IOException if an IOException occurred
(final int position)
| 105 | * @throws IOException if an IOException occurred |
| 106 | */ |
| 107 | public final void seek(final int position) throws IOException { |
| 108 | |
| 109 | if (position == pointer) { |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | if (position < 0 || position >= length()) { |
| 114 | throw new IllegalArgumentException( |
| 115 | "Trying to seek outside file's contents"); |
| 116 | } |
| 117 | |
| 118 | final int pos; |
| 119 | |
| 120 | if (position < pointer) { |
| 121 | /* |
| 122 | * Must go back, i.e. it's necessary to reopen the input stream |
| 123 | */ |
| 124 | |
| 125 | /* |
| 126 | * Close input before reopening it |
| 127 | */ |
| 128 | if (in != null) { |
| 129 | in.close(); |
| 130 | } |
| 131 | |
| 132 | in = file.openDataInputStream(); |
| 133 | pos = position; |
| 134 | } else { |
| 135 | pos = position - pointer; |
| 136 | } |
| 137 | |
| 138 | skipBytes(pos); |
| 139 | |
| 140 | pointer = position; |
| 141 | } |
| 142 | |
| 143 | public final long skip(long n) throws IOException { |
| 144 | return skipBytes((int) n); |
no test coverage detected