public MimeTypeWithSource (@Nonnull final String sMimeType) { this (MimeTypeParser.parseMimeType (sMimeType), (String) null); }
@Nullable public static IMimeType safeParseMimeType (@Nullable final String sMimeType) { try { return MimeTypeParser.parseMimeType (sMimeType); } catch (final MimeTypeParserException ex) { if ("*".equals (sMimeType)) return new MimeType (EMimeContentType._STAR, "*"); } if (LOGGER.isWarnEnabled ()) LOGGER.warn ("Unparsable MIME type '" + sMimeType + "'"); return null; } }
public void setContentType (@Nullable final String sContentType) { m_sContentType = sContentType; if (sContentType != null) { try { final IMimeType aContentType = MimeTypeParser.parseMimeType (sContentType); final String sEncoding = MimeTypeHelper.getCharsetNameFromMimeType (aContentType); if (sEncoding != null) setCharacterEncoding (sEncoding); } catch (final MimeTypeParserException ex) { LOGGER.warn ("Passed content type '" + sContentType + "' cannot be parsed as a MIME type"); } } }
public static IMimeType detectMime (final String sFilename) throws IOException { // Use Files to find content type String sMimeType = Files.probeContentType (Paths.get (sFilename)); // Use URLConnection to find content type if (sMimeType == null) { LOG.info ("Unable to determine MIME type of '" + sFilename + "' using Files.probeContentType(), trying URLConnection.getFileNameMap()"); sMimeType = URLConnection.getFileNameMap ().getContentTypeFor (sFilename); } // Throw exception if content type is not detected if (sMimeType == null) throw new IllegalStateException ("Unable to determine MIME type of " + sFilename); return MimeTypeParser.parseMimeType (sMimeType); }
@Nonnull public final UnifiedResponse setMimeTypeString (@Nonnull @Nonempty final String sMimeType) { ValueEnforcer.notEmpty (sMimeType, "MimeType"); final IMimeType aMimeType = MimeTypeParser.parseMimeType (sMimeType); if (aMimeType != null) setMimeType (aMimeType); else logError ("Failed to resolve mime type from '" + sMimeType + "'"); return this; }
@Nonnull public PModePayloadProfile convertToNative (final IMicroElement aElement) { final String sName = aElement.getAttributeValue (ATTR_NAME); final IMimeType aMimeType = MimeTypeParser.parseMimeType (aElement.getAttributeValue (ATTR_MIME_TYPE)); final String sXSDFilename = aElement.getAttributeValue (ATTR_XSD_FILENAME); final Integer aMaxSizeKB = aElement.getAttributeValueWithConversion (ATTR_MAX_SIZE_KB, Integer.class); final EMandatory eMandatory = EMandatory.valueOf (aElement.getAttributeValueAsBool (ATTR_MANDATORY, PModePayloadProfile.DEFAULT_MANDATORY)); return new PModePayloadProfile (sName, aMimeType, sXSDFilename, aMaxSizeKB, eMandatory); } }
throw new BadRequestException ("Content-Type header is missing"); final MimeType aContentType = MimeTypeParser.parseMimeType (sContentType); if (isDebug ()) LOGGER.info ("Received Content-Type: " + aContentType); final IMimeType aPlainPartMT = MimeTypeParser.parseMimeType (aBodyPart.getContentType ()) .getCopyWithoutParameters ();
for (final IMicroElement eMimeType : aElement.getAllChildElements (ELEMENT_MIMETYPE)) final MimeType aMimeType = MimeTypeParser.parseMimeType (eMimeType.getTextContentTrimmed ()); final String sSource = eMimeType.getAttributeValue (ATTR_SOURCE); aMimeTypes.add (new MimeTypeWithSource (aMimeType, sSource));