public final class ObfuscatorUtils extends Object
Obfuscators
.Modifier and Type | Method and Description |
---|---|
static void |
append(char[] array,
Appendable destination)
Appends an array of characters to an
Appendable . |
static void |
append(char[] array,
int start,
int end,
Appendable destination)
Appends a portion of an array of characters to an
Appendable . |
static void |
append(char c,
int count,
Appendable destination)
Appends a single character a number of times to an
Appendable . |
static void |
append(int c,
Appendable destination)
Appends a single character to an
Appendable . |
static void |
append(String str,
Appendable destination)
Appends a string to an
Appendable . |
static void |
append(String str,
int start,
int end,
Appendable destination)
Appends a portion of a string to an
Appendable . |
static LimitAppendable |
appendAtMost(Appendable appendable,
long limit)
Returns an
Appendable that will discard text after a specific amount of text has been appended. |
static void |
checkIndex(char[] array,
int index)
Checks whether or not an index is valid for a character array.
|
static void |
checkIndex(CharSequence s,
int index)
Checks whether or not an index is valid for a
CharSequence . |
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
CharSequence . |
static void |
checkStartAndEnd(char[] array,
int start,
int end)
Checks whether or not a start and end index are valid for a character array.
|
static void |
checkStartAndEnd(CharSequence sequence,
int start,
int end)
Checks whether or not a start and end index are valid for a
CharSequence . |
static CharSequence |
concat(CharSequence first,
CharSequence second)
Concatenates two
CharSequence s into one. |
static void |
copyAll(Reader input,
Appendable destination)
Copies the contents of a
Reader to an Appendable . |
static Reader |
copyTo(Reader input,
Appendable appendable)
Returns a
Reader that transparently appends all text read from another Reader to an Appendable . |
static CountingReader |
counting(Reader input)
Returns a
Reader that counts all text read from another Reader . |
static long |
discardAll(Reader input)
Discards the contents of a
Reader . |
static void |
getChars(CharSequence src,
int srcBegin,
int srcEnd,
char[] dst,
int dstBegin)
Copies characters from a
CharSequence into a destination character array. |
static int |
indexOf(CharSequence s,
int ch,
int fromIndex,
int toIndex)
Returns the index within a
CharSequence range of the first occurrence of a specific character. |
static int |
lastIndexOf(CharSequence s,
int ch,
int fromIndex,
int toIndex)
Returns the index within a
CharSequence of the last occurrence of a specific character. |
static void |
maskAll(Reader input,
char maskChar,
Appendable destination)
Copies the contents of a
Reader to an Appendable , masking each character. |
static CharSequence |
readAll(Reader input)
Reads the contents of a
Reader . |
static Reader |
readAtMost(Reader input,
int limit)
Returns a
Reader that is able to read only a portion of text from another Reader . |
static Reader |
reader(CharSequence s)
Returns a
Reader for a CharSequence . |
static Reader |
reader(CharSequence s,
int start,
int end)
Returns a
Reader for a portion of a CharSequence . |
static CharSequence |
repeatChar(char c,
int count)
Creates an immutable
CharSequence that repeats a single character. |
static int |
skipLeadingWhitespace(CharSequence s,
int fromIndex,
int toIndex)
Skips leading
whitespace in a range of a CharSequence . |
static int |
skipTrailingWhitespace(CharSequence s,
int fromIndex,
int toIndex)
Skips trailing
whitespace in a range of a CharSequence . |
static CharSequence |
wrapArray(char[] array)
Creates a
CharSequence that wraps a character array. |
static Writer |
writer(Appendable appendable)
Returns an
Appendable as a Writer . |
public static int indexOf(CharSequence s, int ch, int fromIndex, int toIndex)
CharSequence
range of the first occurrence of a specific character.
This method is like String.indexOf(int, int)
, but it works on any CharSequence
, and it has an upper bound as well.s
- The CharSequence
to search.ch
- The character to search for.fromIndex
- The start of the CharSequence
range, inclusive.toIndex
- The end of the CharSequence
range, exclusive.CharSequence
, or -1
if the character does not occur in the given
CharSequence
in the specified range.NullPointerException
- If the given CharSequence
is null
.public static int lastIndexOf(CharSequence s, int ch, int fromIndex, int toIndex)
CharSequence
of the last occurrence of a specific character.
This method is like String.lastIndexOf(int, int)
using toIndex - 1
as second argument, but it works on any
CharSequence
, and it has a lower bound as well.s
- The CharSequence
to search.ch
- The character to search for.fromIndex
- The start of the CharSequence
range, inclusive.toIndex
- The end of the CharSequence
range, exclusive.CharSequence
, or -1
if the character does not occur in the given
CharSequence
in the specified range.NullPointerException
- If the given CharSequence
is null
.public static int skipLeadingWhitespace(CharSequence s, int fromIndex, int toIndex)
whitespace
in a range of a CharSequence
.s
- The CharSequence
to skip leading whitespace in.fromIndex
- The start of the range to start skipping whitespace in, inclusive.toIndex
- The end of the range to start skipping whitespace in, exclusive.CharSequence
of the first non-whitespace character, or toIndex
if the CharSequence
contains only whitespace.NullPointerException
- If the given CharSequence
is null
.IndexOutOfBoundsException
- If the given indexes are invalid for the given CharSequence
.public static int skipTrailingWhitespace(CharSequence s, int fromIndex, int toIndex)
whitespace
in a range of a CharSequence
.s
- The CharSequence
to skip trailing whitespace in.fromIndex
- The start of the range to start skipping whitespace in, inclusive.toIndex
- The end of the range to start skipping whitespace in, exclusive.CharSequence
of the first non-whitespace character, or fromIndex
if the CharSequence
contains only whitespace.IndexOutOfBoundsException
- If the given indexes are invalid for the given CharSequence
.public static void getChars(CharSequence src, int srcBegin, int srcEnd, char[] dst, int dstBegin)
CharSequence
into a destination character array.
This method is a more generic version of String.getChars(int, int, char[], int)
, StringBuilder.getChars(int, int, char[], int)
and StringBuffer.getChars(int, int, char[], int)
.src
- The CharSequence
to copy characters from.srcBegin
- The index of the first character in the CharSequence
to copy.srcEnd
- The index after the last character in the CharSequence
to copy.dst
- The destination array.dstBegin
- The start offset in the destination array.NullPointerException
- If the given CharSequence
or character array is null
.IndexOutOfBoundsException
- If any of the indexes is invalid.public static void checkIndex(char[] array, int index)
array
- The array to check for.index
- The index to check.NullPointerException
- If the given array is null
.IndexOutOfBoundsException
- If the given index is negative or exceeds the given array's length.public static void checkOffsetAndLength(char[] array, int offset, int length)
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 checkStartAndEnd(char[] array, int start, int end)
array
- The array to check for.start
- The start index to check, inclusive.end
- The end index to check, exclusive.NullPointerException
- If the given array is null
.IndexOutOfBoundsException
- If the given start index is negative,
the given end index is larger than the given array's length,
or the given start index is larger than the given end index.public static void checkIndex(CharSequence s, int index)
CharSequence
.s
- The CharSequence
to check for.index
- The index to check.NullPointerException
- If the given CharSequence
is null
.IndexOutOfBoundsException
- If the given index is negative or exceeds the given CharSequence
's length.public static void checkOffsetAndLength(CharSequence sequence, int offset, int length)
CharSequence
.sequence
- The CharSequence
to check for.offset
- The offset to check, inclusive.length
- The length to check.NullPointerException
- If the given CharSequence
is null
.IndexOutOfBoundsException
- If the given offset is negative, the given length is negative,
or the given offset and length exceed the given CharSequence
's length.public static void checkStartAndEnd(CharSequence sequence, int start, int end)
CharSequence
.sequence
- The CharSequence
to check for.start
- The start index to check, inclusive.end
- The end index to check, exclusive.NullPointerException
- If the given CharSequence
is null
.IndexOutOfBoundsException
- If the given start index is negative,
the given end index is larger than the given CharSequence
's length,
or the given start index is larger than the given end index.public static CharSequence wrapArray(char[] array)
CharSequence
that wraps a character array.array
- The array to wrap.CharSequence
wrapper around the given array.NullPointerException
- If the given array is null
.public static CharSequence repeatChar(char c, int count)
CharSequence
that repeats a single character.c
- The character to repeat.count
- The number of times to repeat the character.CharSequence
that repeats the given character the given number of times.IllegalArgumentException
- If the given number of times is negative.public static CharSequence concat(CharSequence first, CharSequence second)
CharSequence
s into one.first
- The first CharSequence
.second
- The second CharSequence
.CharSequence
.NullPointerException
- If either CharSequence
is null
.public static Reader reader(CharSequence s)
Reader
for a CharSequence
.s
- The CharSequence
to return a Reader
for.Reader
for the given CharSequence
.public static Reader reader(CharSequence s, int start, int end)
Reader
for a portion of a CharSequence
.s
- The CharSequence
to return a Reader
for.start
- The start index of the portion, inclusive.end
- The end index of the portion, inclusive.Reader
for the given portion of the given CharSequence
.IndexOutOfBoundsException
- If the given start index is negative,
the given end index is larger than the given CharSequence
's length,
or the given start index is larger than the given end index.public static Writer writer(Appendable appendable)
Appendable
as a Writer
. If the given Appendable
is a Writer
, it is returned unmodified.
Otherwise, a wrapper is returned that will delegate all calls to the wrapped Appendable
. This includes flush()
if the wrapped Appendable
implements Flushable
, and close()
if the wrapped Appendable
implements
Closeable
or AutoCloseable
.
Note that the behaviour of closing a Writer
wrapper depends on the wrapped Appendable
. If it does not support closing,
or if it still allows text to be appended after closing, then the closed AppendableWriter
allows text to be appended after closing.
If it does not allow text to be appended after closing, then neither will the closed Writer
wrapper.
appendable
- The Appendable
to return a Writer
for.Appendable
itself if it's already a Writer
, otherwise a wrapper around the given Appendable
.NullPointerException
- If the given Appendable
is null
.public static CountingReader counting(Reader input)
Reader
that counts all text read from another Reader
.input
- The Reader
to read from.Reader
that counts all text read from the given Reader
.NullPointerException
- If the given Reader
is null
.public static Reader copyTo(Reader input, Appendable appendable)
Reader
that transparently appends all text read from another Reader
to an Appendable
.
If the returned Reader
is closed, the given Reader
will be closed as well. The Appendable
will not be closed though.input
- The Reader
to read from.appendable
- The Appendable
to write to.Reader
that transparently appends all text read from the given Reader
to the given Appendable
.NullPointerException
- If the given Reader
or Appendable
is null
.public static Reader readAtMost(Reader input, int limit)
Reader
that is able to read only a portion of text from another Reader
.input
- The Reader
to read from.limit
- The maximum number of characters to read from the given Reader
.Reader
that is able to read at most limit
characters from the given Reader
.NullPointerException
- If the given Reader
is null
.IllegalArgumentException
- If the given limit is negative.public static LimitAppendable appendAtMost(Appendable appendable, long limit)
Appendable
that will discard text after a specific amount of text has been appended.appendable
- The Appendable
to append to.limit
- The maximum number of characters to append to the given Appendable
.Appendable
that will discard text after a specific amount of text has been appended.NullPointerException
- If the given Appendable
is null
.IllegalArgumentException
- If the given limit is negative.public static CharSequence readAll(Reader input) throws IOException
Reader
.input
- The Reader
to read the contents of.CharSequence
with the contents of the given Reader
.NullPointerException
- If the given Reader
is null
.IOException
- If an I/O error occurs.public static long discardAll(Reader input) throws IOException
Reader
.input
- The Reader
to discard the contents of.NullPointerException
- If the given Reader
is null
.IOException
- If an I/O error occurs.public static void copyAll(Reader input, Appendable destination) throws IOException
Reader
to an Appendable
.input
- The Reader
to copy the contents of.destination
- The Appendable
to copy the contents to.NullPointerException
- If the given Reader
or Appendable
is null
.IOException
- If an I/O error occurs.public static void maskAll(Reader input, char maskChar, Appendable destination) throws IOException
Reader
to an Appendable
, masking each character.input
- The Reader
to copy the contents of.maskChar
- The character to replace with.destination
- The Appendable
to copy the contents to.NullPointerException
- If the given Reader
or Appendable
is null
.IOException
- If an I/O error occurs.public static void append(int c, Appendable destination) throws IOException
Appendable
.
The character to be written is contained in the 16 low-order bits of the given integer value; the 16 high-order bits are ignored.c
- The character to append.destination
- The Appendable
to append to.NullPointerException
- If the given Appendable
is null
.IOException
- If an I/O error occurs.public static void append(char c, int count, Appendable destination) throws IOException
Appendable
.c
- The character to append.count
- The number of times to append the character.destination
- The Appendable
to append to.IllegalArgumentException
- If the given number of times is negative.NullPointerException
- If the given Appendable
is null
.IOException
- If an I/O error occurs.public static void append(char[] array, Appendable destination) throws IOException
Appendable
.array
- The array to append.destination
- The Appendable
to append to.NullPointerException
- If the given array or Appendable
is null
.IOException
- If an I/O error occurs.public static void append(char[] array, int start, int end, Appendable destination) throws IOException
Appendable
.array
- The array to append a portion of.destination
- The Appendable
to append to.start
- The start index of the portion to append, inclusive.end
- The end index of the portion to append, exclusive.NullPointerException
- If the given array or Appendable
is null
.IndexOutOfBoundsException
- If the given start index is negative,
the given end index is larger than the given array's length,
or the given start index is larger than the given end index.IOException
- If an I/O error occurs.public static void append(String str, Appendable destination) throws IOException
Appendable
.str
- The string to append.destination
- The Appendable
to append to.NullPointerException
- If the given string or Appendable
is null
.IOException
- If an I/O error occurs.public static void append(String str, int start, int end, Appendable destination) throws IOException
Appendable
.str
- The string to append a portion of.destination
- The Appendable
to append to.start
- The start index of the portion to append, inclusive.end
- The end index of the portion to append, exclusive.NullPointerException
- If the given string or Appendable
is null
.IndexOutOfBoundsException
- If the given start index is negative,
the given end index is larger than the given string's length,
or the given start index is larger than the given end index.IOException
- If an I/O error occurs.Copyright © 2020–2023. All rights reserved.