Class UnsynchronizedByteArrayOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.apache.xml.security.stax.impl.util.UnsynchronizedByteArrayOutputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public class UnsynchronizedByteArrayOutputStream extends java.io.OutputStream
-
-
Constructor Summary
Constructors Constructor Description UnsynchronizedByteArrayOutputStream()Constructs a new ByteArrayOutputStream with a default size of 32 bytes.UnsynchronizedByteArrayOutputStream(int size)Constructs a newByteArrayOutputStreamwith a default size ofsizebytes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidreset()Resets this stream to the beginning of the underlying byte array.intsize()Returns the total number of bytes written to this stream so far.byte[]toByteArray()Returns the contents of this ByteArrayOutputStream as a byte array.java.lang.StringtoString()Returns the contents of this ByteArrayOutputStream as a string.java.lang.StringtoString(java.lang.String enc)Returns the contents of this ByteArrayOutputStream as a string converted according to the encoding declared inenc.voidwrite(byte[] buffer, int offset, int len)Writescountbytes from the byte arraybufferstarting at offsetindexto this stream.voidwrite(int oneByte)Writes the specified byteoneByteto the OutputStream.voidwriteTo(java.io.OutputStream out)Takes the contents of this stream and writes it to the output streamout.
-
-
-
Constructor Detail
-
UnsynchronizedByteArrayOutputStream
public UnsynchronizedByteArrayOutputStream()
Constructs a new ByteArrayOutputStream with a default size of 32 bytes. If more than 32 bytes are written to this instance, the underlying byte array will expand.
-
UnsynchronizedByteArrayOutputStream
public UnsynchronizedByteArrayOutputStream(int size)
Constructs a newByteArrayOutputStreamwith a default size ofsizebytes. If more thansizebytes are written to this instance, the underlying byte array will expand.- Parameters:
size- initial size for the underlying byte array, must be non-negative.- Throws:
java.lang.IllegalArgumentException- ifsize< 0.
-
-
Method Detail
-
reset
public void reset()
Resets this stream to the beginning of the underlying byte array. All subsequent writes will overwrite any bytes previously stored in this stream.
-
size
public int size()
Returns the total number of bytes written to this stream so far.- Returns:
- the number of bytes written to this stream.
-
toByteArray
public byte[] toByteArray()
Returns the contents of this ByteArrayOutputStream as a byte array. Any changes made to the receiver after returning will not be reflected in the byte array returned to the caller.- Returns:
- this stream's current contents as a byte array.
-
toString
public java.lang.String toString()
Returns the contents of this ByteArrayOutputStream as a string. Any changes made to the receiver after returning will not be reflected in the string returned to the caller.- Overrides:
toStringin classjava.lang.Object- Returns:
- this stream's current contents as a string.
-
toString
public java.lang.String toString(java.lang.String enc) throws java.io.UnsupportedEncodingExceptionReturns the contents of this ByteArrayOutputStream as a string converted according to the encoding declared inenc.- Parameters:
enc- a string representing the encoding to use when translating this stream to a string.- Returns:
- this stream's current contents as an encoded string.
- Throws:
java.io.UnsupportedEncodingException- if the provided encoding is not supported.
-
write
public void write(byte[] buffer, int offset, int len)Writescountbytes from the byte arraybufferstarting at offsetindexto this stream.- Overrides:
writein classjava.io.OutputStream- Parameters:
buffer- the buffer to be written.offset- the initial position inbufferto retrieve bytes.len- the number of bytes ofbufferto write.- Throws:
java.lang.NullPointerException- ifbufferisnull.java.lang.IndexOutOfBoundsException- ifoffset < 0orlen < 0, or ifoffset + lenis greater than the length ofbuffer.
-
write
public void write(int oneByte)
Writes the specified byteoneByteto the OutputStream. Only the low order byte ofoneByteis written.- Specified by:
writein classjava.io.OutputStream- Parameters:
oneByte- the byte to be written.
-
writeTo
public void writeTo(java.io.OutputStream out) throws java.io.IOExceptionTakes the contents of this stream and writes it to the output streamout.- Parameters:
out- an OutputStream on which to write the contents of this stream.- Throws:
java.io.IOException- if an error occurs while writing toout.
-
-