You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ta...@apache.org on 2018/08/03 17:50:50 UTC

[tika] 03/03: TIKA-2704

This is an automated email from the ASF dual-hosted git repository.

tallison pushed a commit to branch branch_1x
in repository https://gitbox.apache.org/repos/asf/tika.git

commit 36fa58f4c298248398749be927e6fdb9868e5676
Author: TALLISON <ta...@apache.org>
AuthorDate: Fri Aug 3 13:49:54 2018 -0400

    TIKA-2704
---
 .../org/apache/tika/parser/mp3/MpegStream.java     | 34 +++++++---------------
 1 file changed, 10 insertions(+), 24 deletions(-)

diff --git a/tika-parsers/src/main/java/org/apache/tika/parser/mp3/MpegStream.java b/tika-parsers/src/main/java/org/apache/tika/parser/mp3/MpegStream.java
index 83a9c87..1814c12 100644
--- a/tika-parsers/src/main/java/org/apache/tika/parser/mp3/MpegStream.java
+++ b/tika-parsers/src/main/java/org/apache/tika/parser/mp3/MpegStream.java
@@ -16,6 +16,9 @@
  */
 package org.apache.tika.parser.mp3;
 
+import org.apache.poi.util.IOUtils;
+
+import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PushbackInputStream;
@@ -157,7 +160,12 @@ class MpegStream extends PushbackInputStream
     {
         if (currentHeader != null)
         {
-            skipStream(in, currentHeader.getLength() - HEADER_SIZE);
+            long toSkip = currentHeader.getLength() - HEADER_SIZE;
+            long skipped = IOUtils.skipFully(in, toSkip);
+            if (skipped < toSkip) {
+                throw new EOFException("EOF: tried to skip "+toSkip +
+                        " but could only skip "+skipped);
+            }
             currentHeader = null;
             return true;
         }
@@ -267,28 +275,6 @@ class MpegStream extends PushbackInputStream
     }
 
     /**
-     * Skips the given number of bytes from the specified input stream.
-     * 
-     * @param in the input stream
-     * @param count the number of bytes to skip
-     * @throws IOException if an IO error occurs
-     */
-    private static void skipStream(InputStream in, long count)
-            throws IOException
-    {
-        long size = count;
-        long skipped = 0;
-        while (size > 0 && skipped >= 0)
-        {
-            skipped = in.skip(size);
-            if (skipped != -1)
-            {
-                size -= skipped;
-            }
-        }
-    }
-    
-    /**
      * Calculates the bit rate based on the given parameters.
      * 
      * @param mpegVer the MPEG version
@@ -428,7 +414,7 @@ class MpegStream extends PushbackInputStream
          * index. E.g. ''from'' = 0, ''to'' = 3 will return the value of the
          * first 4 bits.
          * 
-         * @param the from index
+         * @param from index
          * @param to the to index
          * @return the value of this group of bits
          */