/** * Construct an SObject with key and file specified * * @see #of(String, File, Map) */ public static SObject of(String key, File file) { if (file.canRead() && file.isFile()) { SObject sobj = new FileSObject(key, file); String fileName = file.getName(); sobj.setAttribute(ATTR_FILE_NAME, file.getName()); String fileExtension = S.fileExtension(fileName); MimeType mimeType = MimeType.findByFileExtension(fileExtension); String type = null != mimeType ? mimeType.type() : null; sobj.setAttribute(ATTR_CONTENT_TYPE, type); sobj.setAttribute(ATTR_CONTENT_LENGTH, S.string(file.length())); return sobj; } else { return getInvalidObject(key, new IOException("File is a directory or not readable")); } }
/** * Construct an SObject with key and file specified * * @see #of(String, File, Map) */ public static SObject of(String key, File file) { if (file.canRead() && file.isFile()) { SObject sobj = new FileSObject(key, file); String fileName = file.getName(); sobj.setAttribute(ATTR_FILE_NAME, file.getName()); String fileExtension = S.fileExtension(fileName); MimeType mimeType = MimeType.findByFileExtension(fileExtension); String type = null != mimeType ? mimeType.type() : null; sobj.setAttribute(ATTR_CONTENT_TYPE, type); sobj.setAttribute(ATTR_CONTENT_LENGTH, S.string(file.length())); return sobj; } else { return getInvalidObject(key, new IOException("File is a directory or not readable")); } }