public final class StreamUtils extends Object
InputStreams
, OutputStreams
, Readers
and Writers
.
Some of these are general purpose methods, others can be used for implementing InputStreams
, OutputStreams
, Readers
and
Writers
.Modifier and Type | Method and Description |
---|---|
static void |
checkOffsetAndLength(byte[] array,
int offset,
int length)
Checks whether or not an offset and length are valid for a byte array.
|
static void |
checkOffsetAndLength(char[] array,
int offset,
int length)
Checks whether or not an offset and length are valid for a character array.
|
static void |
checkOffsetAndLength(CharSequence sequence,
int offset,
int length)
Checks whether or not an offset and length are valid for a character sequence.
|
static void |
checkStartAndEnd(CharSequence sequence,
int start,
int end)
Checks whether or not a start and end index are valid for a character sequence.
|
static IOException |
streamClosedException()
Returns an
IOException that indicates a stream is closed. |
public static void checkOffsetAndLength(byte[] array, int offset, int length)
InputStream.read(byte[], int, int)
or OutputStream.write(byte[], int, int)
.array
- The array to check for.offset
- The offset to check, inclusive.length
- The length to check.NullPointerException
- If the given array is null
.IndexOutOfBoundsException
- If the given offset is negative, the given length is negative,
or the given offset and length exceed the given array's length.public static void checkOffsetAndLength(char[] array, int offset, int length)
Reader.read(char[], int, int)
or Writer.write(char[], int, int)
.array
- The array to check for.offset
- The offset to check, inclusive.length
- The length to check.NullPointerException
- If the given array is null
.IndexOutOfBoundsException
- If the given offset is negative, the given length is negative,
or the given offset and length exceed the given array's length.public static void checkOffsetAndLength(CharSequence sequence, int offset, int length)
Writer.write(String, int, int)
.sequence
- The character sequence to check for.offset
- The offset to check, inclusive.length
- The length to check.NullPointerException
- If the given character sequence is null
.IndexOutOfBoundsException
- If the given offset is negative, the given length is negative,
or the given offset and length exceed the given character sequence's length.public static void checkStartAndEnd(CharSequence sequence, int start, int end)
Writer.append(CharSequence, int, int)
.sequence
- The character sequence to check for.start
- The start index to check, inclusive.end
- The end index to check, exclusive.NullPointerException
- If the given character sequence is null
.IndexOutOfBoundsException
- If the given start index is negative,
the given end index is larger than the given character sequence's length,
or the given start index is larger than the given end index.public static IOException streamClosedException()
IOException
that indicates a stream is closed.IOException
that indicates a stream is closed.Copyright © 2020–2024. All rights reserved.