Ignore EOF exceptions when identifying streams.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 19 Mar 2013 20:25:27 +0000 (21:25 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 27 May 2013 20:54:37 +0000 (22:54 +0200)
src/main/java/net/pterodactylus/sonitus/io/IdentifyingInputStream.java

index faf4f01..6035cbf 100644 (file)
@@ -17,6 +17,7 @@
 
 package net.pterodactylus.sonitus.io;
 
+import java.io.EOFException;
 import java.io.FilterInputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -84,17 +85,25 @@ public class IdentifyingInputStream extends FilterInputStream {
                RememberingInputStream rememberingInputStream = new RememberingInputStream(inputStream);
 
                /* try Ogg Vorbis first. */
-               Optional<Metadata> metadata = OggVorbisIdentifier.identify(rememberingInputStream);
-               if (metadata.isPresent()) {
-                       return Optional.of(new IdentifyingInputStream(rememberingInputStream.remembered(), metadata.get()));
+               try {
+                       Optional<Metadata> metadata = OggVorbisIdentifier.identify(rememberingInputStream);
+                       if (metadata.isPresent()) {
+                               return Optional.of(new IdentifyingInputStream(rememberingInputStream.remembered(), metadata.get()));
+                       }
+               } catch (EOFException eofe1) {
+                       /* ignore. */
                }
 
                /* try MP3 now. */
-               rememberingInputStream = new RememberingInputStream(rememberingInputStream.remembered());
-               InputStream limitedInputStream = ByteStreams.limit(rememberingInputStream, 1048576);
-               metadata = Mp3Identifier.identify(limitedInputStream);
-               if (metadata.isPresent()) {
-                       return Optional.of(new IdentifyingInputStream(rememberingInputStream.remembered(), metadata.get()));
+               try {
+                       rememberingInputStream = new RememberingInputStream(rememberingInputStream.remembered());
+                       InputStream limitedInputStream = ByteStreams.limit(rememberingInputStream, 1048576);
+                       Optional<Metadata> metadata = Mp3Identifier.identify(limitedInputStream);
+                       if (metadata.isPresent()) {
+                               return Optional.of(new IdentifyingInputStream(rememberingInputStream.remembered(), metadata.get()));
+                       }
+               } catch (EOFException eofe1) {
+                       /* ignore. */
                }
 
                return Optional.absent();