Class OggPacketInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class OggPacketInputStream
    extends java.io.InputStream
    This provides a stream for OGG packets where the stream is always bounded to the current packet, and the next packet can be started with startNewPacket(). The same way it is bound to a specific track and the next track can be started with startNewTrack() when the previous one has ended (startNewPacket() has returned false).
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()  
      void close()  
      java.util.List<OggSeekPoint> createSeekTable​(int sampleRate)  
      boolean isPacketComplete()  
      int read()  
      int read​(byte[] buffer, int initialOffset, int length)  
      long seek​(long timecode)
      Seeks the stream to the specified timecode.
      OggStreamSizeInfo seekForSizeInfo​(int sampleRate)
      If it is possible to seek backwards on this stream, and the length of the stream is known, seeks to the end of the track to determine the stream length both in bytes and samples.
      void setSeekPoints​(java.util.List<OggSeekPoint> seekPoints)  
      boolean startNewPacket()
      Load the next packet from the stream.
      boolean startNewTrack()
      Load the next track from the stream.
      • Methods inherited from class java.io.InputStream

        mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • OggPacketInputStream

        public OggPacketInputStream​(SeekableInputStream inputStream,
                                    boolean closeDelegated)
        Parameters:
        inputStream - Input stream to read in as OGG packets
        closeDelegated - Whether closing this stream should close the inputStream as well
    • Method Detail

      • setSeekPoints

        public void setSeekPoints​(java.util.List<OggSeekPoint> seekPoints)
      • startNewTrack

        public boolean startNewTrack()
        Load the next track from the stream. This is only valid when the stream is in a track boundary state.
        Returns:
        True if next track is present in the stream, false if the stream has terminated.
      • startNewPacket

        public boolean startNewPacket()
                               throws java.io.IOException
        Load the next packet from the stream. This is only valid when the stream is in a packet boundary state.
        Returns:
        True if next packet is present in the track. State is PACKET_READ. False if the track is finished. State is either TRACK_BOUNDARY or TERMINATED.
        Throws:
        java.io.IOException - On read error.
      • isPacketComplete

        public boolean isPacketComplete()
      • read

        public int read()
                 throws java.io.IOException
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] buffer,
                        int initialOffset,
                        int length)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • available

        public int available()
                      throws java.io.IOException
        Overrides:
        available in class java.io.InputStream
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.InputStream
        Throws:
        java.io.IOException
      • seek

        public long seek​(long timecode)
                  throws java.io.IOException
        Seeks the stream to the specified timecode.
        Parameters:
        timecode - Timecode in milliseconds to seek to.
        Returns:
        The actual timecode in milliseconds to which the stream was seeked.
        Throws:
        java.io.IOException - On read error.
      • createSeekTable

        public java.util.List<OggSeekPoint> createSeekTable​(int sampleRate)
                                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • seekForSizeInfo

        public OggStreamSizeInfo seekForSizeInfo​(int sampleRate)
                                          throws java.io.IOException
        If it is possible to seek backwards on this stream, and the length of the stream is known, seeks to the end of the track to determine the stream length both in bytes and samples.
        Parameters:
        sampleRate - Sample rate of the track in this stream.
        Returns:
        OGG stream size information.
        Throws:
        java.io.IOException - On read error.