Refine search
static MimeType calcExpectedMediaType(AnnotationSource primarySource, ModelBuilder builder ) { XmlMimeType xmt = primarySource.readAnnotation(XmlMimeType.class); if(xmt==null) return null; try { return new MimeType(xmt.value()); } catch (MimeTypeParseException e) { builder.reportError(new IllegalAnnotationException( Messages.ILLEGAL_MIME_TYPE.format(xmt.value(),e.getMessage()), xmt )); return null; } } }
/** * Set the primary type for this object to the given String. * * @param primary the primary MIME type * @exception MimeTypeParseException if the primary type * is not a valid token */ public void setPrimaryType(String primary) throws MimeTypeParseException { // check to see if primary is valid if (!isValidToken(primaryType)) throw new MimeTypeParseException("Primary type is invalid."); primaryType = primary.toLowerCase(Locale.ENGLISH); }
/** * The object implements the readExternal method to restore its * contents by calling the methods of DataInput for primitive * types and readObject for objects, strings and arrays. The * readExternal method must read the values in the same sequence * and with the same types as were written by writeExternal. * * @param in the ObjectInput object to read from * @exception ClassNotFoundException If the class for an object being * restored cannot be found. */ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { try { parse(in.readUTF()); } catch (MimeTypeParseException e) { throw new IOException(e.toString()); } }
public void setMimeType(String mimeType) { if (mimeType == null) { this.mimeType = null; } else { MimeType mt; try { mt = new MimeType(mimeType); } catch (MimeTypeParseException e) { throw new IllegalArgumentException(e.getMessage(), e); } this.mimeType = mt.getPrimaryType() + "/" + mt.getSubType(); } }
/** * * @param requireDocument boolean * @return Document * @throws CosmoDavException */ private Document getSafeRequestDocument(boolean requireDocument) throws CosmoDavException { try { if (StringUtils.isBlank(getContentType()) && requireDocument) { throw new BadRequestException("No Content-Type specified"); } MimeType mimeType = new MimeType(getContentType()); if (!(mimeType.match(APPLICATION_XML) || mimeType.match(TEXT_XML))) { throw new UnsupportedMediaTypeException( "Expected Content-Type " + APPLICATION_XML + " or " + TEXT_XML); } return getRequestDocument(); } catch (MimeTypeParseException e) { throw new UnsupportedMediaTypeException(e.getMessage()); } catch (IllegalArgumentException e) { throwBadRequestExceptionFrom(e); } catch (DavException e) { throwBadRequestExceptionFrom(e); } return null; }
private MimeType getMimeType(final String str) { try { return new MimeType(str); } catch (final MimeTypeParseException ex) { ex.printStackTrace(); } return null; }
throw new MimeTypeParseException( "Couldn't find the '=' that separates a " + "parameter name from its value."); throw new MimeTypeParseException( "Couldn't find a value for parameter named " + name); throw new MimeTypeParseException( "Encountered unterminated quoted parameter value."); throw new MimeTypeParseException( "Encountered unterminated quoted parameter value."); } else { throw new MimeTypeParseException( "Unexpected character encountered at index " + i); throw new MimeTypeParseException( "More characters encountered in input than expected.");
private static String parseToken(String tokenString) throws MimeTypeParseException { tokenString = tokenString.trim(); for (int i=0; i < tokenString.length(); i++) { char c = tokenString.charAt(i); if (isSpecial(c)) { throw new MimeTypeParseException("Special '" + c + "' not allowed in token"); } } return tokenString; } }
private void parseMimeType(String rawData) throws MimeTypeParseException { int index = rawData.indexOf('/'); if (index == -1) { throw new MimeTypeParseException("Expected '/'"); } setPrimaryType(rawData.substring(0, index)); int index2 = rawData.indexOf(';', index+1); if (index2 == -1) { setSubType(rawData.substring(index+1)); } else { setSubType(rawData.substring(index+1, index2)); parameterList.parse(rawData.substring(index2)); } }
/** * Similar to {@link #readMap(com.linkedin.r2.message.rest.RestMessage)}, but will throw an * {@link IOException} instead of a {@link RestLiInternalException} * * @throws IOException if the message entity cannot be parsed. */ public static DataMap readMapWithExceptions(final RestMessage message) throws IOException { try { return DataMapConverter.bytesToDataMap(message.getHeader(RestConstants.HEADER_CONTENT_TYPE), message.getEntity()); } catch (MimeTypeParseException e) { throw new RoutingException(e.getMessage(), HttpStatus.S_400_BAD_REQUEST.getCode(), e); } }
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { try { parseMimeType(in.readUTF()); } catch (MimeTypeParseException mtpex) { throw new IOException(mtpex.getMessage()); } }
public final boolean canOpen(final MimeType t) { for (final String s : type.split(":")) try { if (t.match(s)) { return true; } } catch (final MimeTypeParseException ex) { ex.printStackTrace(); } return false; }
MimeType mimeType = new MimeType(contentType); dataType.setMimeType(mimeType.getPrimaryType() + "/" + mimeType.getSubType()); String encoding = mimeType.getParameter(CHARSET_PARAM); logger.warn(format("%s when parsing Content-Type '%s': %s", e.getClass().getName(), value, e.getMessage())); logger.warn(format("Using defualt encoding: %s", encoding)); dataType.setEncoding(encoding);
/** * * @param requireDocument boolean * @return Document * @throws CosmoDavException */ private Document getSafeRequestDocument(boolean requireDocument) throws CosmoDavException { try { if (StringUtils.isBlank(getContentType()) && requireDocument) { throw new BadRequestException("No Content-Type specified"); } MimeType mimeType = new MimeType(getContentType()); if (!(mimeType.match(APPLICATION_XML) || mimeType.match(TEXT_XML))) { throw new UnsupportedMediaTypeException( "Expected Content-Type " + APPLICATION_XML + " or " + TEXT_XML); } return getRequestDocument(); } catch (MimeTypeParseException e) { throw new UnsupportedMediaTypeException(e.getMessage()); } catch (IllegalArgumentException e) { throwBadRequestExceptionFrom(e); } catch (DavException e) { throwBadRequestExceptionFrom(e); } return null; }
throw new MimeTypeParseException( "Couldn't find the '=' that separates a " + "parameter name from its value."); throw new MimeTypeParseException( "Couldn't find a value for parameter named " + name); throw new MimeTypeParseException( "Encountered unterminated quoted parameter value."); throw new MimeTypeParseException( "Encountered unterminated quoted parameter value."); } else { throw new MimeTypeParseException( "Unexpected character encountered at index " + i); throw new MimeTypeParseException( "More characters encountered in input than expected.");
private static String parseToken(String tokenString) throws MimeTypeParseException { tokenString = tokenString.trim(); for (int i=0; i < tokenString.length(); i++) { char c = tokenString.charAt(i); if (isSpecial(c)) { throw new MimeTypeParseException("Special '" + c + "' not allowed in token"); } } return tokenString; } }
private void parseMimeType(String rawData) throws MimeTypeParseException { int index = rawData.indexOf('/'); if (index == -1) { throw new MimeTypeParseException("Expected '/'"); } setPrimaryType(rawData.substring(0, index)); int index2 = rawData.indexOf(';', index+1); if (index2 == -1) { setSubType(rawData.substring(index+1)); } else { setSubType(rawData.substring(index+1, index2)); parameterList.parse(rawData.substring(index2)); } }
Messages.format(Messages.ERR_ILLEGAL_EXPECTED_MIME_TYPE,emt, e.getMessage()) );
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { try { parseMimeType(in.readUTF()); } catch (MimeTypeParseException mtpex) { throw new IOException(mtpex.getMessage()); } }
static MimeType calcExpectedMediaType(AnnotationSource primarySource, ModelBuilder builder ) { XmlMimeType xmt = primarySource.readAnnotation(XmlMimeType.class); if(xmt==null) return null; try { return new MimeType(xmt.value()); } catch (MimeTypeParseException e) { builder.reportError(new IllegalAnnotationException( Messages.ILLEGAL_MIME_TYPE.format(xmt.value(),e.getMessage()), xmt )); return null; } } }