@Override public boolean equals(Object obj) { if (obj == null || obj.getClass() != AsciiString.class) { return false; } if (this == obj) { return true; } AsciiString other = (AsciiString) obj; return length() == other.length() && hashCode() == other.hashCode() && PlatformDependent.equals(array(), arrayOffset(), other.array(), other.arrayOffset(), length()); }
/** * Copies the content of {@code src} to a {@link ByteBuf} using {@link ByteBuf#writeBytes(byte[], int, int)}. * * @param src the source string to copy * @param srcIdx the starting offset of characters to copy * @param dst the destination buffer * @param length the number of characters to copy */ public static void copy(AsciiString src, int srcIdx, ByteBuf dst, int length) { if (isOutOfBounds(srcIdx, length, src.length())) { throw new IndexOutOfBoundsException("expected: " + "0 <= srcIdx(" + srcIdx + ") <= srcIdx + length(" + length + ") <= srcLen(" + src.length() + ')'); } checkNotNull(dst, "dst").writeBytes(src.array(), srcIdx + src.arrayOffset(), length); }
@Override public boolean equals(Object obj) { if (obj == null || obj.getClass() != AsciiString.class) { return false; } if (this == obj) { return true; } AsciiString other = (AsciiString) obj; return length() == other.length() && hashCode() == other.hashCode() && PlatformDependent.equals(array(), arrayOffset(), other.array(), other.arrayOffset(), length()); }
/** * Compare two {@link CharSequence} objects without leaking timing information. * <p> * The {@code int} return type is intentional and is designed to allow cascading of constant time operations: * <pre> * String s1 = "foo"; * String s2 = "foo"; * String s3 = "foo"; * String s4 = "goo"; * boolean equals = (equalsConstantTime(s1, s2) & equalsConstantTime(s3, s4)) != 0; * </pre> * @param s1 the first value. * @param s2 the second value. * @return {@code 0} if not equal. {@code 1} if equal. */ static int equalsConstantTime(CharSequence s1, CharSequence s2) { if (s1 instanceof AsciiString && s2 instanceof AsciiString) { if (s1.length() != s2.length()) { return 0; } AsciiString s1Ascii = (AsciiString) s1; AsciiString s2Ascii = (AsciiString) s2; return PlatformDependent.equalsConstantTime(s1Ascii.array(), s1Ascii.arrayOffset(), s2Ascii.array(), s2Ascii.arrayOffset(), s1.length()); } return ConstantTimeUtils.equalsConstantTime(s1, s2); }
/** * Copies the content of {@code src} to a {@link ByteBuf} using {@link ByteBuf#writeBytes(byte[], int, int)}. * * @param src the source string to copy * @param srcIdx the starting offset of characters to copy * @param dst the destination buffer * @param length the number of characters to copy */ public static void copy(AsciiString src, int srcIdx, ByteBuf dst, int length) { if (isOutOfBounds(srcIdx, length, src.length())) { throw new IndexOutOfBoundsException("expected: " + "0 <= srcIdx(" + srcIdx + ") <= srcIdx + length(" + length + ") <= srcLen(" + src.length() + ')'); } checkNotNull(dst, "dst").writeBytes(src.array(), srcIdx + src.arrayOffset(), length); }
@Override public boolean equals(Object obj) { if (obj == null || obj.getClass() != AsciiString.class) { return false; } if (this == obj) { return true; } AsciiString other = (AsciiString) obj; return length() == other.length() && hashCode() == other.hashCode() && PlatformDependent.equals(array(), arrayOffset(), other.array(), other.arrayOffset(), length()); }
if (seq instanceof AsciiString) { AsciiString asciiString = (AsciiString) seq; buf.writeBytes(asciiString.array(), asciiString.arrayOffset(), len); } else { for (;;) {
/** * Copies the content of {@code src} to a {@link ByteBuf} using {@link ByteBuf#setBytes(int, byte[], int, int)}. * Unlike the {@link #copy(AsciiString, ByteBuf)} and {@link #copy(AsciiString, int, ByteBuf, int)} methods, * this method do not increase a {@code writerIndex} of {@code dst} buffer. * * @param src the source string to copy * @param srcIdx the starting offset of characters to copy * @param dst the destination buffer * @param dstIdx the starting offset in the destination buffer * @param length the number of characters to copy */ public static void copy(AsciiString src, int srcIdx, ByteBuf dst, int dstIdx, int length) { if (isOutOfBounds(srcIdx, length, src.length())) { throw new IndexOutOfBoundsException("expected: " + "0 <= srcIdx(" + srcIdx + ") <= srcIdx + length(" + length + ") <= srcLen(" + src.length() + ')'); } checkNotNull(dst, "dst").setBytes(dstIdx, src.array(), srcIdx + src.arrayOffset(), length); }
/** * Copies the content of {@code src} to a {@link ByteBuf} using {@link ByteBuf#writeBytes(byte[], int, int)}. * * @param src the source string to copy * @param srcIdx the starting offset of characters to copy * @param dst the destination buffer * @param length the number of characters to copy */ public static void copy(AsciiString src, int srcIdx, ByteBuf dst, int length) { if (isOutOfBounds(srcIdx, length, src.length())) { throw new IndexOutOfBoundsException("expected: " + "0 <= srcIdx(" + srcIdx + ") <= srcIdx + length(" + length + ") <= srcLen(" + src.length() + ')'); } checkNotNull(dst, "dst").writeBytes(src.array(), srcIdx + src.arrayOffset(), length); }
if (seq instanceof AsciiString) { AsciiString asciiString = (AsciiString) seq; buf.writeBytes(asciiString.array(), asciiString.arrayOffset(), len); } else { for (;;) {
/** * Copies the content of {@code src} to a {@link ByteBuf} using {@link ByteBuf#setBytes(int, byte[], int, int)}. * Unlike the {@link #copy(AsciiString, ByteBuf)} and {@link #copy(AsciiString, int, ByteBuf, int)} methods, * this method do not increase a {@code writerIndex} of {@code dst} buffer. * * @param src the source string to copy * @param srcIdx the starting offset of characters to copy * @param dst the destination buffer * @param dstIdx the starting offset in the destination buffer * @param length the number of characters to copy */ public static void copy(AsciiString src, int srcIdx, ByteBuf dst, int dstIdx, int length) { if (isOutOfBounds(srcIdx, length, src.length())) { throw new IndexOutOfBoundsException("expected: " + "0 <= srcIdx(" + srcIdx + ") <= srcIdx + length(" + length + ") <= srcLen(" + src.length() + ')'); } checkNotNull(dst, "dst").setBytes(dstIdx, src.array(), srcIdx + src.arrayOffset(), length); }
private static void convertHeaders(HttpHeaders headers, MimeHeaders cHeaders) { if (headers.isEmpty()) { return; } for (Entry<AsciiString, String> e : headers) { final AsciiString k = e.getKey(); final String v = e.getValue(); if (k.isEmpty() || k.byteAt(0) == ':') { continue; } final MessageBytes cValue = cHeaders.addValue(k.array(), k.arrayOffset(), k.length()); final byte[] valueBytes = v.getBytes(StandardCharsets.US_ASCII); cValue.setBytes(valueBytes, 0, valueBytes.length); } }
if (seq instanceof AsciiString) { AsciiString asciiString = (AsciiString) seq; buf.writeBytes(asciiString.array(), asciiString.arrayOffset(), len); } else { for (;;) {
/** * Copies the content of {@code src} to a {@link ByteBuf} using {@link ByteBuf#setBytes(int, byte[], int, int)}. * Unlike the {@link #copy(AsciiString, ByteBuf)} and {@link #copy(AsciiString, int, ByteBuf, int)} methods, * this method do not increase a {@code writerIndex} of {@code dst} buffer. * * @param src the source string to copy * @param srcIdx the starting offset of characters to copy * @param dst the destination buffer * @param dstIdx the starting offset in the destination buffer * @param length the number of characters to copy */ public static void copy(AsciiString src, int srcIdx, ByteBuf dst, int dstIdx, int length) { if (isOutOfBounds(srcIdx, length, src.length())) { throw new IndexOutOfBoundsException("expected: " + "0 <= srcIdx(" + srcIdx + ") <= srcIdx + length(" + length + ") <= srcLen(" + src.length() + ')'); } checkNotNull(dst, "dst").setBytes(dstIdx, src.array(), srcIdx + src.arrayOffset(), length); }
/** * Encode string literal according to Section 5.2. */ private void encodeStringLiteral(ByteBuf out, CharSequence string) { int huffmanLength = hpackHuffmanEncoder.getEncodedLength(string); if (huffmanLength < string.length()) { encodeInteger(out, 0x80, 7, huffmanLength); hpackHuffmanEncoder.encode(out, string); } else { encodeInteger(out, 0x00, 7, string.length()); if (string instanceof AsciiString) { // Fast-path AsciiString asciiString = (AsciiString) string; out.writeBytes(asciiString.array(), asciiString.arrayOffset(), asciiString.length()); } else { // Only ASCII is allowed in http2 headers, so its fine to use this. // https://tools.ietf.org/html/rfc7540#section-8.1.2 out.writeCharSequence(string, CharsetUtil.ISO_8859_1); } } }
@Override public boolean equals(Object obj) { if (obj == null || obj.getClass() != AsciiString.class) { return false; } if (this == obj) { return true; } AsciiString other = (AsciiString) obj; return length() == other.length() && hashCode() == other.hashCode() && PlatformDependent.equals(array(), arrayOffset(), other.array(), other.arrayOffset(), length()); }
/** * Copies the content of {@code src} to a {@link ByteBuf} using {@link ByteBuf#writeBytes(byte[], int, int)}. * * @param src the source string to copy * @param srcIdx the starting offset of characters to copy * @param dst the destination buffer * @param length the number of characters to copy */ public static void copy(AsciiString src, int srcIdx, ByteBuf dst, int length) { if (isOutOfBounds(srcIdx, length, src.length())) { throw new IndexOutOfBoundsException("expected: " + "0 <= srcIdx(" + srcIdx + ") <= srcIdx + length(" + length + ") <= srcLen(" + src.length() + ')'); } checkNotNull(dst, "dst").writeBytes(src.array(), srcIdx + src.arrayOffset(), length); }
if (seq instanceof AsciiString) { AsciiString asciiString = (AsciiString) seq; buf.writeBytes(asciiString.array(), asciiString.arrayOffset(), len); } else { for (;;) {
/** * Copies the content of {@code src} to a {@link ByteBuf} using {@link ByteBuf#setBytes(int, byte[], int, int)}. * Unlike the {@link #copy(AsciiString, ByteBuf)} and {@link #copy(AsciiString, int, ByteBuf, int)} methods, * this method do not increase a {@code writerIndex} of {@code dst} buffer. * * @param src the source string to copy * @param srcIdx the starting offset of characters to copy * @param dst the destination buffer * @param dstIdx the starting offset in the destination buffer * @param length the number of characters to copy */ public static void copy(AsciiString src, int srcIdx, ByteBuf dst, int dstIdx, int length) { if (isOutOfBounds(srcIdx, length, src.length())) { throw new IndexOutOfBoundsException("expected: " + "0 <= srcIdx(" + srcIdx + ") <= srcIdx + length(" + length + ") <= srcLen(" + src.length() + ')'); } checkNotNull(dst, "dst").setBytes(dstIdx, src.array(), srcIdx + src.arrayOffset(), length); }
@Override public boolean equals(Object obj) { if (obj == null || obj.getClass() != AsciiString.class) { return false; } if (this == obj) { return true; } AsciiString other = (AsciiString) obj; return length() == other.length() && hashCode() == other.hashCode() && PlatformDependent.equals(array(), arrayOffset(), other.array(), other.arrayOffset(), length()); }