Package net.targetr.wtm3.io
Class StreamUtil
java.lang.Object
net.targetr.wtm3.io.StreamUtil
Useful utilities for working with streams.
- Author:
- Dr Michael Gardiner
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe maximum number of bytes to read before automatically aborting. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidconsume(InputStream in) Reads until end of streamstatic byte[]readFully(InputStream in) Reads the stream into memory, rejecting data larger thanMAX_DATA_LENGTH.static byte[]readFully(InputStream in, int limit) Reads the stream into memory, throwing if the accumulated data exceeds the limit.
-
Field Details
-
MAX_DATA_LENGTH
public static final int MAX_DATA_LENGTHThe maximum number of bytes to read before automatically aborting.- See Also:
-
-
Constructor Details
-
StreamUtil
public StreamUtil()Constructs a new StreamUtil.
-
-
Method Details
-
readFully
Reads the stream into memory, rejecting data larger thanMAX_DATA_LENGTH. Does not close the input stream.- Parameters:
in- stream to read.- Returns:
- filled byte array.
- Throws:
IOException- if reading fails or the size limit is exceeded
-
readFully
Reads the stream into memory, throwing if the accumulated data exceeds the limit. The limit is checked after buffered reads; it does not truncate the result or close the stream.- Parameters:
in- stream to read.limit- maximum accepted result size in bytes- Returns:
- filled byte array.
- Throws:
IOException- if reading fails or the size limit is exceeded
-
consume
Reads until end of stream- Parameters:
in- stream to read.- Throws:
IOException- An exception occurred while reading.
-