From ef136195e508933d207ba9bd0899a942273aba73 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 14 Mar 2013 22:21:26 +0100 Subject: [PATCH] Throw a custom exception if a stream can not be identified. --- .../sonitus/io/IdentifierException.java | 67 ++++++++++++++++++++++ .../sonitus/io/OggVorbisIdentifier.java | 6 +- 2 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 src/main/java/net/pterodactylus/sonitus/io/IdentifierException.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 index 0000000..e6c03f6 --- /dev/null +++ b/src/main/java/net/pterodactylus/sonitus/io/IdentifierException.java @@ -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 . + */ + +package net.pterodactylus.sonitus.io; + +import java.io.IOException; + +/** + * Exception that signals that a stream could not be identified by {@link + * IdentifyingInputStream}. + * + * @author David ‘Bombe’ Roden + */ +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); + } + +} diff --git a/src/main/java/net/pterodactylus/sonitus/io/OggVorbisIdentifier.java b/src/main/java/net/pterodactylus/sonitus/io/OggVorbisIdentifier.java index 64ad2dd..ab732b8 100644 --- a/src/main/java/net/pterodactylus/sonitus/io/OggVorbisIdentifier.java +++ b/src/main/java/net/pterodactylus/sonitus/io/OggVorbisIdentifier.java @@ -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++; -- 2.7.4