• R/O
  • HTTP
  • SSH
  • HTTPS

dictzip-java: Commit


Commit MetaInfo

Revision141078c170586d9373c2bc3c0d5a510693c34ae5 (tree)
Zeit2022-04-16 16:32:33
AutorHiroshi Miura <miurahr@linu...>
CommiterHiroshi Miura

Log Message

Fix seek method to return actual seek size

Signed-off-by: Hiroshi Miura <miurahr@linux.com>

Ändern Zusammenfassung

Diff

--- a/dictzip-lib/src/main/java/org/dict/zip/RandomAccessInputStream.java
+++ b/dictzip-lib/src/main/java/org/dict/zip/RandomAccessInputStream.java
@@ -227,30 +227,39 @@ public class RandomAccessInputStream extends InputStream {
227227
228228 /**
229229 * Seek file position.
230+ * <p>
231+ * when specified position is beyond of end of the file, position is set to end of file.
230232 *
231233 * @param pos file position in byte.
232234 * @exception IOException if an I/O error has occurred.
233235 */
234236 public final void seek(final long pos) throws IOException {
235237 if (pos < 0) {
236- currentpos = 0;
238+ throw new IOException("seek position is less than 0");
237239 } else {
238240 currentpos = Math.min(pos, length());
239241 }
240242 }
241243
242244 /**
243- * {@inheritDoc}
245+ * Skip n byte of input stream.
246+ * <p>
247+ * when n is less than 0, it seek backward.
248+ *
249+ * @param n the number of bytes to be skipped.
250+ * @return the actual number of bytes skipped.
251+ * @throws IOException if the stream does not support seek, or if some other I/O error occurs.
244252 */
245253 @Override
246- public final long skip(final long size) throws IOException {
247- if (size < 0 && currentpos + size < 0) {
254+ public final long skip(final long n) throws IOException {
255+ long previous = currentpos;
256+ if (n < 0 && currentpos + n < 0) {
248257 currentpos = 0;
249- } else if (currentpos + size > length()) {
258+ } else if (currentpos + n > length()) {
250259 currentpos = length();
251260 } else {
252- currentpos += size;
261+ currentpos += n;
253262 }
254- return currentpos;
263+ return currentpos - previous;
255264 }
256265 }
Show on old repository browser