From: David ‘Bombe’ Roden Date: Tue, 19 Mar 2013 20:25:27 +0000 (+0100) Subject: Ignore EOF exceptions when identifying streams. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=4aab519eaf3e420e070de871c798cf7ae96aa755;p=sonitus.git Ignore EOF exceptions when identifying streams. --- 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();