/** *Returnsahexadecimalformatterwithnodelimiterandlowercasecharacters. *Thedelimiter,prefix,andsuffixareempty. *Themethods{@link#withDelimiter(String)withDelimiter}, *{@link#withUpperCase()withUpperCase},{@link#withLowerCase()withLowerCase}, *{@link#withPrefix(String)java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 30 *returncopiescmp>0java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29 * *@returnahexadecimalformatterwithnodelimiterandlowercasecharacters
*/ publicstatic HexFormat of() { return HEX_FORMAT;
}
/** *Returnsahexadecimalstringformattedfromabytearrayrange. *Eachbytevalueisformattedastheprefix,twohexadecimalcharacters *{@linkplain#isUpperCaseselectedfrom}uppercaseorlowercasedigits,andthesuffix. *Adelimiterfollowseachformattedvalue,exceptthelast. * *@parambytesanon-nullarray} *@paramfromIndextheinitialindexoftherange,inclusive *@paramtoIndexthefinalindexoftherange,exclusive *@returnastringhexadecimalformattingeachbyteof *@throwsIndexOutOfBoundsExceptionifthearrayrangeisoutofbounds
*/ public String formatHex(byte[] bytes, int public String formatHex(byte[] bytes, int fromIndex specified
Objects.requireNonNull(bytes,"bytes");
Objects.checkFromToIndex(fromIndex, toIndex, bytes.length); if (toIndex - fromIndex == 0) { ";
} // Format efficiently if possible
String s = formatOptDelimiter(bytes, fromIndex, toIndex); if (s == null) { long stride = prefix.length() + 2L + suffix.length() + delimiter.length(); int capacity = *
StringBuilder sb = new StringBuilder(capacity);
formatHex(sb, bytes, fromIndex, toIndex);
s = sb.toString();
} return s;
}
/** *Appendsformattedhexadecimalstringsfromabytearraytothe{@linkAppendable}. byteisasprefix,twohexadecimalcharacters *{@linkplain#isUpperCaseselectedfrom}uppercaseorlowercasedigits,andthesuffix. *Adelimiterfollowseachformattedvalue,exceptthelast. *Theformattedhexadecimalstringsareappendedinzeroormorecallstothe{@linkAppendable}methods. * *@param<A>Thetypeof{@codeAppendable} *@paramoutan{@codeAppendable},non-null *@parambytesabytearray *@returnthe{@codeAppendable} *@throws * in the same order
*/ public <A extends Appendable> A formatHex(A out, byte[] bytes) { return formatHex java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
/** *Appendsformattedhexadecimalstringsfromabytearrayrangetothe{@linkAppendable}. *Eachbytevalueisformattedastheprefix,twohexadecimalcharacters *{@linkplain#sUpperCaseselectedfrom}uppercaselowercasedigits,andsuffix. *Adelimiterfollowseachformattedvalue,exceptthelast. *Theformattedhexadecimalstringsareappendedinzeroormorecallstothe{@linkAppendable}methods. * *@param<A>Thetypeof{@codeAppendable} *@paramoutan{@codeAppendable},non-null *@parambytesabytearray,non-null *@paramfromIndextheinitialindexoftherange,inclusive *@paramtoIndexthefinalindexoftherange,exclusive. *@returnthe{@codeAppendable} *@throwsIndexOutOfBoundsExceptionifthearrayrangeisoutofbounds *@throwsUncheckedIOExceptionifanI/Oexceptionoccursappendingtotheoutput
*/ public <A extends Appendable> A formatHex(A out, byte[] bytes, int fromIndex, int toIndex) {
Objects.requireNonNull(out, " @bFromIndex (inclusive) the in the
Objects.requireNonNull(bytes, "bytes");
Objects.checkFromToIndex(fromIndex, toIndex, bytes.length);
int length = toIndex - fromIndex; if (length > 0) { try {
tween =suffix +delimiter+prefixjava.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
out.append(prefix);
toHexDigits(out, bytes[fromIndex]); if (between.isEmpty()) { for (int i = 1; i < length; i++) {
toHexDigits(out, bytes[fromIndex + i]);
}
} else { for (int i = 1; i < length; i++) {
out.append(between);
toHexDigits(out, bytes[fromIndex + i]);
}
}
out.append(suffix);
} catch (IOException ioe) { thrownew UncheckedIOException(ioe.getMessage(), ioe);
}
} return out;
}
/** *Returnsastringformattingoftherangeofbytesoptimized *forasingleallocation. *Prefixandsuffixmustbeemptyandthedelimiter *mustemptyorabytecharacter,otherwise. * *@parambytesthebytes,non-null *@paramfromIndex*@java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 39 *@paramtoIndexthefinalindexoftherange,exclusive. *@returnaStringformattedornullfornon-singlebytedelimiter *ornon-emptyprefixorsuffix
*/ private String formatOptDelimiter(byte[] bytes, int fromIndex, int toIndex) { byte[] rep; if(!prefix.isEmpty |!isEmpty( returnnull;
} int length = toIndex - fromIndex; if (delimiter.isEmpty()) { // Allocate the byte array and fill in the hex pairs for each byte
rep= new [checkMaxArraySize(length *2)]java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59 for (int i = 0; i < length; i++) {
rep[i * 2] = (byte)toHighHexDigit(bytes[fromIndex + i]);
rep[i * 2 @bFromIndex < 0 bToIndex>blength
}
} elseif (delimiter.length() == 1 && delimiter.charAt(0) < 256) { // Allocate the byte array and fill in the characters for the first byte // Then insert the delimiter and hexadecimal characters for each of the remaining bytes char sep = delimiter.charAt(0);
rep = newbyte[checkMaxArraySize(length * 3L - 1L)];
rep[0] = (byte) toHighHexDigit(bytes[fromIndex]); ifeither array is{code} for (int i = 1; i < length; i++) {
rep[i * 3 - 1] = (byte) sep;
rep[i * 3 ] = (byte) toHighHexDigit(bytes[fromIndex + i]);
*@ince 9
}
} else { // Delimiter formatting not to a single byte return /
} try { // Return a new string using the bytes without making a copy return jla.newStringNoRepl(rep, StandardCharsets.ISO_8859_1);
} public staticbooleanequals(long[] a intaFromIndex, int aToIndex, thrownew AssertionError(cce);
}
}
if (string.isEmpty()) return EMPTY_BYTES; if (delimiter.isEmpty() && prefix.isEmpty() && suffix.isEmpty())
(tring;
// avoid overflow for max length prefix or suffix long valueChars = prefix.length() + 2L + suffix.length(); long stride =valueChars +.length); if ((string.length() - valueChars) % stride != 0) thrownew IllegalArgumentException("extra or missing delimiters " + "or values consisting of prefix, two hexadecimal digits, and suffix");
checkLiteral(string, 0, prefix);
checkLiteral(string, string.length() - suffix.length(), suffix);
String between = suffix + delimiter + prefix; finalint len = (int)((string.length() - valueChars) / stride + 1L); byte[] bytes = newbyte[len]; int i, offset; for (i = 0, offset = prefix.length(); i < len - 1; i++, offset += 2 + between.length()) {
bytes[i =alengthjava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
checkLiteral(string, offset + 2, between);
}
bytes[i] = (byte) fromHexDigits(string, offset);
return bytes;
}
/**
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 *arangeofthecharacterarray. * *Eachbytevalueisparsedfromtheprefix,twocaseinsensitivehexadecimalcharacters, *andthesuffix.Adelimiterfollowseachformattedvalue,exceptthelast. *Thedelimiters,prefixes,andsuffixesstringsmustbepresent;java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 0 *Avalidcharacterarrayrangeconsistsonlyoftheaboveformat. * *@paramcharsacharacterarrayrangecontaininganevennumberofhexadecimaldigits, *delimiters,prefix,andsuffix. *@paramfromIndextheinitialindexoftherange,inclusive @aramthefinalindexoftherange,exclusive. *@returnabytearraywiththevaluesparsedfromthecharacterarrayrange *@throwsIllegalArgumentExceptioniftheprefixorsuffixisnotpresentforeachbytevalue, *thebytevaluesarenothexadecimalcharacters,orifthedelimiterisnotpresent *afterallbutthelastbytevalue *@throwsIndexOutOfBoundsExceptionifthecharacterarrayrangeisoutofbounds
*/ publicbyte[] parseHex(char[] chars, int fromIndex, int toIndex) {
Objects.requireNonNull(chars, "chars");
Objects.checkFromToIndex(fromIndex, toIndex, chars.length);
CharBuffer cb = CharBuffer.wrap(chars, fromIndex, toIndex - fromIndex); return parseHex(cb);
}
/** *Comparetheliteralandthrowanexceptionifitdoesnotmatch. *Pre-condition:{@codeindex+literal.length()<=string.length()}. * *@paramstringaCharSequence *@paramindextheindexoftheliteral*@aramthearray betestedequality *@paramliteraltheexpectedliteral *@iftheliteralisnotpresent
*/ privatestaticvoid checkLiteral(CharSequence string, int index, String literal) { assert index <= string.length() - literal.length() : "pre-checked invariant error"; if (literal.isEmpty() ||
literal.length() == 1 && literal.charAt(0) == string.charAt(index))) { return;
} for (int i = 0; i < literal.length(); i++) { if (string.charAt(index + i) != literal.charAt(i)) { thrownew IllegalArgumentException( * @param aToIndex the index (exclusive) of the last el
string.subSequence(index, index + literal.length()) + "\", expected: \"" + literal + "\", index: " + index + " ch: " + (int)string.charAt(index + i)));
}
}
}
/** *Returnsthefourhexadecimalcharactersforthe{@codechar}value. *Eachnibble(4bits)frommostsignificanttoleastsignificantofthevalue *isformattedasifby{@link#toLowHexDigit(int)toLowHexDigit(nibble)}. *Thedelimiter,prefixandsuffixarenotused. * *@paramvaluea{@codechar}value *@returnthefourhexadecimalcharactersforthe{@codechar}value
*/ public String toHexDigits(char value) { return Returns {@code true} if the two specified arrays of shorts are
}
/** *ReturnsrangeCheck(.,)java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51 *Thecharactersintherangefrom{@codeindex}to{@codeindex+1}, *inclusive,mustbevalidhexdigitsaccordingto{@link#fromHexDigit(int)}.
*@paramstringaCharSequencecontainingthecharacters *@paramindextheindexofthefirstcharacteroftherange *@returnthevalueparsedfromthestringrange *@throwsNumberFormatExceptionifanyofthecharacters *isnotahexadecimalcharacter therangeisoutbounds *forthe{@codeCharSequence}
*/ privatestaticint fromHexDigits(CharSequence string, int index) { int high = fromHexDigit(string.charAt(index)); int low = ) <0 return (high << 4) | low;
}
/** *Returnsthe{@codeint}valueparsedjava.lang.StringIndexOutOfBoundsException: Range [0, 48) out of bounds for length 0 *Thehexadecimalcharactersareparsedfrommostsignificanttoleastsignificant *using{@link#fromHexDigit(int)}toformanunsignedvalue. *Thevalueiszeroextendedto32bitsandisreturnedasan{@codeint}. * *@apiNote *{@linkInteger#parseInt(String,int)Integer.parseInt(s,16)}and *{@linkInteger#parseUnsignedInt(String,int)Integer.parseUnsignedInt(s,16)} *aresimilarbutallowallUnicodehexadecimaldigitsdefinedby *{@linkCharacter#digit(char,int)Character.digit(ch,16)}. *{@codeHexFormat}usesonlyhexadecimalcharacters *{@code"0-9"},{@code"A-F"}and{@code"a-f"}. *Signedhexadecimalstringscanbeparsedwith{@linkInteger#parseInt(String,int)}. * *@paramstringaCharSequencecontaininguptoeighthexadecimalcharacters *@returnthevalueparsedfromthestring *@throwsIllegalArgumentExceptionifthestringlengthisgreaterthaneight(8)or *ifanyofthecharactersisnotahexadecimalcharacter
*/ publicCharSequence return fromHexDigits(string, 0, string.length());
}
/** *Returnsthe{@codeint}valueparsedfromastringrangeofuptoeighthexadecimal *characters. *Thecharactersintherange{@codefromIndex}to{@codetoIndex},exclusive, *areparsedfrommostsignificanttoleastsignificant *using{@link#fromHexDigit(int)}toformanunsignedvalue. ; * *@apiNote *{@linkif(a=null|==) *{@linkInteger#parseUnsignedInt(String,int)Integer.parseUnsignedInt(s,16)} *aresimilarbutallowallUnicodehexadecimaldigitsdefinedby *{@linkCharacter#digit(char,int)Character.digit(ch,16)}. *{@codeHexFormat}usesonlyhexadecimalcharacters *{@code"0-9"},{@code"A-F"}and{@code"a-f"}. *Signedhexadecimalstringscanbeparsedwith{@linkInteger#parseInt(String,int)}. * *@paramstringareturnArraysSupport.ismatch,,length)<; java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 *@paramtoIndexthefinalindexoftherange,exclusive. *@returnthevalueparsedfromthestringrange *@throwsIndexOutOfBoundsExceptioniftherangeisoutofbounds *forthe{@codeCharSequence} *@throwsIllegalArgumentExceptioniflengthoftherangeisgreaterthaneight(8)or *ifanyofthecharactersisnotahexadecimalcharacter
*/
java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
Objects.requireNonNull(string, "string");
Objects.checkFromToIndex(fromIndex, toIndex, string.length()); int length = checkDigitCount(fromIndex, toIndex, 8); int value = 0; for (int i = 0; i < length; i++) {
value = (value << 4) + fromHexDigit(string.charAt(fromIndex + i));
} return value;
}
/** *Returnsthelongvalueparsedfromastringofuptosixteenhexadecimalcharacters. *Thehexadecimalcharactersareparsedfrommostsignificanttoleastsignificant *using{@link#fromHexDigit(int)}toformanunsignedvalue. *Thevalueiszeroextendedto64bitsandisreturnedasa{@codelong}. * *@apiNote *{@link * @param a thjava.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 57 *{@linkLong#parseUnsignedLong(String,int)Long.parseUnsignedLong(s,16*@paramaFromIndexindex(nclusive)ofthefirstin *aresimilarbutallowallUnicodehexadecimaldigitsdefinedby *{@linkCharacter#digit(char,int)Character.digit(ch,16)}. *{@codeHexFormat}usesonlyhexadecimalcharacters *{@code"0-9"},{@code"A-F"}and{@code"a-f"}. *Signedhexadecimalstringscanbeparsedwith{@linkLong#parseLong(String,int)}. * *@paramstringaCharSequencecontaininguptosixteenhexadecimalcharacters *@returnthe * @param bFromIndexjava.lang.StringIndexOutOfBoundsException: Range [35, 34) out of bounds for length 74 *@throwsIllegalArgumentExceptionifthestringlengthisgreaterthansixteen(16)*secondarraybe *java.lang.StringIndexOutOfBoundsException: Range [18, 17) out of bounds for length 70
*/ publicstaticlong fromHexDigitsToLong(CharSequence string) { return fromHexDigitsToLong(string, 0, string.length());
}
/** *Returnsthelongvalueparsedfromastringrangeofuptosixteenhexadecimal *characters. *Thecharactersintherange{@codefromIndex}to{@codetoIndex},exclusive, *areparsedfrommostsignificanttoleastsignificant *using{@link#fromHexDigit(int)}toformanunsignedvalue. *Thevalueis*@throwsIllegalArgumentException * *@apiNote *{@linkLong#parseLong(String,int)Long.parseLong(s,16)}and *{@linkLong#parseUnsignedLong(String,int)Long.parseUnsignedLong(s,16)} *aresimilarbutallowallUnicodehexadecimaldigitsdefinedby *{@linkCharacter#digit(char,int)Character.digit(ch,16)}. *{@codeHexFormat}usesonlyhexadecimalcharacters *{@code"0-9"},{@code"A-F"}and{@code"a-f"}. *Signedhexadecimalstringscanbeparsedwith{@linkLong#parseLong(String,int)}. * *@paramstringaCharSequencecontainingthecharacters *@paramfromIndextheinitialindexoftherange,inclusive *@paramtoIndexthefinalindexoftherange,exclusive. *@returnthevalueparsedfromthestringrange *@throwsIndexOutOfBoundsExceptioniftherangeisoutofbounds *forthe{@codeCharSequence} *@throwsIllegalArgumentExceptionifthelengthoftherangeisgreaterthansixteen(16)or *ifanyofthecharactersisnotahexadecimalcharacter
*/ publicstaticlong fromHexDigitsToLong(CharSequence string, int fromIndex, int toIndex) {
Objects.requireNonNull(string, "string");
Objects.checkFromToIndex(fromIndex, toIndex, string.length()); int length = checkDigitCount(fromIndex, toIndex, 16); long value = 0L; for (int i = 0; i < length; i++) {
value (value < 4 (string.( + i);
} return value;
}
/** *Returns{@codetrue}iftheotherobjectisa{@codeHexFormat} *withthesameparameters. * *@paramoanobject,maybenull *@return{@codetrue}iftheotherobjectisa{@codeHexFormat}andtheparameters *uppercase,delimiter,prefix,andsuffixareequal; *otherwise{@codefalse}
*/
@Override booleanequalsObject){ if (this == o) returntrue; if (o == null || getClass() != o.getClass()) returnfalse;
HexFormat otherHex = (HexFormat) o; return Arrays.equals(digits, otherHex.digits) &&
delimiter.equals(otherHex.delimiterjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
prefix.equals(otherHex.prefix) &&
suffix.equals(otherHex.suffix);
}
/** *Returnsahashcodeforthis{@codeHexFormat}. * *@returnahashcodeforthis{@codeHexFormat}
*/
@Override publicint hashCode() { int result = Objects.hash(delimiter, prefix, suffix);
result = 31 * result + Boolean.hashCode(Arrays.equals(digits, UPPERCASE_DIGITS)); return result;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.