Package org.opends.server.loggers
Class MeteredStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.opends.server.loggers.MeteredStream
-
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
public final class MeteredStream extends OutputStream
A metered stream is a subclass of OutputStream that (a) forwards all its output to a target stream (b) keeps track of how many bytes have been written.
-
-
Constructor Summary
Constructors Constructor Description MeteredStream(OutputStream out, long written)
Create the stream wrapped around the specified output stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close the output stream which closes the target output stream.void
flush()
Flush the output stream which flushes the target output stream.long
getBytesWritten()
Returns the number of bytes written in this stream.void
write(byte[] buff)
void
write(byte[] buff, int off, int len)
void
write(int b)
-
Methods inherited from class java.io.OutputStream
nullOutputStream
-
-
-
-
Constructor Detail
-
MeteredStream
public MeteredStream(OutputStream out, long written)
Create the stream wrapped around the specified output stream.- Parameters:
out
- The target output stream to keep track of.written
- The number of bytes written to the stream.
-
-
Method Detail
-
write
public void write(int b) throws IOException
- Specified by:
write
in classOutputStream
- Throws:
IOException
-
write
public void write(byte[] buff) throws IOException
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
write
public void write(byte[] buff, int off, int len) throws IOException
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
flush
public void flush() throws IOException
Flush the output stream which flushes the target output stream.- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
- if the flush failed.
-
close
public void close() throws IOException
Close the output stream which closes the target output stream.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
- if the close failed.
-
getBytesWritten
public long getBytesWritten()
Returns the number of bytes written in this stream.- Returns:
- the number of bytes
-
-