X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsonitus%2Fio%2FOggVorbisIdentifier.java;h=769acf2f1a910e2babe8b50659c013d1fe477734;hb=5b3515c2fe22320f0a0d8e2e2f10145c89a4cf92;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..769acf2 100644 --- a/src/main/java/net/pterodactylus/sonitus/io/OggVorbisIdentifier.java +++ b/src/main/java/net/pterodactylus/sonitus/io/OggVorbisIdentifier.java @@ -20,8 +20,9 @@ package net.pterodactylus.sonitus.io; import java.io.IOException; import java.io.InputStream; -import net.pterodactylus.sonitus.data.Format; +import net.pterodactylus.sonitus.data.Metadata; +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 */ @@ -46,13 +49,16 @@ public class OggVorbisIdentifier { /** * Tries to parse the given stream as Ogg Vorbis file and returns a {@link - * Format} describing the stream. + * Metadata} describing the stream. * * @param inputStream - * @return + * The input stream to identify as Ogg Vorbis + * @return The identified metadata, or {@link 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 Metadata(info.channels, info.rate, "Vorbis")); } }