public boolean accepts(MediaType item) { if ( ! accept(this.getType(), item.getType()) ) return false ; return accept(this.getSubType(), item.getSubType()) ; }
public static ContentType create(String string) { if ( string == null ) return null ; ContentType ct = new ContentType(MediaType.create(string)) ; return ct ; }
public boolean moreGroundedThan(MediaType item) { if ( isStar(item.getType()) && ! isStar(this.getType()) ) return true ; if ( isStar(item.getSubType()) && ! isStar(this.getSubType()) ) return true ; return false ; }
private void testMatch(String header, String offer, String result) { AcceptList list1 = new AcceptList(header) ; AcceptList list2 = new AcceptList(offer) ; MediaType matchItem = AcceptList.match(list1, list2) ; if ( result == null ) { assertNull("Match not null: from "+q(header)+" :: "+q(offer), matchItem) ; return ; } assertNotNull("Match is null: expected "+q(result), matchItem) ; assertEquals("Match different", result, matchItem.toHeaderString()) ; }
private static void handleHttpException(HttpException ex, boolean ignore404) { if ( ex.getResponseCode() == HttpSC.NOT_FOUND_404 && ignore404 ) return ; throw ex; }
/** * Create a list of accept items from the give MediaTypes. * @param acceptItems */ public static AcceptList create(MediaType... acceptItems) { AcceptList accepList = new AcceptList(); for ( MediaType mtype : acceptItems ) accepList.ranges.add(new MediaRange(mtype)); return accepList; }
public boolean grounded(MediaType item) { return ! isStar(item.getType()) && ! isStar(item.getSubType()) ; }
public static ContentType create(String ctString, String charset) { MediaType.ParsedMediaType x = MediaType.parse(ctString) ; x.params.put(charsetParamName, charset) ; return new ContentType(new MediaType(x)) ; }
public static TypedInputStream wrap(InputStream in) { //Sometimes this is used to intentional loose the content type (in tests). // if ( in instanceof TypedInputStream ) { // return (TypedInputStream)in; // } return new TypedInputStream(in); }
public MediaRange(String type, String subType, String charset) { super(type, subType, charset) ; set_q() ; }
@Override public int hashCode() { final int prime = 31 ; int result = 1 ; result = prime * result + ((mediaType == null) ? 0 : mediaType.hashCode()) ; return result ; }
@Override public String toString() { return mediaType.toString() ; } }
public boolean accepts(MediaType item) { if ( ! accept(this.getType(), item.getType()) ) return false ; return accept(this.getSubType(), item.getSubType()) ; }
public boolean moreGroundedThan(MediaType item) { if ( isStar(item.getType()) && ! isStar(this.getType()) ) return true ; if ( isStar(item.getSubType()) && ! isStar(this.getSubType()) ) return true ; return false ; }
public static ContentType create(String string) { if ( string == null ) return null ; ContentType ct = new ContentType(MediaType.create(string)) ; return ct ; }
public MediaRange(MediaType other) { super(other) ; set_q() ; }