List of usage examples for org.apache.commons.io FilenameUtils getExtension
public static String getExtension(String filename)
From source file:com.splunk.shuttl.archiver.importexport.BucketExportControllerIntegrationTest.java
private void exportingBucketWithRealDataToCsvCreatesCsvBucket() { LocalBucket realBucket = TUtilsBucket.createRealBucket(); LocalBucket csvBucket = bucketExportController.exportBucket(realBucket, BucketFormat.CSV); assertEquals(realBucket.getName(), csvBucket.getName()); assertEquals(BucketFormat.CSV, csvBucket.getFormat()); assertEquals(1, csvBucket.getDirectory().listFiles().length); File csvFile = csvBucket.getDirectory().listFiles()[0]; assertEquals("csv", FilenameUtils.getExtension(csvFile.getName())); long csvFileSize = csvFile.length(); assertTrue(0 < csvFileSize);// ww w. j a v a 2 s .co m }
From source file:de.tudarmstadt.ukp.dkpro.core.api.resources.ResourceUtilsTest.java
@Test public void testWithSpace() throws Exception { File dir = workspace.newFolder("this is a test"); File file = new File(dir, "this is a file name.extension with spaces"); System.out.println("Original: " + file); System.out.println("Original (URL): " + file.toURI().toURL()); File asFile = ResourceUtils.getUrlAsFile(file.toURI().toURL(), false); System.out.println("As file: " + asFile.getPath()); assertEquals("this is a file name", FilenameUtils.getBaseName(asFile.getPath())); assertEquals("extension with spaces", FilenameUtils.getExtension(asFile.getPath())); }
From source file:fr.inria.soctrace.tools.importer.otf2.Otf2Importer.java
private String getNewTraceDBName(String traceFile) { String basename = FilenameUtils.getBaseName(traceFile); String extension = FilenameUtils.getExtension(traceFile); if (extension.equals(Otf2Constants.TRACE_EXT)) { basename = basename.replace(Otf2Constants.TRACE_EXT, ""); }//from w ww .j av a 2 s. c om return FramesocManager.getInstance().getTraceDBName(basename); }
From source file:jp.co.opentone.bsol.linkbinder.dto.Attachment.java
/** * ????.//ww w .jav a 2 s . c om * @param fileName ?? * @return */ public static AttachmentFileType detectFileTypeByFileName(String fileName) { if (StringUtils.isEmpty(fileName)) { return AttachmentFileType.UNKNOWN; } String extension = FilenameUtils.getExtension(fileName); if (StringUtils.isEmpty(extension)) { return AttachmentFileType.UNKNOWN; } return ArrayUtils.contains(IMAGE_EXTENSIONS, extension.toLowerCase()) ? AttachmentFileType.IMAGE : AttachmentFileType.UNKNOWN; }
From source file:com.bt.download.android.gui.transfers.YouTubeDownload.java
private static File buildFile(File savePath, String name) { String baseName = FilenameUtils.getBaseName(name); String ext = FilenameUtils.getExtension(name); File f = new File(savePath, name); int i = 1;/* w w w .ja va 2s .c o m*/ while (f.exists() && i < Integer.MAX_VALUE) { f = new File(savePath, baseName + " (" + i + ")." + ext); i++; } return f; }
From source file:com.opensearchserver.extractor.test.AllTest.java
protected File getTempFile(String fileName) throws IOException { File tempFile = File.createTempFile("oss_extractor", "." + FilenameUtils.getExtension(fileName)); FileOutputStream fos = new FileOutputStream(tempFile); InputStream inputStream = getStream(fileName); IOUtils.copy(inputStream, fos);/*from w w w . j av a2s. c o m*/ return tempFile; }
From source file:com.jaspersoft.studio.server.dnd.RepositoryDNDHelper.java
public static void performDropOperation(final MResource targetParentResource, final String fullFilename) { final File file = new File(fullFilename); final String suggestedId = FilenameUtils.removeExtension(file.getName()); final String suggestedName = FilenameUtils.removeExtension(file.getName()); final String fileExt = Misc.nvl(FilenameUtils.getExtension(fullFilename)).toLowerCase(); try {//w ww .j a va 2s. c om ProgressMonitorDialog pm = new ProgressMonitorDialog(UIUtils.getShell()); pm.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { monitor.beginTask(NLS.bind(Messages.RepositoryDNDHelper_SavingResourceTask, fullFilename), IProgressMonitor.UNKNOWN); // Gets a list of all siblings of the future resource // This will allow to compute correct ID and NAME information for // the // ResourceDescriptor List<ResourceDescriptor> childrenDescriptors = WSClientHelper.listFolder( targetParentResource, WSClientHelper.getClient(monitor, targetParentResource), targetParentResource.getValue().getUriString(), new NullProgressMonitor(), 0); // Create the ResourceDescriptor depending on this kind (use file // extension) ResourceDescriptor newRD = getResourceDescriptor(targetParentResource, fileExt); // Update the NAME and ID for the ResourceDescriptor ResourceDescriptorUtil.setProposedResourceDescriptorIDAndName(childrenDescriptors, newRD, suggestedId, suggestedName); // Create and save the resource final AFileResource fileResource = createNewFileResource(targetParentResource, newRD, fileExt); fileResource.setFile(file); monitor.setTaskName( NLS.bind(Messages.RepositoryDNDHelper_SavingResourceTask, fullFilename)); WSClientHelper.saveResource(fileResource, monitor); } catch (Throwable e) { throw new InvocationTargetException(e); } finally { monitor.done(); } } }); } catch (Exception e) { UIUtils.showError(e); } }
From source file:eu.uqasar.web.upload.FileUploadUtil.java
Path getNewFileName(FileUpload file, User user, boolean overwrite) throws IOException { Path target;// w ww.j a v a 2s .c om String uploadedFileFileName = file.getClientFileName(); if (overwrite) { target = FileSystems.getDefault().getPath(getUserUploadFolder(user).toString(), uploadedFileFileName); } else { final String extensionPart = FilenameUtils.getExtension(uploadedFileFileName); final String extension = StringUtils.isEmpty(extensionPart) ? "" : "." + extensionPart; // we add a dot (".") before the UUID, so +1 final int UUID_LENGTH = 1 + 36; // extension length is given out of extension length + the dot (".txt" == 4, no extension == 0) final int EXTENSION_LENGTH = extension.length(); // MAX file name length is 255 - UUID part - Extension part final int MAX_BASE_FILENAME_LENGTH = 255 - UUID_LENGTH - EXTENSION_LENGTH; // shorten file name to no longer than max length, calculated above final String fileNameWithoutExtension = StringUtils .left(FilenameUtils.getBaseName(uploadedFileFileName), MAX_BASE_FILENAME_LENGTH); // generate new file name out of shortened base name + "." + UUID + any extension (including ".") final String targetFileName = String.format("%s.%s%s", fileNameWithoutExtension, UUID.randomUUID().toString(), extension); target = FileSystems.getDefault().getPath(getUserUploadFolder(user).toString(), targetFileName); } return target; }
From source file:au.org.ala.biocache.util.MimeType.java
/** * Lookup method for mimetype string/*from ww w .j a v a2s.c o m*/ * * @return ContentModelEnum the ContentModelEnum */ public static MimeType getForFileExtension(String fileExtension) { return fileExtensionLookup.get(FilenameUtils.getExtension(fileExtension).toLowerCase()); }
From source file:com.jaeksoft.searchlib.renderer.RendererResult.java
final public String getViewerUrl(ResultDocument resultDocument, String url) throws SearchLibException { HocrPdf hocrPdf = null;/*w w w. ja va 2s . c o m*/ if (hocrField != null) { List<FieldValueItem> fieldValueItem = resultDocument.getValues(hocrField); if (fieldValueItem != null) hocrPdf = new HocrPdf(fieldValueItem); } if (contentTypeField != null) { String ct = resultDocument.getValueContent(contentTypeField, 0); if ("application/pdf".equalsIgnoreCase(ct)) return addItemGetUrl(url, hocrPdf); } else if (filenameField != null) { String fn = resultDocument.getValueContent(filenameField, 0); if ("pdf".equalsIgnoreCase(FilenameUtils.getExtension(fn))) return addItemGetUrl(url, hocrPdf); } return null; }