Interface Bytes
public interface Bytes
Read-only interface for values that are internally represented as binary
data.
This interface provides access to copies of the binary data, making instances effectively immutable. Methods of derived interfaces and classes that relax this restriction and expose access to the internal data should be clearly documented.
- Since:
- 5.7
- Author:
- DiffusionData Limited
-
Method Summary
Modifier and TypeMethodDescriptionReturns a stream that provides the data.void
copyTo
(OutputStream target) Write the bytes to an output stream.int
length()
byte[]
Returns a copy of the data as a byte array.
-
Method Details
-
length
int length()- Returns:
- the length of the data in bytes
-
asInputStream
InputStream asInputStream()Returns a stream that provides the data.- Returns:
- a new input stream over the bytes. Implementations may share the
underlying state with the
Bytes
. This minimises copying at the expense of retaining potentially inaccessible data for longer.
-
toByteArray
byte[] toByteArray()Returns a copy of the data as a byte array.- Returns:
- a copy of the binary data
-
copyTo
Write the bytes to an output stream.This method avoids the allocation and copying costs of producing an
intermediate byte array
.- Parameters:
target
- the target output stream- Throws:
IOException
- if writing to target causes an I/O error
-