X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsonitus%2Fio%2FOggVorbisIdentifier.java;h=49daa2780459842a858d51a35881450a79864418;hb=00af65503a2076371291ce8e019da2546458bdac;hp=64ad2ddab94f6c3058d681e5b28bb9130541937c;hpb=3b99111c3d082841f0a7f5819103fb3db6ba8447;p=sonitus.git diff --git a/src/main/java/net/pterodactylus/sonitus/io/OggVorbisIdentifier.java b/src/main/java/net/pterodactylus/sonitus/io/OggVorbisIdentifier.java index 64ad2dd..49daa27 100644 --- a/src/main/java/net/pterodactylus/sonitus/io/OggVorbisIdentifier.java +++ b/src/main/java/net/pterodactylus/sonitus/io/OggVorbisIdentifier.java @@ -22,6 +22,7 @@ import java.io.InputStream; import net.pterodactylus.sonitus.data.Format; +import com.google.common.base.Optional; import com.jcraft.jogg.Packet; import com.jcraft.jogg.Page; import com.jcraft.jogg.StreamState; @@ -30,7 +31,9 @@ import com.jcraft.jorbis.Comment; import com.jcraft.jorbis.Info; /** - * Identifies Ogg Vorbis files. + * Identifies Ogg Vorbis files.

All knowledge used in this class has been + * taken from jcraft.com/jorbis/tutorial/Tutorial.html. + *

* * @author David ‘Bombe’ Roden */ @@ -49,10 +52,13 @@ public class OggVorbisIdentifier { * Format} describing the stream. * * @param inputStream - * @return + * The input stream to identify as Ogg Vorbis + * @return The identified format, or {@link com.google.common.base.Optional#absent()} + * if the stream could not be identified * @throws IOException + * if an I/O error occurs */ - public static Format identify(InputStream inputStream) throws IOException { + public static Optional identify(InputStream inputStream) throws IOException { /* stuff needed to decode Ogg. */ Packet packet = new Packet(); @@ -79,7 +85,7 @@ public class OggVorbisIdentifier { syncState.wrote(read); switch (syncState.pageout(page)) { case -1: - throw new IOException("Hole in Ogg data!"); + return Optional.absent(); case 1: if (!streamStateInitialized) { /* init stream state. */ @@ -90,11 +96,11 @@ public class OggVorbisIdentifier { streamStateInitialized = true; } if (streamState.pagein(page) == -1) { - throw new IOException("Error parsing Ogg data!"); + return Optional.absent(); } switch (streamState.packetout(packet)) { case -1: - throw new IOException("Error parsing Ogg data!"); + return Optional.absent(); case 1: info.synthesis_headerin(comment, packet); packetsRead++; @@ -109,7 +115,7 @@ public class OggVorbisIdentifier { buffer = syncState.data; } - return new Format(info.channels, info.rate, "Vorbis"); + return Optional.of(new Format(info.channels, info.rate, "Vorbis")); } }