From 4aab519eaf3e420e070de871c798cf7ae96aa755 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 19 Mar 2013 21:25:27 +0100 Subject: [PATCH] Ignore EOF exceptions when identifying streams. --- .../sonitus/io/IdentifyingInputStream.java | 25 +++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/pterodactylus/sonitus/io/IdentifyingInputStream.java b/src/main/java/net/pterodactylus/sonitus/io/IdentifyingInputStream.java index faf4f01..6035cbf 100644 --- a/src/main/java/net/pterodactylus/sonitus/io/IdentifyingInputStream.java +++ b/src/main/java/net/pterodactylus/sonitus/io/IdentifyingInputStream.java @@ -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 = OggVorbisIdentifier.identify(rememberingInputStream); - if (metadata.isPresent()) { - return Optional.of(new IdentifyingInputStream(rememberingInputStream.remembered(), metadata.get())); + try { + Optional 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 = Mp3Identifier.identify(limitedInputStream); + if (metadata.isPresent()) { + return Optional.of(new IdentifyingInputStream(rememberingInputStream.remembered(), metadata.get())); + } + } catch (EOFException eofe1) { + /* ignore. */ } return Optional.absent(); -- 2.7.4