Package com.sun.xml.ws.util
Class ByteArrayBuffer
java.lang.Object
java.io.OutputStream
com.sun.xml.ws.util.ByteArrayBuffer
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
Read/write buffer that stores a sequence of bytes.
It works in a way similar to ByteArrayOutputStream
but
this class works better in the following ways:
- no synchronization
- offers a
newInputStream()
that creates a newInputStream
that won't cause buffer reallocation. - less parameter correctness checking
- offers a
write(InputStream)
method that reads the entirety of the givenInputStream
without using a temporary buffer.
- Author:
- Kohsuke Kawaguchi
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new byte array output stream.ByteArrayBuffer
(byte[] data) ByteArrayBuffer
(byte[] data, int length) ByteArrayBuffer
(int size) Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
final byte[]
Gets the underlying buffer that thisByteArrayBuffer
uses.final InputStream
Creates a newInputStream
that reads from this buffer.final InputStream
newInputStream
(int start, int length) Creates a newInputStream
that reads a part of this bfufer.final void
reset()
final int
size()
final byte[]
Deprecated.this method causes a buffer reallocation.toString()
Decodes the contents of this buffer by the default encoding and returns it as a string.final void
write
(byte[] b, int off, int len) final void
write
(int b) final void
write
(InputStream in) Reads all the data of the givenInputStream
and appends them into this buffer.final void
writeTo
(OutputStream out) Methods inherited from class java.io.OutputStream
flush, nullOutputStream, write
-
Field Details
-
buf
protected byte[] bufThe buffer where data is stored.
-
-
Constructor Details
-
ByteArrayBuffer
public ByteArrayBuffer()Creates a new byte array output stream. The buffer capacity is initially 32 bytes, though its size increases if necessary. -
ByteArrayBuffer
public ByteArrayBuffer(int size) Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes.- Parameters:
size
- the initial size.- Throws:
IllegalArgumentException
- if size is negative.
-
ByteArrayBuffer
public ByteArrayBuffer(byte[] data) -
ByteArrayBuffer
public ByteArrayBuffer(byte[] data, int length)
-
-
Method Details
-
write
Reads all the data of the givenInputStream
and appends them into this buffer.- Throws:
IOException
- if the read operation fails with anIOException
.
-
write
public final void write(int b) - Specified by:
write
in classOutputStream
-
write
public final void write(byte[] b, int off, int len) - Overrides:
write
in classOutputStream
-
writeTo
- Throws:
IOException
-
reset
public final void reset() -
toByteArray
public final byte[] toByteArray()Deprecated.this method causes a buffer reallocation. Use it only when you have to.Gets the copy of exact-size byte[] that represents the written data.Since this method needs to allocate a new byte[], this method will be costly.
-
size
public final int size() -
getRawData
public final byte[] getRawData()Gets the underlying buffer that thisByteArrayBuffer
uses. It's never small than itssize()
. Use with caution. -
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-
newInputStream
Creates a newInputStream
that reads from this buffer. -
newInputStream
Creates a newInputStream
that reads a part of this bfufer. -
toString
Decodes the contents of this buffer by the default encoding and returns it as a string.Meant to aid debugging, but no more.
-