Package de.jarnbjo.ogg
Class CachedUrlStream
java.lang.Object
de.jarnbjo.ogg.CachedUrlStream
- All Implemented Interfaces:
PhysicalOggStream
Implementation of the
PhysicalOggStream interface for reading and
caching an Ogg stream from a URL. This class reads the data as fast as
possible from the URL, caches it locally either in memory or on disk, and
supports seeking within the available data.-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionCachedUrlStream(URL source) Creates an instance of this class, using a memory cache.CachedUrlStream(URL source, RandomAccessFile drain) Creates an instance of this class, using the specified file as cache. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this stream.longReturns a collection of objects implementingLogicalOggStreamfor accessing the separate logical streams within this physical Ogg stream.getOggPage(int index) Return the Ogg page with the absolute indexindex, independent of the logical structure of this stream or if the index parameter is -1, the next Ogg page is returned.booleanisOpen()Checks if this stream is open for reading.booleanvoidsetTime(long granulePosition) Sets this stream's (and its logical stream's) position to the granule position.
-
Constructor Details
-
CachedUrlStream
Creates an instance of this class, using a memory cache.- Parameters:
source-- Throws:
OggFormatExceptionIOException
-
CachedUrlStream
Creates an instance of this class, using the specified file as cache. The file is not automatically deleted when this class is disposed.- Parameters:
source-drain-- Throws:
OggFormatExceptionIOException
-
-
Method Details
-
getLogicalStreams
Description copied from interface:PhysicalOggStreamReturns a collection of objects implementingLogicalOggStreamfor accessing the separate logical streams within this physical Ogg stream.- Specified by:
getLogicalStreamsin interfacePhysicalOggStream- Returns:
- a collection of objects implementing
LogicalOggStreamwhich are representing the logical streams contained within this physical stream - See Also:
-
isOpen
public boolean isOpen()Description copied from interface:PhysicalOggStreamChecks if this stream is open for reading.- Specified by:
isOpenin interfacePhysicalOggStream- Returns:
trueif this stream is open for reading,falseotherwise
-
close
Description copied from interface:PhysicalOggStreamCloses this stream. After invoking this method, no further access to the stream's data is possible.- Specified by:
closein interfacePhysicalOggStream- Throws:
IOException
-
getCacheLength
public long getCacheLength() -
getOggPage
Description copied from interface:PhysicalOggStreamReturn the Ogg page with the absolute indexindex, independent of the logical structure of this stream or if the index parameter is -1, the next Ogg page is returned. This method should only be used by implementations ofLogicalOggStreamto access the raw pages.- Specified by:
getOggPagein interfacePhysicalOggStream- Parameters:
index- the absolute index starting from 0 at the beginning of the file or stream or -1 to get the next page in a non-seekable stream- Returns:
- the Ogg page with the physical absolute index
index - Throws:
OggFormatException- if the ogg stream is corruptedIOException- if some other IO error occurs
-
setTime
Description copied from interface:PhysicalOggStreamSets this stream's (and its logical stream's) position to the granule position. The next packet read from any logical stream will be the first packet beginning on the first page with a granule position higher than the argument.
At the moment, this method only works correctly for Ogg files with a single logical Vorbis stream, and due to the different interpretations of the granule position, depending on mixed content, this method will never be able to work for mixed streams. Chained and interleaved streams are also not yet supported. Actually, this method is only a hack to support seeking from JMF, but may of course be abused otherwise too :)- Specified by:
setTimein interfacePhysicalOggStream- Throws:
OggFormatException- if the ogg stream is corruptedIOException- if some other IO error occurs
-
isSeekable
public boolean isSeekable()- Specified by:
isSeekablein interfacePhysicalOggStream- Returns:
trueif the stream is seekable,falseotherwise
-