Refine search
/** * Determine if the primary and sub type of this object is * the same as the content type described in rawdata. * * @param rawdata the MIME type string to compare with * @return true if they match */ public boolean match(String rawdata) throws MimeTypeParseException { return match(new MimeType(rawdata)); }
/** * The object implements the writeExternal method to save its contents * by calling the methods of DataOutput for its primitive values or * calling the writeObject method of ObjectOutput for objects, strings * and arrays. * * @param out the ObjectOutput object to write to * @exception IOException Includes any I/O exceptions that may occur */ public void writeExternal(ObjectOutput out) throws IOException { out.writeUTF(toString()); out.flush(); }
/** * Determine if the primary and sub type of this object is * the same as what is in the given type. * * @param type the MimeType object to compare with * @return true if they match */ public boolean match(MimeType type) { return primaryType.equals(type.getPrimaryType()) && (subType.equals("*") || type.getSubType().equals("*") || (subType.equals(type.getSubType()))); }
public DataSourceSource(DataSource source) throws MimeTypeParseException { this.source = source; String ct = source.getContentType(); if(ct==null) { charset = null; } else { MimeType mimeType = new MimeType(ct); this.charset = mimeType.getParameter("charset"); } }
@Override public String getContentType(File filename) { if (!filename.exists()) { return null; } try { final MimeType type = getMimeType(filename.toURI().toURL()); if (type != null) { return type.toString(); } } catch (Exception e) { // } final FileTypeMap lparent = this.parent.get(); if (lparent != null) { return lparent.getContentType(filename); } return MimeName.MIME_OCTET_STREAM.getMimeConstant(); }
/** Replies if the given file has the given MIME type. * * @param filename is the filename of the file to read. * @param mimeType is the restriction type. * @return <code>true</code> if the file has the given MIME type, * otherwise <code>false</code> */ public boolean isContentType(File filename, String mimeType) { assert filename != null : AssertMessages.notNullParameter(0); assert mimeType != null && !mimeType.isEmpty() : AssertMessages.notNullParameter(1); if (!filename.exists()) { return false; } try { final MimeType mtype = new MimeType(mimeType); if (isMimeType(filename.toURI().toURL(), mtype)) { return true; } } catch (Exception e) { // silently ignore errors } final FileTypeMap lparent = this.parent.get(); if (lparent != null) { final String mime = lparent.getContentType(filename); return mimeType.equalsIgnoreCase(mime); } return false; }
String path = exchange.getRequestURI().getPath(); String requestQueryRaw = exchange.getRequestURI().getRawQuery(); if (requestQueryRaw != null) { StringTokenizer stk = new StringTokenizer(requestQueryRaw, AND_DELIMITER); MimeType mimeType = new MimeType(headers.getFirst("Content-Type")); String baseType = mimeType.getBaseType(); String charset = mimeType.getParameter("charset"); if (charset != null && !charset.equals(CHARSET)) { throw new IllegalArgumentException("Illegal Content-Type charset. Only UTF-8 is supported"); String requestQueryRaw = exchange.getRequestURI().getRawQuery(); if (requestQueryRaw != null) { StringTokenizer stk = new StringTokenizer(requestQueryRaw, AND_DELIMITER);
public static VariableValueDto fromFormPart(String type, FormPart binaryDataFormPart) { VariableValueDto dto = new VariableValueDto(); dto.type = type; dto.value = binaryDataFormPart.getBinaryContent(); if (ValueType.FILE.getName().equals(fromRestApiTypeName(type))) { String contentType = binaryDataFormPart.getContentType(); if (contentType == null) { contentType = MediaType.APPLICATION_OCTET_STREAM; } dto.valueInfo = new HashMap<String, Object>(); dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_NAME, binaryDataFormPart.getFileName()); MimeType mimeType = null; try { mimeType = new MimeType(contentType); } catch (MimeTypeParseException e) { throw new RestException(Status.BAD_REQUEST, "Invalid mime type given"); } dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_MIME_TYPE, mimeType.getBaseType()); String encoding = mimeType.getParameter("encoding"); if (encoding != null) { dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_ENCODING, encoding); } String transientString = mimeType.getParameter("transient"); boolean isTransient = Boolean.parseBoolean(transientString); if (isTransient) { dto.valueInfo.put(AbstractValueTypeImpl.VALUE_INFO_TRANSIENT, isTransient); } } return dto; }
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(); } }
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; } } }
/** * * @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; }
/** * Use the MimeType class to extract the MIME type/subtype, * ignoring the parameters. The type is cached. */ private synchronized String getBaseType() { if (shortType == null) { String ct = getContentType(); try { MimeType mt = new MimeType(ct); shortType = mt.getBaseType(); } catch (MimeTypeParseException e) { shortType = ct; } } return shortType; }
@Override public String visitMemoryResource(final MemoryResourceReference memoryResourceReference) throws RuntimeException { try { final String mimeType = memoryResourceReference.getContentType(); if (mimeType == null) { return null; } return new MimeType(mimeType).getSubType(); } catch (final MimeTypeParseException exception) { return null; } }
private MimeType getMimeType(final String str) { try { return new MimeType(str); } catch (final MimeTypeParseException ex) { ex.printStackTrace(); } return null; }
/** * Return the String representation of this object. */ public String toString() { return getBaseType() + parameters.toString(); }
/** * Compare two media types according to their relative level of specificity */ public static int compare(MimeType mt1, MimeType mt2) { String st1 = mt1.getSubType(); String st2 = mt2.getSubType(); if (MimeTypeHelper.isMatch(mt1, mt2)) { if (st1.equals("*")) return -1; if (st2.equals("*")) return 1; } return 0; }
public static String getCharset( final MimeType type, String defaultCharset ) { String charset = null; if( type != null ) { charset = type.getParameter( CHARSET_PARAMETER_NAME ); } if( charset == null ) { charset = defaultCharset; } return charset; }