Class LazyFileOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- de.japrost.jabudget.serialization.LazyFileOutputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
public class LazyFileOutputStream extends java.io.OutputStream
AnOutputStream
that uses aFileOutputStream
internally, which is created when first access is done. OnOutputStream.close()
the internalFileOutputStream
will be closed and unset that next writing will get a new stream.
-
-
Constructor Summary
Constructors Constructor Description LazyFileOutputStream(java.io.File file)
Create an instance based on the given File.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
flush()
java.nio.channels.FileChannel
getChannel()
Initializes the delegate if not already done and delegates toFileOutputStream.getChannel()
.java.io.FileDescriptor
getFD()
Initializes the delegate if not already done and delegates toFileOutputStream.getFD()
.boolean
isOpen()
Tell if the delegate is initialized.void
write(byte[] b)
void
write(byte[] b, int off, int len)
void
write(int b)
-
-
-
Method Detail
-
close
public void close() throws java.io.IOException
This implementation calls
FileOutputStream.close()
on the delegate and unassigns the delegate.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException
This implementation calls
OutputStream.flush()
on the delegate if it is initalized.- Specified by:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
getChannel
public java.nio.channels.FileChannel getChannel() throws java.io.FileNotFoundException
Initializes the delegate if not already done and delegates toFileOutputStream.getChannel()
.- Returns:
FileOutputStream.getChannel()
- Throws:
java.io.FileNotFoundException
- if initialization of delegate fails. seeFileOutputStream(File)
.
-
getFD
public java.io.FileDescriptor getFD() throws java.io.IOException
Initializes the delegate if not already done and delegates toFileOutputStream.getFD()
.- Returns:
FileOutputStream.getFD()
- Throws:
java.io.IOException
- seeFileOutputStream.getFD()
.java.io.FileNotFoundException
- if initialization of delegate fails. seeFileOutputStream(File)
.
-
write
public void write(byte[] b) throws java.io.IOException
This implementation innitializes the delegate if not already done and delegates to
FileOutputStream.write(byte[])
.- Overrides:
write
in classjava.io.OutputStream
- Throws:
java.io.FileNotFoundException
- if initialization of delegate fails. seeFileOutputStream(File)
.java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException
This implementation innitializes the delegate if not already done and delegates to
FileOutputStream.write(byte[], int, int)
.- Overrides:
write
in classjava.io.OutputStream
- Throws:
java.io.FileNotFoundException
- if initialization of delegate fails. seeFileOutputStream(File)
.java.io.IOException
-
write
public void write(int b) throws java.io.IOException
This implementation innitializes the delegate if not already done and delegates to
FileOutputStream.write(int)
.- Specified by:
write
in classjava.io.OutputStream
- Throws:
java.io.FileNotFoundException
- if initialization of delegate fails. seeFileOutputStream(File)
.java.io.IOException
-
isOpen
public boolean isOpen()
Tell if the delegate is initialized.- Returns:
true
if there is a delegate.
-
-