/** * Parses the sequence of bytes into {@link RawField}. * * @throws MimeException if the input data does not contain a valid MIME field. */ public RawField parseField(final ByteSequence raw) throws MimeException { if (raw == null) { return null; } ParserCursor cursor = new ParserCursor(0, raw.length()); String name = parseToken(raw, cursor, COLON); if (cursor.atEnd()) { throw new MimeException("Invalid MIME field: no name/value separator found: " + raw.toString()); } return new RawField(raw, cursor.getPos(), name, null); }
public AddressList parseAddressList(final ByteSequence buf, final ParserCursor cursor) { List<Address> addresses = new ArrayList<Address>(); while (!cursor.atEnd()) { int pos = cursor.getPos(); int current = (char) (buf.byteAt(pos) & 0xff); if (current == COMMA) { cursor.updatePos(pos + 1); } else { Address address = parseAddress(buf, cursor, COMMA_ONLY); if (address != null) { addresses.add(address); } } } return new AddressList(addresses, false); }
if (cursor.atEnd()) { return; int pos = cursor.getPos(); int indexFrom = cursor.getPos(); int indexTo = cursor.getUpperBound(); char current = (char) (buf.byteAt(pos) & 0xff); if (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 bytes to be parsed * @param cursor defines the bounds and current position of the buffer */ public void skipWhiteSpace(final ByteSequence buf, final ParserCursor cursor) { int pos = cursor.getPos(); int indexFrom = cursor.getPos(); int indexTo = cursor.getUpperBound(); for (int i = indexFrom; i < indexTo; i++) { char current = (char) (buf.byteAt(i) & 0xff); if (!CharsetUtil.isWhitespace(current)) { break; } else { pos++; } } cursor.updatePos(pos); }
ParserCursor cursor = new ParserCursor(pos, buf.length()); String token1 = parser.parseValue(buf, cursor, DELIM); try { if (!cursor.atEnd() && buf.byteAt(cursor.getPos()) == FULL_STOP) { cursor.updatePos(cursor.getPos() + 1);
String parseDomain(final ByteSequence buf, final ParserCursor cursor, final BitSet delimiters) { StringBuilder dst = new StringBuilder(); while (!cursor.atEnd()) { char current = (char) (buf.byteAt(cursor.getPos()) & 0xff); if (delimiters != null && delimiters.get(current)) { break; } else if (CharsetUtil.isWhitespace(current)) { this.parser.skipWhiteSpace(buf, cursor); } else if (current == '(') { this.parser.skipComment(buf, cursor); } else { this.parser.copyContent(buf, cursor, delimiters, dst); } } return dst.toString(); }
public Mailbox parseMailbox(final CharSequence text) { ByteSequence raw = ContentUtil.encode(text); ParserCursor cursor = new ParserCursor(0, text.length()); return parseMailbox(raw, cursor, null); }
/** * Parses the sequence of bytes containing field parameters delimited with semicolon into * a list of {@link NameValuePair}s. * * @param buf buffer with the sequence of bytes to be parsed * @param cursor defines the bounds and current position of the buffer */ public List<NameValuePair> parseParameters(final ByteSequence buf, final ParserCursor cursor) { List<NameValuePair> params = new ArrayList<NameValuePair>(); skipWhiteSpace(buf, cursor); while (!cursor.atEnd()) { NameValuePair param = parseParameter(buf, cursor); params.add(param); } return params; }
ParserCursor cursor = new ParserCursor(pos, buf.length()); for (;;) { String token = parser.parseToken(buf, cursor, DELIM); languages.add(token); if (cursor.atEnd()) { break; } else { pos = cursor.getPos(); if (buf.byteAt(pos) == COMMA) { cursor.updatePos(pos + 1);
/** * Transfers content into the destination buffer until a whitespace character, a comment, * a quote, or any of the given delimiters is encountered. * * @param buf buffer with the sequence of bytes to be parsed * @param cursor defines the bounds and current position of the buffer * @param delimiters set of delimiting characters. Can be <code>null</code> if the value * is delimited by a whitespace, a quote or a comment only. * @param dst destination buffer */ public void copyUnquotedContent(final ByteSequence buf, final ParserCursor cursor, final BitSet delimiters, final StringBuilder dst) { int pos = cursor.getPos(); int indexFrom = cursor.getPos(); int indexTo = cursor.getUpperBound(); for (int i = indexFrom; i < indexTo; i++) { char current = (char) (buf.byteAt(i) & 0xff); if ((delimiters != null && delimiters.get(current)) || CharsetUtil.isWhitespace(current) || current == '(' || current == '\"') { break; } else { pos++; dst.append(current); } } cursor.updatePos(pos); }
public Group parseGroup(final CharSequence text) { ByteSequence raw = ContentUtil.encode(text); ParserCursor cursor = new ParserCursor(0, text.length()); return parseGroup(raw, cursor); }
/** * Parses the sequence of bytes containing a value with parameters into {@link RawBody}. * * @param buf buffer with the sequence of bytes to be parsed * @param cursor defines the bounds and current position of the buffer */ public RawBody parseRawBody(final ByteSequence buf, final ParserCursor cursor) { String value = parseToken(buf, cursor, SEMICOLON); if (cursor.atEnd()) { return new RawBody(value, new ArrayList<NameValuePair>()); } cursor.updatePos(cursor.getPos() + 1); List<NameValuePair> params = parseParameters(buf, cursor); return new RawBody(value, params); }
if (cursor.atEnd()) { return; int pos = cursor.getPos(); int indexFrom = cursor.getPos(); int indexTo = cursor.getUpperBound(); char current = (char) (buf.byteAt(pos) & 0xff); if (current != '\"') { cursor.updatePos(pos);
/** * Transfers content into the destination buffer until a whitespace character, a comment, * or any of the given delimiters is encountered. * * @param buf buffer with the sequence of bytes to be parsed * @param cursor defines the bounds and current position of the buffer * @param delimiters set of delimiting characters. Can be <code>null</code> if the value * is delimited by a whitespace or a comment only. * @param dst destination buffer */ public void copyContent(final ByteSequence buf, final ParserCursor cursor, final BitSet delimiters, final StringBuilder dst) { int pos = cursor.getPos(); int indexFrom = cursor.getPos(); int indexTo = cursor.getUpperBound(); for (int i = indexFrom; i < indexTo; i++) { char current = (char) (buf.byteAt(i) & 0xff); if ((delimiters != null && delimiters.get(current)) || CharsetUtil.isWhitespace(current) || current == '(') { break; } else { pos++; dst.append(current); } } cursor.updatePos(pos); }
/** * Skips semantically insignificant whitespace characters and comments and moves the cursor * to the closest semantically significant non-whitespace character. * Nested comments and escaped characters are recognized and handled appropriately. * * @param buf buffer with the sequence of bytes to be parsed * @param cursor defines the bounds and current position of the buffer */ public void skipAllWhiteSpace(final ByteSequence buf, final ParserCursor cursor) { while (!cursor.atEnd()) { char current = (char) (buf.byteAt(cursor.getPos()) & 0xff); if (CharsetUtil.isWhitespace(current)) { skipWhiteSpace(buf, cursor); } else if (current == '(') { skipComment(buf, cursor); } else { break; } } }
public AddressList parseAddressList(final CharSequence text) { ByteSequence raw = ContentUtil.encode(text); ParserCursor cursor = new ParserCursor(0, text.length()); return parseAddressList(raw, cursor); }
/** * Parses the sequence of bytes containing a field parameter delimited with semicolon into * {@link NameValuePair}. * * @param buf buffer with the sequence of bytes to be parsed * @param cursor defines the bounds and current position of the buffer */ public NameValuePair parseParameter(final ByteSequence buf, final ParserCursor cursor) { String name = parseToken(buf, cursor, EQUAL_OR_SEMICOLON); if (cursor.atEnd()) { return new NameValuePair(name, null); } int delim = buf.byteAt(cursor.getPos()); cursor.updatePos(cursor.getPos() + 1); if (delim == ';') { return new NameValuePair(name, null); } String value = parseValue(buf, cursor, SEMICOLON); if (!cursor.atEnd()) { cursor.updatePos(cursor.getPos() + 1); } return new NameValuePair(name, value); }
public Address parseAddress(final CharSequence text) { ByteSequence raw = ContentUtil.encode(text); ParserCursor cursor = new ParserCursor(0, text.length()); return parseAddress(raw, cursor, null); }