Class MatroskaFileReader


  • public class MatroskaFileReader
    extends java.lang.Object
    Handles reading of elements and their content from an MKV file.
    • Constructor Detail

      • MatroskaFileReader

        public MatroskaFileReader​(SeekableInputStream inputStream)
        Parameters:
        inputStream - Input stream to read from.
    • Method Detail

      • readNextElement

        public MatroskaElement readNextElement​(MatroskaElement parent)
                                        throws java.io.IOException
        Parameters:
        parent - The parent element to use for bounds checking, null is valid.
        Returns:
        The element whose header was read. Null if the parent/file has ended. The contents of this element are only valid until the next element at the same level is read, use MatroskaElement.frozen() to get a permanent instance.
        Throws:
        java.io.IOException - On read error
      • readBlockHeader

        public MatroskaBlock readBlockHeader​(MatroskaElement parent,
                                             int trackFilter)
                                      throws java.io.IOException
        Reads one Matroska block header. The data is of the block is not read, but can be read frame by frame using MatroskaBlock.getNextFrameBuffer(MatroskaFileReader, int).
        Parameters:
        parent - The block parent element.
        trackFilter - The ID of the track to read data for from the block.
        Returns:
        An instance of a block if it contains data for the requested track, null otherwise.
        Throws:
        java.io.IOException - On read error.
      • asInteger

        public int asInteger​(MatroskaElement element)
                      throws java.io.IOException
        Parameters:
        element - Element to read from
        Returns:
        The contents of the element as an integer
        Throws:
        java.io.IOException - On read error
      • asLong

        public long asLong​(MatroskaElement element)
                    throws java.io.IOException
        Parameters:
        element - Element to read from
        Returns:
        The contents of the element as a long
        Throws:
        java.io.IOException - On read error
      • asFloat

        public float asFloat​(MatroskaElement element)
                      throws java.io.IOException
        Parameters:
        element - Element to read from
        Returns:
        The contents of the element as a float
        Throws:
        java.io.IOException - On read error
      • asDouble

        public double asDouble​(MatroskaElement element)
                        throws java.io.IOException
        Parameters:
        element - Element to read from
        Returns:
        The contents of the element as a double
        Throws:
        java.io.IOException - On read error
      • asString

        public java.lang.String asString​(MatroskaElement element)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • asString

        public java.lang.String asString​(MatroskaElement element,
                                         java.nio.charset.Charset forceCharset)
                                  throws java.io.IOException
        Parameters:
        element - Element to read from
        forceCharset - The charset to use, or null for default.
        Returns:
        The contents of the element as a string
        Throws:
        java.io.IOException - On read error
      • asBytes

        public byte[] asBytes​(MatroskaElement element)
                       throws java.io.IOException
        Parameters:
        element - Element to read from
        Returns:
        The contents of the element as a byte array
        Throws:
        java.io.IOException - On read error
      • skip

        public void skip​(MatroskaElement element)
                  throws java.io.IOException
        Parameters:
        element - Element to skip over
        Throws:
        java.io.IOException - On read error
      • getPosition

        public long getPosition()
        Returns:
        Returns the current absolute position of the file.
      • seek

        public void seek​(long position)
                  throws java.io.IOException
        Seeks to the specified position.
        Parameters:
        position - The position in bytes.
        Throws:
        java.io.IOException - On read error
      • getDataInput

        public java.io.DataInput getDataInput()