Package org.apache.http.impl.io
Class ContentLengthOutputStream
java.lang.Object
java.io.OutputStream
org.apache.http.impl.io.ContentLengthOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
public class ContentLengthOutputStream extends OutputStream
A stream wrapper that closes itself after a defined number of bytes.
- Since:
- 4.0
- Version:
- $Revision: 560343 $
- Author:
- Oleg Kalnichevski
-
Constructor Summary
Constructors Constructor Description ContentLengthOutputStream(SessionOutputBuffer out, long contentLength)Creates a new length limited stream -
Method Summary
Modifier and Type Method Description voidclose()Does not close the underlying socket output.voidflush()Flushes this stream.voidwrite(byte[] b)Equivalent towrite(buffer, 0, buffer.length).voidwrite(byte[] b, int off, int len)Writescountbytes from the byte arraybufferstarting at positionoffsetto this stream.voidwrite(int b)Writes a single byte to this stream.
-
Constructor Details
-
ContentLengthOutputStream
Creates a new length limited stream- Parameters:
out- The data transmitter to wrapcontentLength- The maximum number of bytes that can be written to the stream. Subsequent write operations will be ignored.- Since:
- 4.0
-
-
Method Details
-
close
Does not close the underlying socket output.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException- If an I/O problem occurs.
-
flush
Description copied from class:OutputStreamFlushes this stream. Implementations of this method should ensure that any buffered data is written out. This implementation does nothing.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException- if an error occurs while flushing this stream.
-
write
Description copied from class:OutputStreamWritescountbytes from the byte arraybufferstarting at positionoffsetto this stream.- Overrides:
writein classOutputStream- Parameters:
b- the buffer to be written.off- the start position inbufferfrom where to get bytes.len- the number of bytes frombufferto write to this stream.- Throws:
IOException- if an error occurs while writing to this stream.
-
write
Description copied from class:OutputStreamEquivalent towrite(buffer, 0, buffer.length).- Overrides:
writein classOutputStream- Throws:
IOException
-
write
Description copied from class:OutputStreamWrites a single byte to this stream. Only the least significant byte of the integeroneByteis written to the stream.- Specified by:
writein classOutputStream- Parameters:
b- the byte to be written.- Throws:
IOException- if an error occurs while writing to this stream.
-