Class MagicNumberStream

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public final class MagicNumberStream
    extends InputStream
    This class defines a set of informations that could distinguish a file content from another one. It is also known as Magic Number on several operating systems.
    Since:
    14.0
    Version:
    17.0 2020-01-04 14:41:40
    Author:
    Stéphane GALLAND
    Maven Group Id:
    org.arakhne.afc.core
    Maven Artifact Id:
    inputoutput
    • Constructor Detail

      • MagicNumberStream

        MagicNumberStream​(URL url,
                          InputStream is)
        Constructor.
        Parameters:
        url - is the url of the input stream to read.
        is - is the input stream.
    • Method Detail

      • getURL

        public URL getURL()
        Replies the URL of the stream to test.
        Returns:
        the url of the stream to test.
      • setOverridingStream

        public void setOverridingStream​(InputStream newis)
        Set the input stream which may be used in place of the original input stream.
        Parameters:
        newis - is the stream to read.
      • getInputStream

        public InputStream getInputStream()
        Replies the stream read by the magic number API. The replied input stream is the stream linked to the file to test, or the stream passed as parameter of setOverridingStream(InputStream) if invoked.
        Returns:
        the stream read by the magic number API.
      • read

        public byte[] read​(int offset,
                           int length)
                    throws IOException
        Replies the bytes at the specified offset.
        Parameters:
        offset - is the position of the first byte to read.
        length - is the cout of bytes to read.
        Returns:
        the array of red bytes.
        Throws:
        IOException - in case of problems
      • read

        public byte read​(int offset)
                  throws IOException
        Replies a byte at the specified offset.
        Parameters:
        offset - is the position of the byte to read.
        Returns:
        the byte.
        Throws:
        IOException - in case of problems
      • readLine

        public byte[] readLine​(int offset)
                        throws IOException
        Replies the bytes until the next end of the first line (inclusive).
        Parameters:
        offset - is the position of the byte to read.
        Returns:
        the bytes.
        Throws:
        IOException - in case of problems