@Override public void validateName(CharSequence name) { if (name == null || name.length() == 0) { throw new IllegalArgumentException("empty headers are not allowed [" + name + "]"); } if (name instanceof AsciiString) { try { ((AsciiString) name).forEachByte(HEADER_NAME_VALIDATOR); } catch (Exception e) { PlatformDependent.throwException(e); } } else { // Go through each character in the name for (int index = 0; index < name.length(); ++index) { validateHeaderNameElement(name.charAt(index)); } } } };
/** * Parses the specified HTTP status line into a {@link HttpResponseStatus}. The expected formats of the line are: * <ul> * <li>{@code statusCode} (e.g. 200)</li> * <li>{@code statusCode} {@code reasonPhrase} (e.g. 404 Not Found)</li> * </ul> * * @throws IllegalArgumentException if the specified status line is malformed */ public static HttpResponseStatus parseLine(AsciiString line) { try { int space = line.forEachByte(FIND_ASCII_SPACE); return space == -1 ? valueOf(line.parseInt()) : valueOf(line.parseInt(0, space), line.toString(space + 1)); } catch (Exception e) { throw new IllegalArgumentException("malformed status line: " + line, e); } }
/** * Compresses the input string literal using the Huffman coding. * * @param out the output stream for the compressed data * @param data the string literal to be Huffman encoded */ public void encode(ByteBuf out, CharSequence data) { ObjectUtil.checkNotNull(out, "out"); if (data instanceof AsciiString) { AsciiString string = (AsciiString) data; try { encodeProcessor.out = out; string.forEachByte(encodeProcessor); } catch (Exception e) { PlatformDependent.throwException(e); } finally { encodeProcessor.end(); } } else { encodeSlowPath(out, data); } }
/** * Returns the number of bytes required to Huffman encode the input string literal. * * @param data the string literal to be Huffman encoded * @return the number of bytes required to Huffman encode {@code data} */ int getEncodedLength(CharSequence data) { if (data instanceof AsciiString) { AsciiString string = (AsciiString) data; try { encodedLengthProcessor.reset(); string.forEachByte(encodedLengthProcessor); return encodedLengthProcessor.length(); } catch (Exception e) { PlatformDependent.throwException(e); return -1; } } else { return getEncodedLengthSlowPath(data); } }
final int index; try { index = ((AsciiString) name).forEachByte(HTTP2_NAME_VALIDATOR_PROCESSOR); } catch (Http2Exception e) { PlatformDependent.throwException(e);
private static CharSequenceMap toLowercaseMap(Iterator<? extends CharSequence> valuesIter, int arraySizeHint) { final CharSequenceMap result = new CharSequenceMap(arraySizeHint); while (valuesIter.hasNext()) { final AsciiString lowerCased = HttpHeaderNames.of(valuesIter.next()).toLowerCase(); try { int index = lowerCased.forEachByte(FIND_COMMA); if (index != -1) { int start = 0; do { result.add(lowerCased.subSequence(start, index, false).trim(), EMPTY_STRING); start = index + 1; } while (start < lowerCased.length() && (index = lowerCased.forEachByte(start, lowerCased.length() - start, FIND_COMMA)) != -1); result.add(lowerCased.subSequence(start, lowerCased.length(), false).trim(), EMPTY_STRING); } else { result.add(lowerCased.trim(), EMPTY_STRING); } } catch (Exception e) { // This is not expect to happen because FIND_COMMA never throws but must be caught // because of the ByteProcessor interface. throw new IllegalStateException(e); } } return result; }
private static CharSequenceMap<AsciiString> toLowercaseMap(Iterator<? extends CharSequence> valuesIter, int arraySizeHint) { UnsupportedValueConverter<AsciiString> valueConverter = UnsupportedValueConverter.<AsciiString>instance(); CharSequenceMap<AsciiString> result = new CharSequenceMap<AsciiString>(true, valueConverter, arraySizeHint); while (valuesIter.hasNext()) { AsciiString lowerCased = AsciiString.of(valuesIter.next()).toLowerCase(); try { int index = lowerCased.forEachByte(FIND_COMMA); if (index != -1) { int start = 0; do { result.add(lowerCased.subSequence(start, index, false).trim(), EMPTY_STRING); start = index + 1; } while (start < lowerCased.length() && (index = lowerCased.forEachByte(start, lowerCased.length() - start, FIND_COMMA)) != -1); result.add(lowerCased.subSequence(start, lowerCased.length(), false).trim(), EMPTY_STRING); } else { result.add(lowerCased.trim(), EMPTY_STRING); } } catch (Exception e) { // This is not expect to happen because FIND_COMMA never throws but must be caught // because of the ByteProcessor interface. throw new IllegalStateException(e); } } return result; }
int index = value.forEachByte(FIND_SEMI_COLON); if (index != -1) { int start = 0; (index = value.forEachByte(start, value.length() - start, FIND_SEMI_COLON)) != -1); if (start >= value.length()) { throw new IllegalArgumentException("cookie value is of unexpected format: " + value);
@Override public void validateName(CharSequence name) { if (name == null || name.length() == 0) { throw new IllegalArgumentException("empty headers are not allowed [" + name + "]"); } if (name instanceof AsciiString) { try { ((AsciiString) name).forEachByte(HEADER_NAME_VALIDATOR); } catch (Exception e) { PlatformDependent.throwException(e); } } else { // Go through each character in the name for (int index = 0; index < name.length(); ++index) { validateHeaderNameElement(name.charAt(index)); } } } };
@Override public void validateName(CharSequence name) { if (name == null || name.length() == 0) { throw new IllegalArgumentException("empty headers are not allowed [" + name + "]"); } if (name instanceof AsciiString) { try { ((AsciiString) name).forEachByte(HEADER_NAME_VALIDATOR); } catch (Exception e) { PlatformDependent.throwException(e); } } else { // Go through each character in the name for (int index = 0; index < name.length(); ++index) { validateHeaderNameElement(name.charAt(index)); } } } };
@Override public void validateName(CharSequence name) { if (name == null || name.length() == 0) { throw new IllegalArgumentException("empty headers are not allowed [" + name + "]"); } if (name instanceof AsciiString) { try { ((AsciiString) name).forEachByte(HEADER_NAME_VALIDATOR); } catch (Exception e) { PlatformDependent.throwException(e); } } else { // Go through each character in the name for (int index = 0; index < name.length(); ++index) { validateHeaderNameElement(name.charAt(index)); } } } };
@Override public void validateName(CharSequence name) { if (name == null || name.length() == 0) { throw new IllegalArgumentException("empty headers are not allowed [" + name + "]"); } if (name instanceof AsciiString) { try { ((AsciiString) name).forEachByte(HEADER_NAME_VALIDATOR); } catch (Exception e) { PlatformDependent.throwException(e); } } else { // Go through each character in the name for (int index = 0; index < name.length(); ++index) { validateHeaderNameElement(name.charAt(index)); } } } };
@Override public void validateName(CharSequence name) { if (name instanceof AsciiString) { try { ((AsciiString) name).forEachByte(HEADER_NAME_VALIDATOR); } catch (Exception e) { PlatformDependent.throwException(e); } } else { checkNotNull(name, "name"); // Go through each character in the name for (int index = 0; index < name.length(); ++index) { validateChar(name.charAt(index)); } } } };
/** * Parses the specified HTTP status line into a {@link HttpResponseStatus}. The expected formats of the line are: * <ul> * <li>{@code statusCode} (e.g. 200)</li> * <li>{@code statusCode} {@code reasonPhrase} (e.g. 404 Not Found)</li> * </ul> * * @throws IllegalArgumentException if the specified status line is malformed */ public static HttpResponseStatus parseLine(AsciiString line) { try { int space = line.forEachByte(FIND_ASCII_SPACE); return space == -1 ? valueOf(line.parseInt()) : valueOf(line.parseInt(0, space), line.toString(space + 1)); } catch (Exception e) { throw new IllegalArgumentException("malformed status line: " + line, e); } }
/** * Parses the specified HTTP status line into a {@link HttpResponseStatus}. The expected formats of the line are: * <ul> * <li>{@code statusCode} (e.g. 200)</li> * <li>{@code statusCode} {@code reasonPhrase} (e.g. 404 Not Found)</li> * </ul> * * @throws IllegalArgumentException if the specified status line is malformed */ public static HttpResponseStatus parseLine(AsciiString line) { try { int space = line.forEachByte(FIND_ASCII_SPACE); return space == -1 ? valueOf(line.parseInt()) : valueOf(line.parseInt(0, space), line.toString(space + 1)); } catch (Exception e) { throw new IllegalArgumentException("malformed status line: " + line, e); } }
/** * Parses the specified HTTP status line into a {@link HttpResponseStatus}. The expected formats of the line are: * <ul> * <li>{@code statusCode} (e.g. 200)</li> * <li>{@code statusCode} {@code reasonPhrase} (e.g. 404 Not Found)</li> * </ul> * * @throws IllegalArgumentException if the specified status line is malformed */ public static HttpResponseStatus parseLine(AsciiString line) { try { int space = line.forEachByte(FIND_ASCII_SPACE); return space == -1 ? valueOf(line.parseInt()) : valueOf(line.parseInt(0, space), line.toString(space + 1)); } catch (Exception e) { throw new IllegalArgumentException("malformed status line: " + line, e); } }
/** * Parses the specified HTTP status line into a {@link HttpResponseStatus}. The expected formats of the line are: * <ul> * <li>{@code statusCode} (e.g. 200)</li> * <li>{@code statusCode} {@code reasonPhrase} (e.g. 404 Not Found)</li> * </ul> * * @throws IllegalArgumentException if the specified status line is malformed */ public static HttpResponseStatus parseLine(AsciiString line) { try { int space = line.forEachByte(FIND_ASCII_SPACE); return space == -1 ? valueOf(line.parseInt()) : valueOf(line.parseInt(0, space), line.toString(space + 1)); } catch (Exception e) { throw new IllegalArgumentException("malformed status line: " + line, e); } }
/** * Returns the number of bytes required to Huffman encode the input string literal. * * @param data the string literal to be Huffman encoded * @return the number of bytes required to Huffman encode {@code data} */ int getEncodedLength(CharSequence data) { if (data instanceof AsciiString) { AsciiString string = (AsciiString) data; try { encodedLengthProcessor.reset(); string.forEachByte(encodedLengthProcessor); return encodedLengthProcessor.length(); } catch (Exception e) { PlatformDependent.throwException(e); return -1; } } else { return getEncodedLengthSlowPath(data); } }
/** * Returns the number of bytes required to Huffman encode the input string literal. * * @param data the string literal to be Huffman encoded * @return the number of bytes required to Huffman encode {@code data} */ int getEncodedLength(CharSequence data) { if (data instanceof AsciiString) { AsciiString string = (AsciiString) data; try { encodedLengthProcessor.reset(); string.forEachByte(encodedLengthProcessor); return encodedLengthProcessor.length(); } catch (Exception e) { PlatformDependent.throwException(e); return -1; } } else { return getEncodedLengthSlowPath(data); } }
/** * Compresses the input string literal using the Huffman coding. * * @param out the output stream for the compressed data * @param data the string literal to be Huffman encoded */ public void encode(ByteBuf out, CharSequence data) { ObjectUtil.checkNotNull(out, "out"); if (data instanceof AsciiString) { AsciiString string = (AsciiString) data; try { encodeProcessor.out = out; string.forEachByte(encodeProcessor); } catch (Exception e) { PlatformDependent.throwException(e); } finally { encodeProcessor.end(); } } else { encodeSlowPath(out, data); } }