public class DataFileSource extends Object implements DataSource
A DataSource
implementation based on a file.
Constructor and Description |
---|
DataFileSource(File file)
Creates a source.
|
DataFileSource(File file,
boolean resettable)
Creates a source.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
InputStream |
getInputStream()
Returns a stream for reading the data.
|
long |
getLength()
Returns the length of the data which can be read from the source in
bytes.
|
String |
getName()
Returns the name of the source.
|
boolean |
isResettable()
Returns the flag if the source can be reseted.
|
void |
reset()
Resets the source.
|
public DataFileSource(File file, boolean resettable)
Creates a source.
The stream on the file will be opened the first time the
getInputStream()
method is called.
file
- The file.resettable
- The flag if the reset()
method will be supported.IllegalArgumentException
- If the file is null
.public DataFileSource(File file)
Creates a source.
The stream on the file will be opened the first time the
getInputStream()
method is called.
The reset()
method will be supported.
file
- The file.IllegalArgumentException
- If the file is null
.public String getName()
DataSource
Returns the name of the source.
This name is used e.g. for detail messages of exceptions.
getName
in interface DataSource
public long getLength()
DataSource
Returns the length of the data which can be read from the source in bytes.
getLength
in interface DataSource
-1
, if the length is unknown.public boolean isResettable()
DataSource
Returns the flag if the source can be reseted.
isResettable
in interface DataSource
true
, if the source can be reseted,
false
otherwise.DataSource.reset()
public void reset() throws IOException
DataSource
Resets the source.
If the source can't be reseted an IOException
will be thrown.
If the source can be reseted the next call of the
DataSource.getInputStream()
method will return a new InputStream
which reads the source from the beginning again.
reset
in interface DataSource
IOException
- If an I/O error occurs or if the source doesn't support a
reset.DataSource.isResettable()
public InputStream getInputStream() throws IOException
DataSource
Returns a stream for reading the data.
The method will always return the same InputStream
if the source
is still open. If the InputStream.close()
method is called the
source will behave the same as the Closeable.close()
method was called.
If the DataSource.reset()
method was successfully called the method will
return a different InputStream
.
getInputStream
in interface DataSource
IOException
- If an I/O error occurs.public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
Copyright © 2015–2019. All rights reserved.