Add FLAC identifier and fix comments.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 3 Jun 2013 20:27:50 +0000 (22:27 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 4 Jun 2013 04:21:45 +0000 (06:21 +0200)
src/main/java/net/pterodactylus/sonitus/io/IdentifyingInputStream.java

index 6035cbf..3a4a9fb 100644 (file)
@@ -84,8 +84,19 @@ public class IdentifyingInputStream extends FilterInputStream {
                /* remember everything we read here. */
                RememberingInputStream rememberingInputStream = new RememberingInputStream(inputStream);
 
-               /* try Ogg Vorbis first. */
+               /* first, try formats with unambiguous layouts. */
                try {
+                       Optional<Metadata> metadata = FlacIdentifier.identify(rememberingInputStream);
+                       if (metadata.isPresent()) {
+                               return Optional.of(new IdentifyingInputStream(rememberingInputStream.remembered(), metadata.get()));
+                       }
+               } catch (EOFException eofe1) {
+                       /* ignore. */
+               }
+
+               /* try Ogg Vorbis next. */
+               try {
+                       rememberingInputStream = new RememberingInputStream(rememberingInputStream.remembered());
                        Optional<Metadata> metadata = OggVorbisIdentifier.identify(rememberingInputStream);
                        if (metadata.isPresent()) {
                                return Optional.of(new IdentifyingInputStream(rememberingInputStream.remembered(), metadata.get()));
@@ -94,7 +105,7 @@ public class IdentifyingInputStream extends FilterInputStream {
                        /* ignore. */
                }
 
-               /* try MP3 now. */
+               /* finally, try MP3. */
                try {
                        rememberingInputStream = new RememberingInputStream(rememberingInputStream.remembered());
                        InputStream limitedInputStream = ByteStreams.limit(rememberingInputStream, 1048576);