/** * Determines the mimetype of a file by looking up the file's extension in an internal listing * to find the corresponding mime type. If the file has no extension, or the extension is not * available in the listing contained in this class, the default mimetype * <code>application/octet-stream</code> is returned. * <p> * A file extension is one or more characters that occur after the last period (.) in the file's name. * If a file has no extension, * Guesses the mimetype of file data based on the file's extension. * * @param file * the file whose extension may match a known mimetype. * * @return * the file's mimetype based on its extension, or a default value of * <code>application/octet-stream</code> if a mime type value cannot be found. */ public String getMimetype(File file) { return getMimetype(file.getName()); }
/** * Loads mime type settings from the file 'mime.types' in the classpath, if it's available. */ public static synchronized Mimetypes getInstance() { if (mimetypes != null) { return mimetypes; } mimetypes = new Mimetypes(); InputStream mimetypesFile = mimetypes.getClass().getResourceAsStream("/mime.types"); if (mimetypesFile != null) { if (log.isDebugEnabled()) { log.debug("Loading mime types from file in the classpath: mime.types"); } try { mimetypes.loadAndReplaceMimetypes(mimetypesFile); } catch (IOException e) { if (log.isErrorEnabled()) { log.error("Failed to load mime types from file in the classpath: mime.types", e); } } } else { if (log.isWarnEnabled()) { log.warn("Unable to find 'mime.types' file in classpath"); } } return mimetypes; }
/** * Create an object representing a file. The object is initialised with the file's name * as its key, the file's content as its data, a content type based on the file's extension * (see {@link Mimetypes}), and a content length matching the file's size. * The file's MD5 hash value is also calculated and provided to the destination service, * so the service can verify that no data are corrupted in transit. * <p> * <b>NOTE:</b> The automatic calculation of a file's MD5 hash digest as performed by * this constructor could take some time for large files, or for many small ones. * * @param file * the file the object will represent. This file must exist and be readable. * * @throws IOException when an i/o error occurred reading the file * @throws NoSuchAlgorithmException when this JRE doesn't support the MD5 hash algorithm */ public StorageObject(File file) throws NoSuchAlgorithmException, IOException { this(file.getName()); setContentLength(file.length()); setContentType(Mimetypes.getInstance().getMimetype(file)); if (!file.exists()) { throw new FileNotFoundException("Cannot read from file: " + file.getAbsolutePath()); } setDataInputFile(file); setMd5Hash(ServiceUtils.computeMD5Hash(new FileInputStream(file))); }
if (mimeTypesFile.exists()) { try { Mimetypes.getInstance().loadAndReplaceMimetypes( new FileInputStream(mimeTypesFile)); } catch (IOException e) {
/** * Create an object representing a file. The object is initialised with the file's name * as its key, the file's content as its data, a content type based on the file's extension * (see {@link Mimetypes}), and a content length matching the file's size. * The file's MD5 hash value is also calculated and provided to the destination service, * so the service can verify that no data are corrupted in transit. * <p> * <b>NOTE:</b> The automatic calculation of a file's MD5 hash digest as performed by * this constructor could take some time for large files, or for many small ones. * * @param file * the file the object will represent. This file must exist and be readable. * * @throws IOException when an i/o error occurred reading the file * @throws NoSuchAlgorithmException when this JRE doesn't support the MD5 hash algorithm */ public StorageObject(File file) throws NoSuchAlgorithmException, IOException { this(file.getName()); setContentLength(file.length()); setContentType(Mimetypes.getInstance().getMimetype(file)); if (!file.exists()) { throw new FileNotFoundException("Cannot read from file: " + file.getAbsolutePath()); } setDataInputFile(file); setMd5Hash(ServiceUtils.computeMD5Hash(new FileInputStream(file))); }
if (mimeTypesFile.exists()) { try { Mimetypes.getInstance().loadAndReplaceMimetypes( new FileInputStream(mimeTypesFile)); } catch (IOException e) {
s3Object.setContentType(Mimetypes.MIMETYPE_BINARY_OCTET_STREAM); } else { s3Object.setContentType(Mimetypes.getInstance().getMimetype(dataFile)); File uploadFile = transformUploadFile(dataFile, s3Object, encryptionUtil, gzipFile, progressWatcher);
/** * Loads mime type settings from the file 'mime.types' in the classpath, if it's available. */ public static synchronized Mimetypes getInstance() { if (mimetypes != null) { return mimetypes; } mimetypes = new Mimetypes(); InputStream mimetypesFile = mimetypes.getClass().getResourceAsStream("/mime.types"); if (mimetypesFile != null) { if (log.isDebugEnabled()) { log.debug("Loading mime types from file in the classpath: mime.types"); } try { mimetypes.loadAndReplaceMimetypes(mimetypesFile); } catch (IOException e) { if (log.isErrorEnabled()) { log.error("Failed to load mime types from file in the classpath: mime.types", e); } } } else { if (log.isWarnEnabled()) { log.warn("Unable to find 'mime.types' file in classpath"); } } return mimetypes; }
/** * Determines the mimetype of a file by looking up the file's extension in an internal listing * to find the corresponding mime type. If the file has no extension, or the extension is not * available in the listing contained in this class, the default mimetype * <code>application/octet-stream</code> is returned. * <p> * A file extension is one or more characters that occur after the last period (.) in the file's name. * If a file has no extension, * Guesses the mimetype of file data based on the file's extension. * * @param file * the file whose extension may match a known mimetype. * * @return * the file's mimetype based on its extension, or a default value of * <code>application/octet-stream</code> if a mime type value cannot be found. */ public String getMimetype(File file) { return getMimetype(file.getName()); }
s3Object.setContentType(Mimetypes.MIMETYPE_BINARY_OCTET_STREAM); } else { s3Object.setContentType(Mimetypes.getInstance().getMimetype(dataFile)); File uploadFile = transformUploadFile(dataFile, s3Object, encryptionUtil, gzipFile, progressWatcher);
@Override public String getMime(final String filename) { if(StringUtils.startsWith(filename, "._")) { return DEFAULT_CONTENT_TYPE; } // Reads from mime.types in classpath return types.getMimetype(StringUtils.lowerCase(filename)); } }