Class StreamDrainer

java.lang.Object
net.bytebuddy.utility.StreamDrainer

@Enhance public class StreamDrainer extends Object
A utility for draining the contents of an InputStream into a byte array.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final int
    The buffer size for reading from a given stream.
    static final StreamDrainer
    A default instance using the DEFAULT_BUFFER_SIZE.
    static final int
    The default size of the buffer for draining a stream.
    private static final int
    A convenience constant referring to the value representing the end of a stream.
    private static final int
    A convenience constant referring to the value representing the start of a stream.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a stream drainer with the default buffer size.
    StreamDrainer(int bufferSize)
    Creates a stream drainer with the given buffer size.
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    drain(InputStream inputStream)
    Drains an input stream into a byte array.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_BUFFER_SIZE

      public static final int DEFAULT_BUFFER_SIZE
      The default size of the buffer for draining a stream.
      See Also:
    • DEFAULT

      public static final StreamDrainer DEFAULT
      A default instance using the DEFAULT_BUFFER_SIZE.
    • END_OF_STREAM

      private static final int END_OF_STREAM
      A convenience constant referring to the value representing the end of a stream.
      See Also:
    • FROM_BEGINNING

      private static final int FROM_BEGINNING
      A convenience constant referring to the value representing the start of a stream.
      See Also:
    • bufferSize

      private final int bufferSize
      The buffer size for reading from a given stream.
  • Constructor Details

    • StreamDrainer

      public StreamDrainer()
      Creates a stream drainer with the default buffer size.
    • StreamDrainer

      public StreamDrainer(int bufferSize)
      Creates a stream drainer with the given buffer size.
      Parameters:
      bufferSize - The buffer size for reading from a given stream.
  • Method Details

    • drain

      public byte[] drain(InputStream inputStream) throws IOException
      Drains an input stream into a byte array. The given input stream is not closed.
      Parameters:
      inputStream - The input stream to drain.
      Returns:
      A byte array containing the content of the input stream.
      Throws:
      IOException - If the stream reading causes an error.