Top Description Fields Constructors Methods
org.apache.derby.iapi.services.io

public Class CounterOutputStream

extends OutputStream
implements Limit
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.services.io.Limit
Imports
java.io.OutputStream, .IOException, .EOFException

An OutputStream that simply provides methods to count the number of bytes written to an underlying stream.

Field Summary

Modifier and TypeField and Description
private int
private int
protected OutputStream

Constructor Summary

AccessConstructor and Description
public
CounterOutputStream()

Create a CounterOutputStream that will discard any bytes written but still coutn them and call its reset method so that the count is intially zero.

Method Summary

Modifier and TypeMethod and Description
public int
clearLimit()

Implements org.apache.derby.iapi.services.io.Limit.clearLimit.

Clear any limit set by setLimit.

public int

Returns:

the number of bytes written since the last reset() call
getCount
()

Get count of bytes written to the stream since the last reset() call.

public void
setLimit(int
The length to set
limit
)

Implements org.apache.derby.iapi.services.io.Limit.setLimit.

Set a limit at which an exception will be thrown.

public void
public void
write(int
the byte.
b
)

Implements abstract java.io.OutputStream.write.

Add 1 to the count.

public void
write(byte[]
the data.
b
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Overrides java.io.OutputStream.write.

Add len to the count, discard the data.

Inherited from java.io.OutputStream:
closeflushnullOutputStreamwrite

Field Detail

countback to summary
private int count
limitback to summary
private int limit
outback to summary
protected OutputStream out

Constructor Detail

CounterOutputStreamback to summary
public CounterOutputStream()

Create a CounterOutputStream that will discard any bytes written but still coutn them and call its reset method so that the count is intially zero.

Method Detail

clearLimitback to summary
public int clearLimit()

Implements org.apache.derby.iapi.services.io.Limit.clearLimit.

Doc from org.apache.derby.iapi.services.io.Limit.clearLimit.

Clear any limit set by setLimit. After this call no limit checking will be made on any read until a setLimit()) call is made.

Returns:int

the number of bytes within the limit that have not been read or written.

getCountback to summary
public int getCount()

Get count of bytes written to the stream since the last reset() call.

Returns:int

the number of bytes written since the last reset() call

setLimitback to summary
public void setLimit(int limit)

Implements org.apache.derby.iapi.services.io.Limit.setLimit.

Set a limit at which an exception will be thrown. This allows callers to count the number of bytes up to some point, without having to complete the count. E.g. a caller may only want to see if some object will write out over 4096 bytes, without waiting for all 200,000 bytes of the object to be written.
If the passed in limit is 0 or negative then the stream will count bytes without throwing an exception.

Parameters
limit:int

Doc from org.apache.derby.iapi.services.io.Limit.setLimit.

The length to set

See Also
EOFException
setOutputStreamback to summary
public void setOutputStream(OutputStream out)
writeback to summary
public void write(int b) throws IOException

Implements abstract java.io.OutputStream.write.

Add 1 to the count.

Parameters
b:int

Doc from java.io.OutputStream.write.

the byte.

Exceptions
IOException:

Doc from java.io.OutputStream.write.

if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.

See Also
OutputStream#write
writeback to summary
public void write(byte[] b, int off, int len) throws IOException

Overrides java.io.OutputStream.write.

Add len to the count, discard the data.

Parameters
b:byte[]

Doc from java.io.OutputStream.write.

the data.

off:int

Doc from java.io.OutputStream.write.

the start offset in the data.

len:int

Doc from java.io.OutputStream.write.

the number of bytes to write.

Exceptions
IOException:

Doc from java.io.OutputStream.write.

if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.

See Also
OutputStream#write