private void copyContent(final CharSequence buf, final ParserCursor cursor, final StringBuilder dst) { int pos = cursor.getPos(); final int indexFrom = cursor.getPos(); final int indexTo = cursor.getUpperBound(); for (int i = indexFrom; i < indexTo; i++) { final char current = buf.charAt(i); if (DELIMS.get(current)) { break; } pos++; dst.append(current); } cursor.updatePos(pos); }
private void skipDelims(final CharSequence buf, final ParserCursor cursor) { int pos = cursor.getPos(); final int indexFrom = cursor.getPos(); final int indexTo = cursor.getUpperBound(); for (int i = indexFrom; i < indexTo; i++) { final char current = buf.charAt(i); if (DELIMS.get(current)) { pos++; } else { break; } } cursor.updatePos(pos); }
@Override public void copyUnquotedContent( final CharSequence buf, final ParserCursor cursor, final BitSet delimiters, final StringBuilder dst) { int pos = cursor.getPos(); final int indexFrom = cursor.getPos(); final int indexTo = cursor.getUpperBound(); boolean escaped = false; for (int i = indexFrom; i < indexTo; i++, pos++) { final char current = buf.charAt(i); if (escaped) { dst.append(current); escaped = false; } else { if ((delimiters != null && delimiters.get(current)) || TokenParser.isWhitespace(current) || current == '\"') { break; } else if (current == '\\') { escaped = true; } else { dst.append(current); } } } cursor.updatePos(pos); } }
final BitSet delimiters) throws ParseException { final int lowerBound = cursor.getLowerBound(); final int upperBound = cursor.getUpperBound(); if (pos + 4 > cursor.getUpperBound()) { throw new ParseException("Invalid TLS protocol version", buffer, lowerBound, upperBound, pos);
final int indexTo = cursor.getUpperBound(); char current = buf.charAt(pos); if (current != DQUOTE) {
/** * Transfers content into the destination buffer until a whitespace character or any of * the given delimiters is encountered. * * @param buf buffer with the sequence of chars to be parsed * @param cursor defines the bounds and current position of the buffer * @param delimiters set of delimiting characters. Can be {@code null} if the value * is delimited by a whitespace only. * @param dst destination buffer */ public void copyContent(final CharSequence buf, final ParserCursor cursor, final BitSet delimiters, final StringBuilder dst) { Args.notNull(buf, "Char sequence"); Args.notNull(cursor, "Parser cursor"); Args.notNull(dst, "String builder"); int pos = cursor.getPos(); final int indexFrom = cursor.getPos(); final int indexTo = cursor.getUpperBound(); for (int i = indexFrom; i < indexTo; i++) { final char current = buf.charAt(i); if ((delimiters != null && delimiters.get(current)) || isWhitespace(current)) { break; } pos++; dst.append(current); } cursor.updatePos(pos); }
final int indexTo = cursor.getUpperBound(); char current = buf.charAt(pos); if (current != DQUOTE) {
@Override public StatusLine parseStatusLine(final CharArrayBuffer buffer) throws ParseException { Args.notNull(buffer, "Char array buffer"); final ParserCursor cursor = new ParserCursor(0, buffer.length()); this.tokenParser.skipWhiteSpace(buffer, cursor); final ProtocolVersion ver = parseProtocolVersion(buffer, cursor); this.tokenParser.skipWhiteSpace(buffer, cursor); final String s = this.tokenParser.parseToken(buffer, cursor, BLANKS); for (int i = 0; i < s.length(); i++) { if (!Character.isDigit(s.charAt(i))) { throw new ParseException("Status line contains invalid status code", buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos()); } } final int statusCode; try { statusCode = Integer.parseInt(s); } catch (final NumberFormatException e) { throw new ParseException("Status line contains invalid status code", buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos()); } final String text = buffer.substringTrimmed(cursor.getPos(), cursor.getUpperBound()); return new StatusLine(ver, statusCode, text); }
/** * Transfers content into the destination buffer until a whitespace character, a quote, * or any of the given delimiters is encountered. * * @param buf buffer with the sequence of chars to be parsed * @param cursor defines the bounds and current position of the buffer * @param delimiters set of delimiting characters. Can be {@code null} if the value * is delimited by a whitespace or a quote only. * @param dst destination buffer */ public void copyUnquotedContent(final CharSequence buf, final ParserCursor cursor, final BitSet delimiters, final StringBuilder dst) { Args.notNull(buf, "Char sequence"); Args.notNull(cursor, "Parser cursor"); Args.notNull(dst, "String builder"); int pos = cursor.getPos(); final int indexFrom = cursor.getPos(); final int indexTo = cursor.getUpperBound(); for (int i = indexFrom; i < indexTo; i++) { final char current = buf.charAt(i); if ((delimiters != null && delimiters.get(current)) || isWhitespace(current) || current == DQUOTE) { break; } pos++; dst.append(current); } cursor.updatePos(pos); }
@Override public StatusLine parseStatusLine(final CharArrayBuffer buffer) throws ParseException { Args.notNull(buffer, "Char array buffer"); final ParserCursor cursor = new ParserCursor(0, buffer.length()); this.tokenParser.skipWhiteSpace(buffer, cursor); final ProtocolVersion ver = parseProtocolVersion(buffer, cursor); this.tokenParser.skipWhiteSpace(buffer, cursor); final String s = this.tokenParser.parseToken(buffer, cursor, BLANKS); for (int i = 0; i < s.length(); i++) { if (!Character.isDigit(s.charAt(i))) { throw new ParseException("Status line contains invalid status code", buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos()); } } final int statusCode; try { statusCode = Integer.parseInt(s); } catch (final NumberFormatException e) { throw new ParseException("Status line contains invalid status code", buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos()); } final String text = buffer.substringTrimmed(cursor.getPos(), cursor.getUpperBound()); return new StatusLine(ver, statusCode, text); }
/** * Transfers content into the destination buffer until a whitespace character or any of * the given delimiters is encountered. * * @param buf buffer with the sequence of chars to be parsed * @param cursor defines the bounds and current position of the buffer * @param delimiters set of delimiting characters. Can be {@code null} if the value * is delimited by a whitespace only. * @param dst destination buffer */ public void copyContent(final CharSequence buf, final ParserCursor cursor, final BitSet delimiters, final StringBuilder dst) { Args.notNull(buf, "Char sequence"); Args.notNull(cursor, "Parser cursor"); Args.notNull(dst, "String builder"); int pos = cursor.getPos(); final int indexFrom = cursor.getPos(); final int indexTo = cursor.getUpperBound(); for (int i = indexFrom; i < indexTo; i++) { final char current = buf.charAt(i); if ((delimiters != null && delimiters.get(current)) || isWhitespace(current)) { break; } pos++; dst.append(current); } cursor.updatePos(pos); }
/** * Transfers content into the destination buffer until a whitespace character, a quote, * or any of the given delimiters is encountered. * * @param buf buffer with the sequence of chars to be parsed * @param cursor defines the bounds and current position of the buffer * @param delimiters set of delimiting characters. Can be {@code null} if the value * is delimited by a whitespace or a quote only. * @param dst destination buffer */ public void copyUnquotedContent(final CharSequence buf, final ParserCursor cursor, final BitSet delimiters, final StringBuilder dst) { Args.notNull(buf, "Char sequence"); Args.notNull(cursor, "Parser cursor"); Args.notNull(dst, "String builder"); int pos = cursor.getPos(); final int indexFrom = cursor.getPos(); final int indexTo = cursor.getUpperBound(); for (int i = indexFrom; i < indexTo; i++) { final char current = buf.charAt(i); if ((delimiters != null && delimiters.get(current)) || isWhitespace(current) || current == DQUOTE) { break; } pos++; dst.append(current); } cursor.updatePos(pos); }
/** * Skips semantically insignificant whitespace characters and moves the cursor to the closest * non-whitespace character. * * @param buf buffer with the sequence of chars to be parsed * @param cursor defines the bounds and current position of the buffer */ public void skipWhiteSpace(final CharSequence buf, final ParserCursor cursor) { Args.notNull(buf, "Char sequence"); Args.notNull(cursor, "Parser cursor"); int pos = cursor.getPos(); final int indexFrom = cursor.getPos(); final int indexTo = cursor.getUpperBound(); for (int i = indexFrom; i < indexTo; i++) { final char current = buf.charAt(i); if (!isWhitespace(current)) { break; } pos++; } cursor.updatePos(pos); }
/** * Skips semantically insignificant whitespace characters and moves the cursor to the closest * non-whitespace character. * * @param buf buffer with the sequence of chars to be parsed * @param cursor defines the bounds and current position of the buffer */ public void skipWhiteSpace(final CharSequence buf, final ParserCursor cursor) { Args.notNull(buf, "Char sequence"); Args.notNull(cursor, "Parser cursor"); int pos = cursor.getPos(); final int indexFrom = cursor.getPos(); final int indexTo = cursor.getUpperBound(); for (int i = indexFrom; i < indexTo; i++) { final char current = buf.charAt(i); if (!isWhitespace(current)) { break; } pos++; } cursor.updatePos(pos); }
if (pos + protolength + 4 > cursor.getUpperBound()) { throw new ParseException("Invalid protocol version", buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos()); buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos()); } catch (final NumberFormatException e) { throw new ParseException("Invalid protocol major version number", buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos()); buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos()); } catch (final NumberFormatException e) { throw new ParseException("Invalid protocol minor version number", buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos());
if (pos + protolength + 4 > cursor.getUpperBound()) { throw new ParseException("Invalid protocol version", buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos()); buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos()); } catch (final NumberFormatException e) { throw new ParseException("Invalid protocol major version number", buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos()); buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos()); } catch (final NumberFormatException e) { throw new ParseException("Invalid protocol minor version number", buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos());
@Override public Header parseHeader(final CharArrayBuffer buffer) throws ParseException { Args.notNull(buffer, "Char array buffer"); final ParserCursor cursor = new ParserCursor(0, buffer.length()); this.tokenParser.skipWhiteSpace(buffer, cursor); final String name = this.tokenParser.parseToken(buffer, cursor, COLON); if (cursor.getPos() == cursor.getLowerBound() || cursor.getPos() == cursor.getUpperBound() || buffer.charAt(cursor.getPos()) != ':' || TextUtils.isEmpty(name) || TokenParser.isWhitespace(buffer.charAt(cursor.getPos() - 1))) { throw new ParseException("Invalid header", buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos()); } final String value = buffer.substringTrimmed(cursor.getPos() + 1, cursor.getUpperBound()); return new BasicHeader(name, value); }
@Override public Header parseHeader(final CharArrayBuffer buffer) throws ParseException { Args.notNull(buffer, "Char array buffer"); final ParserCursor cursor = new ParserCursor(0, buffer.length()); this.tokenParser.skipWhiteSpace(buffer, cursor); final String name = this.tokenParser.parseToken(buffer, cursor, COLON); if (cursor.getPos() == cursor.getLowerBound() || cursor.getPos() == cursor.getUpperBound() || buffer.charAt(cursor.getPos()) != ':' || TextUtils.isEmpty(name) || TokenParser.isWhitespace(buffer.charAt(cursor.getPos() - 1))) { throw new ParseException("Invalid header", buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos()); } final String value = buffer.substringTrimmed(cursor.getPos() + 1, cursor.getUpperBound()); return new BasicHeader(name, value); }
if (TextUtils.isEmpty(method)) { throw new ParseException("Invalid request line", buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos()); if (TextUtils.isEmpty(uri)) { throw new ParseException("Invalid request line", buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos()); if (!cursor.atEnd()) { throw new ParseException("Invalid request line", buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos());
if (TextUtils.isEmpty(method)) { throw new ParseException("Invalid request line", buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos()); if (TextUtils.isEmpty(uri)) { throw new ParseException("Invalid request line", buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos()); if (!cursor.atEnd()) { throw new ParseException("Invalid request line", buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos());