List of usage examples for org.apache.commons.io FilenameUtils removeExtension
public static String removeExtension(String filename)
From source file:eu.prestoprime.plugin.mserve.MServeTasks.java
@WfService(name = "mserve_transcode2ogv", version = "1.0.0") public void transcodeToOGV(Map<String, String> sParams, Map<String, String> dParamsString, Map<String, File> dParamsFile) throws TaskExecutionFailedException { // get static parameters String url = sParams.get("mserve.url"); // get dynamic parameters String sipID = dParamsString.get("sipID"); String fileID = dParamsString.get("mserveFileID"); String userID = dParamsString.get("userID"); // get serviceID String serviceID = ConfigurationManager.getUserInstance().getService(userID, "mserve"); // get SIP/* ww w . j a v a 2 s . c o m*/ SIP sip = null; try { sip = P4DataManager.getInstance().getSIPByID(sipID); // run FFmbc MServeClient cl = new MServeClient(url, serviceID); Map<String, String> params = new HashMap<>(); params.put("args", "-a 3 -v 7"); File output = cl.runMServeTask(fileID, MServeTask.ffmpeg2theora, params); // MD5 MessageDigestExtractor mde = new MessageDigestExtractor(); ToolOutput<MessageDigestExtractor.AttributeType> toolOutput = mde.extract(output.getAbsolutePath()); String md5sum = toolOutput.getAttribute(MessageDigestExtractor.AttributeType.MD5); // get outputVideo String outputVideoName = FilenameUtils.removeExtension( FilenameUtils.getName(sip.getAVMaterial("application/mxf", "FILE").get(0))) + ".ogv"; String outputVideo = dParamsString.get("videosFolder") + File.separator + outputVideoName; File targetFile = new File(outputVideo); // copy webm to p4 storage output.renameTo(targetFile); // update SIP sip.addFile("video/ogg", "FILE", outputVideo, md5sum, targetFile.length()); dParamsFile.put("webm", new File(outputVideo)); } catch (DataException e) { e.printStackTrace(); throw new TaskExecutionFailedException("Unable to find SIP..."); } catch (IPException e) { e.printStackTrace(); throw new TaskExecutionFailedException("Unable to work with SIP..."); } catch (MServeException | ToolException e) { e.printStackTrace(); throw new TaskExecutionFailedException("Unable to run FFmbc extractor on MServe..."); } finally { // release SIP P4DataManager.getInstance().releaseIP(sip); } }
From source file:com.daphne.es.showcase.excel.service.ExcelDataService.java
private String compressAndDeleteOriginal(final String filename) { String newFileName = FilenameUtils.removeExtension(filename) + ".zip"; compressAndDeleteOriginal(newFileName, filename); return newFileName; }
From source file:it.govpay.core.business.EstrattoConto.java
private EstrattoContoMetadata getEstrattoContoFromJson(String codDominio, String fileName) { EstrattoContoMetadata estrattoConto = new EstrattoContoMetadata(); estrattoConto.setCodDominio(codDominio); estrattoConto.setNomeFile(fileName); try {/* w w w . j av a 2 s . co m*/ // decodificare l'estensione del file String extension = FilenameUtils.getExtension(fileName); estrattoConto.setFormato(extension); fileName = FilenameUtils.removeExtension(fileName); String[] split = fileName.split("_"); if (split != null && split.length > 0) { boolean formatoOk = false; // formato Nome file codDominio_anno_mese if (split.length == 3) { estrattoConto.setAnno(Integer.parseInt(split[1])); estrattoConto.setMese(Integer.parseInt(split[2])); formatoOk = true; } // formato Nome file codDominio_iban_anno_mese if (split.length == 4) { estrattoConto.setIbanAccredito(split[1]); estrattoConto.setAnno(Integer.parseInt(split[2])); estrattoConto.setMese(Integer.parseInt(split[3])); formatoOk = true; } if (formatoOk) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.MONTH, estrattoConto.getMese() - 1); cal.set(Calendar.YEAR, estrattoConto.getAnno()); estrattoConto.setMeseAnno(this.f3.format(cal.getTime())); } else { log.debug("Formato nome del file [" + fileName + "] non valido, impossibile identificare mese/anno dell'estratto conto."); } } } catch (Exception e) { log.error(e.getMessage(), e); } return estrattoConto; }
From source file:io.dockstore.client.cli.nested.ToolClient.java
public void downloadDescriptors(String entry, String descriptor, File tempDir) { // In the future, delete tmp files DockstoreTool tool = null;/*from w w w. j a v a 2 s.c o m*/ String[] parts = entry.split(":"); String path = parts[0]; String version = (parts.length > 1) ? parts[1] : "master"; try { tool = containersApi.getPublishedContainerByToolPath(path); } catch (ApiException e) { exceptionMessage(e, "No match for entry", Client.API_ERROR); } if (tool != null) { try { if (descriptor.toLowerCase().equals("cwl")) { List<SourceFile> files = containersApi.secondaryCwl(tool.getId(), version); for (SourceFile sourceFile : files) { File tempDescriptor = new File(tempDir.getAbsolutePath() + sourceFile.getPath()); Files.write(sourceFile.getContent(), tempDescriptor, StandardCharsets.UTF_8); } } else { List<SourceFile> files = containersApi.secondaryWdl(tool.getId(), version); for (SourceFile sourceFile : files) { File tempDescriptor = File.createTempFile( FilenameUtils.removeExtension(sourceFile.getPath()), FilenameUtils.getExtension(sourceFile.getPath()), tempDir); Files.write(sourceFile.getContent(), tempDescriptor, StandardCharsets.UTF_8); } } } catch (ApiException e) { exceptionMessage(e, "Error getting file(s) from server", Client.API_ERROR); } catch (IOException e) { exceptionMessage(e, "Error writing to File", Client.IO_ERROR); } } }
From source file:com.opendoorlogistics.studio.AppFrame.java
private void saveDatastoreWithoutUserPrompt(File file) { String ext = FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase(); // ensure we have spreadsheet extension if (!ext.equals("xls") && !ext.equals("xlsx")) { ext = "xlsx"; String filename = FilenameUtils.removeExtension(file.getAbsolutePath()) + "." + ext; file = new File(filename); }/*from ww w . j av a 2s.c o m*/ final File finalFile = file; final String finalExt = ext; String message = "Saving " + file; ProgressDialog<Boolean> pd = new ProgressDialog<>(AppFrame.this, message, false); pd.setLocationRelativeTo(this); pd.setText("Saving file, please wait."); final ExecutionReport report = new ExecutionReportImpl(); pd.start(new Callable<Boolean>() { @Override public Boolean call() throws Exception { // return PoiIO.export(loaded.getDs(), finalFile, // finalExt.equals("xlsx")); try { return loaded.save(finalFile, finalExt.equals("xlsx"), report); } catch (Throwable e) { report.setFailed(e); return false; } } }, new OnFinishedSwingThreadCB<Boolean>() { @Override public void onFinished(Boolean result, boolean userCancelled, boolean userFinishedNow) { if (result == false) { report.setFailed("Could not save file " + finalFile.getAbsolutePath()); ExecutionReportDialog.show(AppFrame.this, "Error saving file", report); } else { loaded.onSaved(finalFile); if (report.size() > 0) { ExecutionReportDialog.show(AppFrame.this, "Warning saving file", report); } PreferencesManager.getSingleton().addRecentFile(finalFile); PreferencesManager.getSingleton().setDirectory(PrefKey.LAST_IO_DIR, finalFile); } updateAppearance(); } }); }
From source file:ffx.xray.DiffractionData.java
/** * write current datasets to MTZ files//from ww w . j a va 2 s . co m * * @param filename output filename, or filename root for multiple datasets * @see MTZWriter#write() */ public void writeData(String filename) { if (n == 1) { writeData(filename, 0); } else { for (int i = 0; i < n; i++) { writeData("" + FilenameUtils.removeExtension(filename) + "_" + i + ".mtz", i); } } }
From source file:com.moviejukebox.scanner.AttachmentScanner.java
/** * Extract an attachment//from www .j a va 2 s . c o m * * @param attachment the attachment to extract * @param setImage true, if a set image should be extracted; in this case ".set" is append before file extension * @param counter a counter (only used for NFOs cause there may be multiple NFOs in one file) * @return */ private static File extractAttachment(Attachment attachment) { File sourceFile = attachment.getSourceFile(); if (sourceFile == null) { // source file must exist return null; } else if (!sourceFile.exists()) { // source file must exist return null; } // build return file name StringBuilder returnFileName = new StringBuilder(); returnFileName.append(tempDirectory.getAbsolutePath()); returnFileName.append(File.separatorChar); returnFileName.append(FilenameUtils.removeExtension(sourceFile.getName())); // add attachment id so the extracted file becomes unique per movie file returnFileName.append("."); returnFileName.append(attachment.getAttachmentId()); switch (attachment.getContentType()) { case NFO: returnFileName.append(".nfo"); break; case POSTER: case FANART: case BANNER: case SET_POSTER: case SET_FANART: case SET_BANNER: case VIDEOIMAGE: returnFileName.append(VALID_IMAGE_MIME_TYPES.get(attachment.getMimeType())); break; default: returnFileName.append(VALID_IMAGE_MIME_TYPES.get(attachment.getMimeType())); break; } File returnFile = new File(returnFileName.toString()); if (returnFile.exists() && (returnFile.lastModified() >= sourceFile.lastModified())) { // already present or extracted LOG.debug("File to extract already exists; no extraction needed"); return returnFile; } LOG.trace("Extract attachement ({})", attachment); try { // Create the command line List<String> commandMedia = new ArrayList<>(MT_EXTRACT_EXE); commandMedia.add("attachments"); commandMedia.add(sourceFile.getAbsolutePath()); commandMedia.add(attachment.getAttachmentId() + ":" + returnFileName.toString()); ProcessBuilder pb = new ProcessBuilder(commandMedia); pb.directory(MT_PATH); Process p = pb.start(); if (p.waitFor() != 0) { LOG.error("Error during extraction - ErrorCode={}", p.exitValue()); returnFile = null; } } catch (IOException | InterruptedException ex) { LOG.error(SystemTools.getStackTrace(ex)); returnFile = null; } if (returnFile != null) { if (returnFile.exists()) { // need to reset last modification date to last modification date // of source file to fulfill later checks try { returnFile.setLastModified(sourceFile.lastModified()); } catch (Exception ignore) { // nothing to do anymore } } else { // reset return file to null if not existent returnFile = null; } } return returnFile; }
From source file:edu.ku.brc.util.WebStoreAttachmentMgr.java
/** * @param fileName//from ww w .jav a2s .c o m * @param scale * @return */ private String getScaledFileName(final String fileName, final Integer scale) { String newPath = FilenameUtils.removeExtension(fileName); String ext = FilenameUtils.getExtension(fileName); return String.format("%s_%d%s%s", newPath, scale, FilenameUtils.EXTENSION_SEPARATOR_STR, ext); }
From source file:ddf.catalog.impl.CatalogFrameworkImpl.java
private String updateFileExtension(String mimeTypeRaw, String fileName) { String extension = FilenameUtils.getExtension(fileName); if (ContentItem.DEFAULT_FILE_NAME.equals(fileName) && !ContentItem.DEFAULT_MIME_TYPE.equals(mimeTypeRaw) || StringUtils.isEmpty(extension)) { try {//from w ww.ja v a2 s . com extension = frameworkProperties.getMimeTypeMapper().getFileExtensionForMimeType(mimeTypeRaw); if (StringUtils.isNotEmpty(extension)) { fileName = FilenameUtils.removeExtension(fileName); fileName += extension; } } catch (MimeTypeResolutionException e) { LOGGER.debug("Unable to guess file extension for mime type.", e); } } return fileName; }
From source file:ffx.xray.DiffractionData.java
/** * write 2Fo-Fc and Fo-Fc maps for all datasets * * @param filename output root filename for Fo-Fc and 2Fo-Fc maps *//*from w ww . ja va 2 s. c o m*/ public void writeMaps(String filename) { if (n == 1) { writeMaps(filename, 0); } else { for (int i = 0; i < n; i++) { writeMaps("" + FilenameUtils.removeExtension(filename) + "_" + i + ".map", i); } } }