public FileContentInfo create()

in commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeFileContentInfoFactory.java [34:78]


    public FileContentInfo create(final FileContent fileContent) throws FileSystemException {
        final MimeFileObject mimeFile = (MimeFileObject) fileContent.getFile();
        final Part part = mimeFile.getPart();

        String contentTypeString = null;
        String charset = null;

        try {
            // special handling for multipart
            if (mimeFile.isMultipart()) {
                // get the original content type, but ...
                contentTypeString = part.getContentType();

                // .... we deliver the preamble instead of an inupt string
                // the preamble will be delivered in UTF-8 - fixed
                charset = MimeFileSystem.PREAMBLE_CHARSET;
            }
        } catch (final MessagingException e) {
            throw new FileSystemException(e);
        }

        if (contentTypeString == null) {
            // normal message ... get the content type
            try {
                contentTypeString = part.getContentType();
            } catch (final MessagingException e) {
                throw new FileSystemException(e);
            }
        }

        ContentType contentType;
        try {
            contentType = new ContentType(contentTypeString);
        } catch (final MessagingException e) {
            throw new FileSystemException(e);
        }

        if (charset == null) {
            // charset might already be set by the multipart message stuff, else
            // extract it from the contentType now
            charset = contentType.getParameter("charset"); // NON-NLS
        }

        return new DefaultFileContentInfo(contentType.getBaseType(), charset);
    }