Throw a custom exception if a stream can not be identified.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 14 Mar 2013 21:21:26 +0000 (22:21 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 14 Mar 2013 21:21:26 +0000 (22:21 +0100)
src/main/java/net/pterodactylus/sonitus/io/IdentifierException.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sonitus/io/OggVorbisIdentifier.java

diff --git a/src/main/java/net/pterodactylus/sonitus/io/IdentifierException.java b/src/main/java/net/pterodactylus/sonitus/io/IdentifierException.java
new file mode 100644 (file)
index 0000000..e6c03f6
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Sonitus - IdentifierException.java - Copyright © 2013 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sonitus.io;
+
+import java.io.IOException;
+
+/**
+ * Exception that signals that a stream could not be identified by {@link
+ * IdentifyingInputStream}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class IdentifierException extends IOException {
+
+       /** Creates a new identifier exception. */
+       public IdentifierException() {
+               super();
+       }
+
+       /**
+        * Creates a new identifier exception.
+        *
+        * @param message
+        *              The message of the exception
+        */
+       public IdentifierException(String message) {
+               super(message);
+       }
+
+       /**
+        * Creates a new identifier exception.
+        *
+        * @param cause
+        *              The root cause of the exception
+        */
+       public IdentifierException(Throwable cause) {
+               super(cause);
+       }
+
+       /**
+        * Creates a new identifier exception.
+        *
+        * @param message
+        *              The message of the exception
+        * @param cause
+        *              The root cause of the exception
+        */
+       public IdentifierException(String message, Throwable cause) {
+               super(message, cause);
+       }
+
+}
index 64ad2dd..ab732b8 100644 (file)
@@ -79,7 +79,7 @@ public class OggVorbisIdentifier {
                        syncState.wrote(read);
                        switch (syncState.pageout(page)) {
                                case -1:
-                                       throw new IOException("Hole in Ogg data!");
+                                       throw new IdentifierException("Hole in Ogg data!");
                                case 1:
                                        if (!streamStateInitialized) {
                                                /* init stream state. */
@@ -90,11 +90,11 @@ public class OggVorbisIdentifier {
                                                streamStateInitialized = true;
                                        }
                                        if (streamState.pagein(page) == -1) {
-                                               throw new IOException("Error parsing Ogg data!");
+                                               throw new IdentifierException("Error parsing Ogg data!");
                                        }
                                        switch (streamState.packetout(packet)) {
                                                case -1:
-                                                       throw new IOException("Error parsing Ogg data!");
+                                                       throw new IdentifierException("Error parsing Ogg data!");
                                                case 1:
                                                        info.synthesis_headerin(comment, packet);
                                                        packetsRead++;