projects
/
sonitus.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add filter that supports changing sources.
[sonitus.git]
/
src
/
main
/
java
/
net
/
pterodactylus
/
sonitus
/
io
/
OggVorbisIdentifier.java
diff --git
a/src/main/java/net/pterodactylus/sonitus/io/OggVorbisIdentifier.java
b/src/main/java/net/pterodactylus/sonitus/io/OggVorbisIdentifier.java
index
ab732b8
..
49daa27
100644
(file)
--- 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 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;
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;
/**
import com.jcraft.jorbis.Info;
/**
- * Identifies Ogg Vorbis files.
+ * Identifies Ogg Vorbis files. <p> All knowledge used in this class has been
+ * taken from <a href="http://www.jcraft.com/jorbis/tutorial/Tutorial.html">jcraft.com/jorbis/tutorial/Tutorial.html</a>.
+ * </p>
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
@@
-49,10
+52,13
@@
public class OggVorbisIdentifier {
* Format} describing the stream.
*
* @param inputStream
* 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
* @throws IOException
+ * if an I/O error occurs
*/
*/
- public static
Format
identify(InputStream inputStream) throws IOException {
+ public static
Optional<Format>
identify(InputStream inputStream) throws IOException {
/* stuff needed to decode Ogg. */
Packet packet = new Packet();
/* 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:
syncState.wrote(read);
switch (syncState.pageout(page)) {
case -1:
-
throw new IdentifierException("Hole in Ogg data!"
);
+
return Optional.absent(
);
case 1:
if (!streamStateInitialized) {
/* init stream state. */
case 1:
if (!streamStateInitialized) {
/* init stream state. */
@@
-90,11
+96,11
@@
public class OggVorbisIdentifier {
streamStateInitialized = true;
}
if (streamState.pagein(page) == -1) {
streamStateInitialized = true;
}
if (streamState.pagein(page) == -1) {
-
throw new IdentifierException("Error parsing Ogg data!"
);
+
return Optional.absent(
);
}
switch (streamState.packetout(packet)) {
case -1:
}
switch (streamState.packetout(packet)) {
case -1:
-
throw new IdentifierException("Error parsing Ogg data!"
);
+
return Optional.absent(
);
case 1:
info.synthesis_headerin(comment, packet);
packetsRead++;
case 1:
info.synthesis_headerin(comment, packet);
packetsRead++;
@@
-109,7
+115,7
@@
public class OggVorbisIdentifier {
buffer = syncState.data;
}
buffer = syncState.data;
}
- return
new Format(info.channels, info.rate, "Vorbis"
);
+ return
Optional.of(new Format(info.channels, info.rate, "Vorbis")
);
}
}
}
}