Top Description Fields Constructors Methods
net.bytebuddy.utility

public Class StreamDrainer

extends Object
Class Inheritance
Annotations
@Enhance
Imports
net.bytebuddy.build.HashCodeAndEqualsPlugin, java.io.IOException, .InputStream, java.util.ArrayList, .List

A utility for draining the contents of an java.io.InputStream into a byte array.

Field Summary

Modifier and TypeField and Description
private final int
bufferSize

The buffer size for reading from a given stream.

public static final StreamDrainer
DEFAULT

A default instance using the StreamDrainer#DEFAULT_BUFFER_SIZE.

public static final int
DEFAULT_BUFFER_SIZE

The default size of the buffer for draining a stream.

private static final int
END_OF_STREAM

A convenience constant referring to the value representing the end of a stream.

private static final int
FROM_BEGINNING

A convenience constant referring to the value representing the start of a stream.

Constructor Summary

AccessConstructor and Description
public
StreamDrainer()

Creates a stream drainer with the default buffer size.

public
StreamDrainer(int
The buffer size for reading from a given stream.
bufferSize
)

Creates a stream drainer with the given buffer size.

Method Summary

Modifier and TypeMethod and Description
public byte[]

Returns:

A byte array containing the content of the input stream.
drain
(InputStream
The input stream to drain.
inputStream
)

Drains an input stream into a byte array.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferSizeback to summary
private final int bufferSize

The buffer size for reading from a given stream.

DEFAULTback to summary
public static final StreamDrainer DEFAULT

A default instance using the StreamDrainer#DEFAULT_BUFFER_SIZE.

DEFAULT_BUFFER_SIZEback to summary
public static final int DEFAULT_BUFFER_SIZE

The default size of the buffer for draining a stream.

END_OF_STREAMback to summary
private static final int END_OF_STREAM

A convenience constant referring to the value representing the end of a stream.

FROM_BEGINNINGback to summary
private static final int FROM_BEGINNING

A convenience constant referring to the value representing the start of a stream.

Constructor Detail

StreamDrainerback to summary
public StreamDrainer()

Creates a stream drainer with the default buffer size.

StreamDrainerback to summary
public StreamDrainer(int bufferSize)

Creates a stream drainer with the given buffer size.

Parameters
bufferSize:int

The buffer size for reading from a given stream.

Method Detail

drainback to summary
public byte[] drain(InputStream inputStream) throws IOException

Drains an input stream into a byte array. The given input stream is not closed.

Parameters
inputStream:InputStream

The input stream to drain.

Returns:byte[]

A byte array containing the content of the input stream.

Exceptions
IOException:
If the stream reading causes an error.