Class LazyFileInputStream
- java.lang.Object
-
- java.io.InputStream
-
- de.japrost.jabudget.serialization.LazyFileInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class LazyFileInputStream extends java.io.InputStream
AnInputStream
that uses aFileInputStream
internally, which is created when the first acces is done. OnInputStream.close()
the internalFileInputStream
will be closed and unset that next reading all will get a new stream.
-
-
Constructor Summary
Constructors Constructor Description LazyFileInputStream(java.io.File file)
Create aLazyFileInputStream
to be based on the givenFile
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
void
close()
java.nio.channels.FileChannel
getChannel()
Initializes the delegate if not already done and delegates toFileInputStream.getChannel()
.java.io.FileDescriptor
getFD()
Initializes the delegate if not already done and delegates toFileInputStream.getFD()
.boolean
isOpen()
Tell if the delegate is initialized.int
read()
int
read(byte[] b)
int
read(byte[] b, int off, int len)
byte[]
readAllBytes()
int
readNBytes(byte[] b, int off, int len)
long
skip(long n)
long
transferTo(java.io.OutputStream out)
-
-
-
Constructor Detail
-
LazyFileInputStream
public LazyFileInputStream(java.io.File file)
Create aLazyFileInputStream
to be based on the givenFile
.- Parameters:
file
- the file to use in the delegate.
-
-
Method Detail
-
read
public int read() throws java.io.IOException
This implementation initializes the delegate if not already done and delegates to
FileInputStream.read()
.- Specified by:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] b) throws java.io.IOException
This implementation initializes the delegate if not already done and delegates to
FileInputStream.read(byte[])
.- Overrides:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException
This implementation initializes the delegate if not already done and delegates to
FileInputStream.read(byte[], int, int)
.- Overrides:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
readNBytes
public int readNBytes(byte[] b, int off, int len) throws java.io.IOException
This implementation initializes the delegate if not already done and delegates to
InputStream.readNBytes(byte[], int, int)
.- Overrides:
readNBytes
in classjava.io.InputStream
- Throws:
java.io.IOException
-
readAllBytes
public byte[] readAllBytes() throws java.io.IOException
This implementation initializes the delegate if not already done and delegates to
InputStream.readAllBytes()
.- Overrides:
readAllBytes
in classjava.io.InputStream
- Throws:
java.io.IOException
-
skip
public long skip(long n) throws java.io.IOException
This implementation initializes the delegate if not already done and delegates to
FileInputStream.skip(long)
.- Overrides:
skip
in classjava.io.InputStream
- Throws:
java.io.IOException
-
available
public int available() throws java.io.IOException
This implementation initializes the delegate if not already done and delegates to
FileInputStream.available()
.- Overrides:
available
in classjava.io.InputStream
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
This implementation calls
FileInputStream.close()
on the delegate and unassignes the delegate.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.InputStream
- Throws:
java.io.IOException
-
getChannel
public java.nio.channels.FileChannel getChannel() throws java.io.FileNotFoundException
Initializes the delegate if not already done and delegates toFileInputStream.getChannel()
.- Returns:
FileInputStream.getChannel()
- Throws:
java.io.FileNotFoundException
- seeFileInputStream(File)
.
-
getFD
public final java.io.FileDescriptor getFD() throws java.io.IOException
Initializes the delegate if not already done and delegates toFileInputStream.getFD()
.- Returns:
FileInputStream.getFD()
- Throws:
java.io.IOException
- seeFileInputStream.getFD()
-
transferTo
public long transferTo(java.io.OutputStream out) throws java.io.IOException
This implementation initializes the delegate if not already done and delegates to
InputStream.transferTo(OutputStream)
.- Overrides:
transferTo
in classjava.io.InputStream
- Throws:
java.io.IOException
-
isOpen
public boolean isOpen()
Tell if the delegate is initialized.- Returns:
true
if there is a delegate.
-
-