Class MagicNumberStream
- java.lang.Object
-
- java.io.InputStream
-
- org.arakhne.afc.inputoutput.filetype.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 Summary
Constructors Constructor Description MagicNumberStream(URL url, InputStream is)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
InputStream
getInputStream()
Replies the stream read by the magic number API.URL
getURL()
Replies the URL of the stream to test.int
read()
byte
read(int offset)
Replies a byte at the specified offset.byte[]
read(int offset, int length)
Replies the bytes at the specified offset.byte[]
readLine(int offset)
Replies the bytes until the next end of the first line (inclusive).void
resetOverridingStream()
Cancel any previous call tosetOverridingStream(InputStream)
.void
setOverridingStream(InputStream newis)
Set the input stream which may be used in place of the original input stream.-
Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, read, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
-
-
-
-
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.
-
resetOverridingStream
public void resetOverridingStream()
Cancel any previous call tosetOverridingStream(InputStream)
.
-
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 ofsetOverridingStream(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
-
read
public int read() throws IOException
- Specified by:
read
in classInputStream
- Throws:
IOException
-
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
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
-