Search in sources :

Example 1 with Event

use of org.glassfish.jersey.message.internal.HttpHeaderReader.Event in project jersey by jersey.

the class EntityTagProvider method fromString.

@Override
public EntityTag fromString(String header) {
    throwIllegalArgumentExceptionIfNull(header, LocalizationMessages.ENTITY_TAG_IS_NULL());
    try {
        HttpHeaderReader reader = HttpHeaderReader.newInstance(header);
        Event e = reader.next(false);
        if (e == Event.QuotedString) {
            return new EntityTag(reader.getEventValue().toString());
        } else if (e == Event.Token) {
            final CharSequence ev = reader.getEventValue();
            if (ev != null && ev.length() > 0 && ev.charAt(0) == 'W') {
                reader.nextSeparator('/');
                return new EntityTag(reader.nextQuotedString().toString(), true);
            }
        }
    } catch (ParseException ex) {
        throw new IllegalArgumentException("Error parsing entity tag '" + header + "'", ex);
    }
    throw new IllegalArgumentException("Error parsing entity tag '" + header + "'");
}
Also used : Event(org.glassfish.jersey.message.internal.HttpHeaderReader.Event) EntityTag(javax.ws.rs.core.EntityTag) ParseException(java.text.ParseException)

Aggregations

ParseException (java.text.ParseException)1 EntityTag (javax.ws.rs.core.EntityTag)1 Event (org.glassfish.jersey.message.internal.HttpHeaderReader.Event)1