class EntityTagHeaderProvider implements HeaderDelegate<EntityTag> {

    public EntityTag fromString(String header) {


        if (header == null) {
            throw new IllegalArgumentException("ETag value can not be null");
        }

        if ("*".equals(header)) {
            return new EntityTag("*");
        }

        String tag = null;
        boolean weak = false;
        int i = header.indexOf(WEAK_PREFIX);
        if (i != -1) {
            weak = true;
            if (i + 2 < header.length()) {
                tag = header.substring(i + 2);
            } else {
                return new EntityTag("", weak);
            }
        }  else {
            tag = header;
        }
        if (tag.length() > 0 && !tag.startsWith("\"") && !tag.endsWith("\"")) {
            return new EntityTag(tag, weak);
        }
        if (tag.length() < 2 || !tag.startsWith("\"") || !tag.endsWith("\"")) {
            throw new IllegalArgumentException("Misformatted ETag : " + header);
        }
        tag = tag.length() == 2 ? "" : tag.substring(1, tag.length() - 1);
        return new EntityTag(tag, weak);
    }

}