/** * Parses the given byte sequence and returns an instance of the {@link ParsedField} class. * The type of the class returned depends on the field name; see {@link #parse(String)} for * a table of field names and their corresponding classes. * * @param raw the bytes to parse. * @param monitor decoding monitor used while parsing/decoding. * @return a parsed field. * @throws MimeException if the raw string cannot be split into field name and body. */ public static ParsedField parse( final ByteSequence raw, final DecodeMonitor monitor) throws MimeException { Field rawField = RawFieldParser.DEFAULT.parseField(raw); return PARSER.parse(rawField, monitor); }
/** * Parses the given byte sequence and returns an instance of the {@link ParsedField} class. * The type of the class returned depends on the field name; see {@link #parse(String)} for * a table of field names and their corresponding classes. * * @param raw the bytes to parse. * @param monitor decoding monitor used while parsing/decoding. * @return a parsed field. * @throws MimeException if the raw string cannot be split into field name and body. */ public static ParsedField parse( final ByteSequence raw, final DecodeMonitor monitor) throws MimeException { Field rawField = RawFieldParser.DEFAULT.parseField(raw); return PARSER.parse(rawField, monitor); }
/** * Parses the given string and returns an instance of the <code>Field</code> class. * The type of the class returned depends on the field name. * * @param rawStr the string to parse. * @param monitor a DecodeMonitor object used while parsing/decoding. * @return a <code>ParsedField</code> instance. * @throws MimeException if the raw string cannot be split into field name and body. */ public static ParsedField parse( final String rawStr, final DecodeMonitor monitor) throws MimeException { ByteSequence raw = ContentUtil.encode(rawStr); RawField rawField = RawFieldParser.DEFAULT.parseField(raw); // Do not retain the original raw representation as the field // may require folding return PARSER.parse(rawField, monitor); }
final DecodeMonitor monitor) throws MimeException { ByteSequence raw = ContentUtil.encode(rawStr); RawField rawField = RawFieldParser.DEFAULT.parseField(raw);
public RawField build() throws MimeException { int len = this.buf.length(); if (len > 0) { if (this.buf.byteAt(len - 1) == '\n') { len --; } if (this.buf.byteAt(len - 1) == '\r') { len --; } } ByteArrayBuffer copy = new ByteArrayBuffer(this.buf.buffer(), len, false); RawField field = RawFieldParser.DEFAULT.parseField(copy); String name = field.getName(); for (int i = 0; i < name.length(); i++) { char ch = name.charAt(i); if (!FIELD_CHARS.get(ch)) { throw new MimeException("MIME field name contains illegal characters: " + field.getName()); } } return field; }