List of usage examples for org.apache.commons.io FilenameUtils getExtension
public static String getExtension(String filename)
From source file:it.feio.android.omninotes.utils.BitmapHelper.java
/** * Retrieves a the bitmap relative to attachment based on mime type *//* w ww . ja v a2 s. c o m*/ public static Bitmap getBitmapFromAttachment(Context mContext, Attachment mAttachment, int width, int height) { Bitmap bmp = null; String path; mAttachment.getUri().getPath(); // Video if (Constants.MIME_TYPE_VIDEO.equals(mAttachment.getMime_type())) { // Tries to retrieve full path from ContentResolver if is a new video path = StorageHelper.getRealPathFromURI(mContext, mAttachment.getUri()); // .. or directly from local directory otherwise if (path == null) { path = FileHelper.getPath(mContext, mAttachment.getUri()); } bmp = ThumbnailUtils.createVideoThumbnail(path, Thumbnails.MINI_KIND); if (bmp == null) { return null; } else { bmp = BitmapUtils.createVideoThumbnail(mContext, bmp, width, height); } // Image } else if (Constants.MIME_TYPE_IMAGE.equals(mAttachment.getMime_type()) || Constants.MIME_TYPE_SKETCH.equals(mAttachment.getMime_type())) { try { bmp = BitmapUtils.getThumbnail(mContext, mAttachment.getUri(), width, height); } catch (NullPointerException e) { bmp = null; } // Audio } else if (Constants.MIME_TYPE_AUDIO.equals(mAttachment.getMime_type())) { bmp = ThumbnailUtils.extractThumbnail( BitmapUtils.decodeSampledBitmapFromResourceMemOpt( mContext.getResources().openRawResource(R.drawable.play), width, height), width, height); // File } else if (Constants.MIME_TYPE_FILES.equals(mAttachment.getMime_type())) { // vCard if (Constants.MIME_TYPE_CONTACT_EXT.equals(FilenameUtils.getExtension(mAttachment.getName()))) { bmp = ThumbnailUtils.extractThumbnail( BitmapUtils.decodeSampledBitmapFromResourceMemOpt( mContext.getResources().openRawResource(R.drawable.vcard), width, height), width, height); } else { bmp = ThumbnailUtils.extractThumbnail( BitmapUtils.decodeSampledBitmapFromResourceMemOpt( mContext.getResources().openRawResource(R.drawable.files), width, height), width, height); } } return bmp; }
From source file:com.iyonger.apm.web.model.FileType.java
/** * Get file type by extension of given name. * //from w w w . ja v a 2s . co m * @param name name of file. * @return FileType which matches to extension. UNKNOWN otherwise. */ public static FileType getFileTypeByName(String name) { return getFileTypeByExtension(FilenameUtils.getExtension(name)); }
From source file:com.yahoo.flowetl.services.factory.ServiceFactory.java
/** * Parses the config file and returns a configuration object for it. It * attempts to look at the extension of the file and then create the * corresponding apache commons configuration reader for that file type. * Currently this is supporting a .xml file and a .properties file. * //from w ww .j a va2s .co m * @param configFileName * * @return the configuration * * @throws ConfigurationException */ protected Configuration parseConfigFile(String configFileName) throws ConfigurationException { if (configFileName == null) { return null; } Configuration out = null; String ext = FilenameUtils.getExtension(configFileName); if (StringUtils.equalsIgnoreCase("xml", ext)) { out = new XMLConfiguration(configFileName); } else if (StringUtils.equalsIgnoreCase("properties", ext)) { out = new PropertiesConfiguration(configFileName); } return out; }
From source file:ch.cyberduck.core.transfer.upload.RenameFilter.java
@Override public TransferStatus prepare(final Path file, final Local local, final TransferStatus parent, final ProgressListener progress) throws BackgroundException { final TransferStatus status = super.prepare(file, local, parent, progress); if (status.isExists()) { final String filename = file.getName(); int no = 0; do {/* w w w. jav a 2 s .c o m*/ String proposal = String.format("%s-%d", FilenameUtils.getBaseName(filename), ++no); if (StringUtils.isNotBlank(FilenameUtils.getExtension(filename))) { proposal += String.format(".%s", FilenameUtils.getExtension(filename)); } if (parent.getRename().remote != null) { status.rename(new Path(parent.getRename().remote, proposal, file.getType())); } else { status.rename(new Path(file.getParent(), proposal, file.getType())); } } while (find.find(status.getRename().remote)); if (log.isInfoEnabled()) { log.info(String.format("Changed upload target from %s to %s", file, status.getRename().remote)); } if (log.isDebugEnabled()) { log.debug(String.format("Clear exist flag for file %s", file)); } status.setExists(false); } else { if (parent.getRename().remote != null) { status.rename(new Path(parent.getRename().remote, file.getName(), file.getType())); } if (log.isInfoEnabled()) { log.info(String.format("Changed upload target from %s to %s", file, status.getRename().remote)); } } return status; }
From source file:mx.eersya.beans.CreateItemBean.java
public void savePicture() { try {/*from w w w.j av a 2 s . com*/ Path path = Paths.get("/home/eersya/Projects/W/"); String filename = FilenameUtils.getBaseName(picture.getFileName()); String extension = FilenameUtils.getExtension(picture.getFileName()); Path file = Files.createTempFile(path, filename, "." + extension); picturePath = file.toString(); try (InputStream in = picture.getInputstream()) { Files.copy(in, file, StandardCopyOption.REPLACE_EXISTING); } catch (IOException exa) { System.err.println(exa); } picturePath = file.toString(); System.out.println("Picture:" + picturePath); } catch (IOException ex) { System.err.println(ex); } }
From source file:cn.tst.sbjxzzglxt.MoKuai.SheBeiGuanLi.WenDangJiTuPianGuanLi.WenDangJiTuPianGuanLiBizLogicImpl.java
private void uploadFile(ViewModel vm) { String fileUploadPath = Controller.FILE_UPLOAD_PATH; UploadedFile file = vm.getCurrentUploadedFile(); final String EXTENSION_NAME = FilenameUtils.getExtension(file.getFileName()); final String FILE_NAME_ON_SERVER = UUID.randomUUID().toString().concat(CConst.DOT).concat(EXTENSION_NAME); try {/*from ww w .java 2 s. c om*/ Path originFilePath = Paths.get(fileUploadPath, SepC.UploadFileType.ORIGIN, FILE_NAME_ON_SERVER); Path compressedFilePath = Paths.get(fileUploadPath, SepC.UploadFileType.COMPRESSION, FILE_NAME_ON_SERVER); Path previewFilePath = Paths.get(fileUploadPath, SepC.UploadFileType.PREVIEW, FILE_NAME_ON_SERVER); Thumbnails.of(file.getInputstream()).scale(1, 1).toFile(new File(originFilePath.toString())); Thumbnails.of(file.getInputstream()).size(400, 320).toFile(new File(compressedFilePath.toString())); Thumbnails.of(file.getInputstream()).size(85, 100).toFile(new File(previewFilePath.toString())); } catch (IOException ex) { } vm.getEquipmentDocumentInEdit().setFOriginalName(file.getFileName()); vm.getEquipmentDocumentInEdit().setFNameOnServer(FILE_NAME_ON_SERVER); // List<LTEquipGraphic> list = equipmentGraphicFacade.findByOriginalName(file.getFileName()); // vm.getEquipmentDocumentInEdit().setFVer(list.toArray().length + 1); }
From source file:edu.scripps.fl.pubchem.app.cids.WriteSDFStage.java
public File newOutputFile(int index) { String outputFile = getOutputFile(); outputFile = new File(outputFile).getAbsoluteFile().toString(); String path = FilenameUtils.getFullPath(outputFile); String name = FilenameUtils.getBaseName(outputFile); String ext = FilenameUtils.getExtension(outputFile); File file = new File(path, name + "-" + index + "." + ext); return file;/*w ww . j a v a 2 s. co m*/ }
From source file:annis.administration.BinaryImportHelper.java
public BinaryImportHelper(File f, File dataDir, String toplevelCorpusName, long corpusRef, Map<String, String> mimeTypeMapping) { this.fileSource = f; // create a file-name in the form of "filename_toplevelcorpus_UUID.ending", thus we // need to split the file name into its components String baseName = FilenameUtils.getBaseName(fileSource.getName()); String extension = FilenameUtils.getExtension(fileSource.getName()); UUID uuid = UUID.randomUUID(); String outputName = ""; if (toplevelCorpusName == null) { outputName = baseName + "_" + uuid.toString() + (extension.isEmpty() ? "" : "." + extension); } else {/*from ww w .jav a2 s . c o m*/ outputName = baseName + "_" + CommonHelper.getSafeFileName(toplevelCorpusName) + "_" + uuid.toString() + (extension.isEmpty() ? "" : "." + extension); } fileDestination = new File(dataDir, outputName); String fileEnding = FilenameUtils.getExtension(f.getName()); if (mimeTypeMapping.containsKey(fileEnding)) { this.mimeType = mimeTypeMapping.get(fileEnding); } else { this.mimeType = new MimetypesFileTypeMap().getContentType(fileSource); } this.corpusRef = corpusRef; }
From source file:com.haulmont.cuba.web.app.ui.frame.FileFrameController.java
@Override public void init(Map<String, Object> params) { super.init(params); uploadField = (FileUploadField) getComponent("uploadField"); filesTable = (Table) getComponent("files"); initGeneratedColumn();//from w w w.j a v a 2 s . c o m ds = (CollectionDatasource) getDsContext().get("filesDs"); Button remove = (Button) getComponentNN("remove"); remove.setAction(new RemoveAction(filesTable, false)); uploadField.addFileUploadSucceedListener(e -> { fd = metadata.create(FileDescriptor.class); fd.setName(uploadField.getFileName()); fd.setExtension(FilenameUtils.getExtension(uploadField.getFileName())); FileUploadingAPI fileUploading = AppBeans.get(FileUploadingAPI.NAME); File file = fileUploading.getFile(uploadField.getFileId()); fd.setSize(file.length()); fd.setCreateDate(AppBeans.get(TimeSource.class).currentTimestamp()); saveFile(); ds.addItem(fd); showNotification(getMessage("uploadSuccess"), NotificationType.HUMANIZED); }); uploadField.addFileUploadErrorListener( e -> showNotification(getMessage("uploadUnsuccess"), NotificationType.HUMANIZED)); }
From source file:com.dycody.android.idealnote.utils.BitmapHelper.java
/** * Retrieves a the bitmap relative to attachment based on mime type *///from w w w .jav a 2 s . com public static Bitmap getBitmapFromAttachment(Context mContext, Attachment mAttachment, int width, int height) { Bitmap bmp = null; String path; mAttachment.getUri().getPath(); // Video if (Constants.MIME_TYPE_VIDEO.equals(mAttachment.getMime_type())) { // Tries to retrieve full path from ContentResolver if is a new video path = StorageHelper.getRealPathFromURI(mContext, mAttachment.getUri()); // .. or directly from local directory otherwise if (path == null) { path = FileHelper.getPath(mContext, mAttachment.getUri()); } bmp = ThumbnailUtils.createVideoThumbnail(path, Thumbnails.MINI_KIND); if (bmp == null) { return null; } else { bmp = BitmapUtils.createVideoThumbnail(mContext, bmp, width, height); } // Image } else if (Constants.MIME_TYPE_IMAGE.equals(mAttachment.getMime_type()) || Constants.MIME_TYPE_SKETCH.equals(mAttachment.getMime_type())) { try { bmp = BitmapUtils.getThumbnail(mContext, mAttachment.getUri(), width, height); } catch (NullPointerException e) { bmp = null; } // Audio } else if (Constants.MIME_TYPE_AUDIO.equals(mAttachment.getMime_type())) { bmp = ThumbnailUtils .extractThumbnail( BitmapUtils.decodeSampledBitmapFromResourceMemOpt(mContext.getResources() .openRawResource(com.dycody.android.idealnote.R.raw.play), width, height), width, height); // File } else if (Constants.MIME_TYPE_FILES.equals(mAttachment.getMime_type())) { // vCard if (Constants.MIME_TYPE_CONTACT_EXT.equals(FilenameUtils.getExtension(mAttachment.getName()))) { bmp = ThumbnailUtils .extractThumbnail( BitmapUtils.decodeSampledBitmapFromResourceMemOpt(mContext.getResources() .openRawResource(com.dycody.android.idealnote.R.raw.vcard), width, height), width, height); } else { bmp = ThumbnailUtils .extractThumbnail( BitmapUtils.decodeSampledBitmapFromResourceMemOpt(mContext.getResources() .openRawResource(com.dycody.android.idealnote.R.raw.files), width, height), width, height); } } return bmp; }