Package org.apache.commons.vfs2.util
Class MonitorOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- java.io.BufferedOutputStream
-
- org.apache.commons.vfs2.util.MonitorOutputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public class MonitorOutputStream extends java.io.BufferedOutputStream
An OutputStream that provides buffering and end-of-stream monitoring.
-
-
Constructor Summary
Constructors Constructor Description MonitorOutputStream(java.io.OutputStream out)Constructs a MonitorOutputStream from the passed OutputStream.MonitorOutputStream(java.io.OutputStream out, int bufferSize)Constructs a MonitorOutputStream from the passed OutputStream and with the specified buffer size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidassertOpen()Check if file is still open.voidclose()Closes this output stream.voidflush()protected voidonClose()Called after this stream is closed.voidwrite(byte[] b)voidwrite(byte[] b, int off, int len)voidwrite(int b)
-
-
-
Constructor Detail
-
MonitorOutputStream
public MonitorOutputStream(java.io.OutputStream out)
Constructs a MonitorOutputStream from the passed OutputStream.- Parameters:
out- The output stream to wrap.
-
MonitorOutputStream
public MonitorOutputStream(java.io.OutputStream out, int bufferSize)
Constructs a MonitorOutputStream from the passed OutputStream and with the specified buffer size.- Parameters:
out- The output stream to wrap.bufferSize- The buffer size to use.- Since:
- 2.4
-
-
Method Detail
-
assertOpen
protected void assertOpen() throws FileSystemException
Check if file is still open.This is a workaround for an oddity with Java's BufferedOutputStream where you can write to even if the stream has been closed.
- Throws:
FileSystemException- if already closed.- Since:
- 2.0
-
close
public void close() throws java.io.IOException
Closes this output stream.This makes sure the buffers are flushed, close the output stream and it will call
onClose()and re-throw last exception from any of the three.This does nothing if the stream is closed already.
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.FilterOutputStream- Throws:
java.io.IOException- if an IO error occurs.
-
flush
public void flush() throws java.io.IOException
- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.BufferedOutputStream- Throws:
java.io.IOException- if an error occurs.- Since:
- 2.0
-
onClose
protected void onClose() throws java.io.IOException
Called after this stream is closed.This implementation does nothing.
- Throws:
java.io.IOException- if an error occurs.
-
write
public void write(byte[] b) throws java.io.IOException
- Overrides:
writein classjava.io.FilterOutputStream- Parameters:
b- The byte array.- Throws:
java.io.IOException- if an error occurs.- Since:
- 2.0
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
writein classjava.io.BufferedOutputStream- Parameters:
b- The byte array.off- The offset into the array.len- The number of bytes to write.- Throws:
java.io.IOException- if an error occurs.- Since:
- 2.0
-
write
public void write(int b) throws java.io.IOException
- Overrides:
writein classjava.io.BufferedOutputStream- Parameters:
b- The character to write.- Throws:
java.io.IOException- if an error occurs.- Since:
- 2.0
-
-