List of usage examples for org.apache.commons.io FilenameUtils getBaseName
public static String getBaseName(String filename)
From source file:com.salsaw.msalsa.clustal.ClustalOmegaManager.java
@Override public void callClustal(String clustalPath, ClustalFileMapper clustalFileMapper) throws IOException, InterruptedException, SALSAException { // Get program path to execute List<String> clustalProcessCommands = new ArrayList<String>(); clustalProcessCommands.add(clustalPath); // Create the name of output files String inputFileName = FilenameUtils.getBaseName(clustalFileMapper.getInputFilePath()); String inputFileFolderPath = FilenameUtils.getFullPath(clustalFileMapper.getInputFilePath()); Path alignmentFilePath = Paths.get(inputFileFolderPath, inputFileName + "-aln.fasta"); Path guideTreeFilePath = Paths.get(inputFileFolderPath, inputFileName + "-tree.dnd"); // Set inside file mapper clustalFileMapper.setAlignmentFilePath(alignmentFilePath.toString()); clustalFileMapper.setGuideTreeFilePath(guideTreeFilePath.toString()); setClustalFileMapper(clustalFileMapper); // Create clustal omega data generateClustalArguments(clustalProcessCommands); // http://www.rgagnon.com/javadetails/java-0014.html ProcessBuilder builder = new ProcessBuilder(clustalProcessCommands); builder.redirectErrorStream(true);//w ww . j a va 2 s. c o m System.out.println(builder.command()); final Process process = builder.start(); InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line; while ((line = br.readLine()) != null) { System.out.println(line); } process.waitFor(); if (process.exitValue() != 0) { throw new SALSAException("Failed clustal omega call"); } }
From source file:de.mpg.imeji.presentation.beans.PropertyBean.java
/** * @return the internalStorageBase//from w w w . jav a 2 s. c o m * @throws URISyntaxException * @throws IOException */ public String getInternalStorageBase() throws IOException, URISyntaxException { this.internalStorageBase = FilenameUtils.getBaseName( FilenameUtils.normalizeNoEndSeparator(PropertyReader.getProperty("imeji.storage.path"))); return internalStorageBase; }
From source file:eu.uqasar.web.upload.FileUploadUtil.java
Path getNewFileName(FileUpload file, User user, boolean overwrite) throws IOException { Path target;// w w w . j a v a2s .c o m 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:de.uzk.hki.da.format.PublishImageConversionStrategy.java
/** */// w w w .j av a2 s .c o m @Override public List<Event> convertFile(ConversionInstruction ci) throws FileNotFoundException { if (cliConnector == null) throw new IllegalStateException("cliConnector not set"); if (ci.getConversion_routine() == null) throw new IllegalStateException("conversionRoutine not set"); if (ci.getConversion_routine().getTarget_suffix() == null || ci.getConversion_routine().getTarget_suffix().isEmpty()) throw new IllegalStateException("target suffix in conversionRoutine not set"); List<Event> results = new ArrayList<Event>(); // connect dafile to package String input = ci.getSource_file().toRegularFile().getAbsolutePath(); // Convert ArrayList<String> commandAsList = null; for (String audience : audiences) { Path.makeFile(object.getDataPath(), pips, audience.toLowerCase(), ci.getTarget_folder()).mkdirs(); commandAsList = new ArrayList<String>(); commandAsList.add("convert"); commandAsList.add(ci.getSource_file().toRegularFile().getAbsolutePath()); logger.debug(commandAsList.toString()); commandAsList = assembleResizeDimensionsCommand(commandAsList, audience); commandAsList = assembleWatermarkCommand(commandAsList, audience); commandAsList = assembleFooterTextCommand(commandAsList, audience, ci.getSource_file().toRegularFile().getAbsolutePath()); DAFile target = new DAFile(pkg, pips + "/" + audience.toLowerCase(), Utilities.slashize(ci.getTarget_folder()) + FilenameUtils.getBaseName(input) + "." + ci.getConversion_routine().getTarget_suffix()); commandAsList.add(target.toRegularFile().getAbsolutePath()); logger.debug(commandAsList.toString()); String[] commandAsArray = new String[commandAsList.size()]; commandAsArray = commandAsList.toArray(commandAsArray); if (!cliConnector.execute(commandAsArray)) throw new RuntimeException("convert did not succeed: " + Arrays.toString(commandAsArray)); // In order to support multipage tiffs, we check for files by wildcard expression String extension = FilenameUtils.getExtension(target.toRegularFile().getAbsolutePath()); List<File> wild = findFilesWithRegex( new File(FilenameUtils.getFullPath(target.toRegularFile().getAbsolutePath())), Pattern.quote(FilenameUtils.getBaseName(target.getRelative_path())) + "-\\d+\\." + extension); if (!target.toRegularFile().exists() && !wild.isEmpty()) { for (File f : wild) { DAFile multipageTarget = new DAFile(pkg, pips + "/" + audience.toLowerCase(), Utilities.slashize(ci.getTarget_folder()) + f.getName()); Event e = new Event(); e.setDetail(Utilities.createString(commandAsList)); e.setSource_file(ci.getSource_file()); e.setTarget_file(multipageTarget); e.setType("CONVERT"); e.setDate(new Date()); results.add(e); } } else { Event e = new Event(); e.setDetail(Utilities.createString(commandAsList)); e.setSource_file(ci.getSource_file()); e.setTarget_file(target); e.setType("CONVERT"); e.setDate(new Date()); results.add(e); } } return results; }
From source file:br.com.pontocontrol.controleponto.controller.impl.ArquivoController.java
@Override public List<Integer> getAvalableFileMonths(int ano) { File dir = new File(getYearPath(ano)); List<Integer> saida = new ArrayList<Integer>(); if (dir.exists()) { File[] listFiles = dir.listFiles(); for (File file : listFiles) { final String ext = FilenameUtils.getExtension(file.getName()); final String nomeArquivo = FilenameUtils.getBaseName(file.getName()); final String[] nomeArquivoSplit = nomeArquivo.split("_"); if (file.isFile() && EXTENSAO_ARQUIVOS.equalsIgnoreCase(ext) && PREFIXO_ARQUIVOS.equalsIgnoreCase(nomeArquivoSplit[0])) { String mesStr = nomeArquivoSplit[1]; try { Date date = new SimpleDateFormat(SUFIXO_ARQUIVOS_PARSER).parse(mesStr); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); saida.add(calendar.get(Calendar.MONTH)); } catch (ParseException ex) { LOG.log(Level.SEVERE, format( "Erro ao executar parse de data da entrada \"%s\" atravs do padro \"MMM\" o arquivo ser descartado.", mesStr), ex); }/*from w ww . j a v a 2 s. c om*/ } } } return saida; }
From source file:integr.org.pgptool.gui.encryption.EncryptionDecryptionTests.java
@Test public void testWeCanDecryptTheProductOfEncryption() throws Exception { String targetFilename = tempDirPath + File.separator + FilenameUtils.getBaseName(testSubjectFilename) + ".pgp"; encryptionService.encrypt(testSubjectFilename, targetFilename, keys.values(), null, null, null); PasswordDeterminedForKey keyAndPassword = buildPasswordDeterminedForKey(targetFilename, "Alice.asc", "pass"); encryptionService.decrypt(targetFilename, targetFilename + ".test", keyAndPassword, null, null); String result = TextFile.read(targetFilename + ".test"); assertEquals(testSubjectContents, result); }
From source file:edu.cornell.med.icb.goby.modes.FilesToAttributesMode.java
@Override public void execute() throws IOException { final PrintWriter out = outputFilename == null ? new PrintWriter(System.out) : new PrintWriter(outputFilename); try {// ww w. j a v a 2 s . c om int index = 0; out.print("trackName\t"); for (String attributeName : attributeNames) { if (!"ignore".equals(attributeName)) { out.print(attributeName); if (index != attributeNames.length) { out.print('\t'); } } index++; } out.println(); for (String file : filenames) { final String file1 = file; String name = FilenameUtils.getName(file1); String filename = FilenameUtils.getBaseName(name); String[] tokens = filename.split(delimiter); out.printf("%s\t", adjustSuffix(name)); for (int i = 0; i < attributeNames.length; i++) { if (!"ignore".equals(attributeNames[i])) { if (tokens.length <= i) { continue; } out.print(tokens[i]); if (i != attributeNames.length) { out.print('\t'); } } } out.println(); } out.flush(); } finally { out.close(); } }
From source file:controller.servlet.ImportAmenities.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from w w w .j av a 2s . com*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Obtencin de la regin String regionName = request.getParameter("regionname"); boolean isXML = false; // Procesado del fichero para subirlo al servidor. for (Part part : request.getParts()) { if (part.getName().equals("file")) { try (InputStream is = request.getPart(part.getName()).getInputStream()) { int i = is.available(); byte[] b = new byte[i]; if (b.length == 0) { break; } is.read(b); String fileName = obtenerNombreFichero(part); String extension = FilenameUtils.getExtension(fileName); String path = this.getServletContext().getRealPath(""); String ruta = path + File.separator + Path.POIS_FOLDER + File.separator + fileName; File directory = new File(path + File.separator + Path.POIS_FOLDER); fileName = FilenameUtils.getBaseName(fileName); if (!directory.exists()) { directory.mkdirs(); } try (FileOutputStream os = new FileOutputStream(ruta)) { os.write(b); } // Comprobacin de que sea un fichero xml. if (extension.equals("xml")) { isXML = true; } else { break; } if (isXML) { // Crear entrada en la tabla de ficheros de PDIs. UploadedPoiFileDaoImpl uPFDao = new UploadedPoiFileDaoImpl(); UploadedFile uFile = new UploadedFile(); uFile.setName(fileName); uFile.setProcessedDate(new java.sql.Date(new java.util.Date().getTime())); uPFDao.createFile(uFile); // Almacenado de los datos en la Base de Datos. NotifyingThread nT = new AmenityProcessing(ruta, regionName); nT.addListener(this); nT.setName(ThreadName.AMENITIES_THREAD_NAME); nT.start(); } } } } HttpSession session = request.getSession(true); session.setAttribute("isXML", isXML); if (!isXML) { session.setAttribute("error", true); String page = "/pages/amenitiesmanage.jsp"; RequestDispatcher requestDispatcher = getServletContext().getRequestDispatcher(page); requestDispatcher.forward(request, response); } else { session.setAttribute("error", false); processRequest(request, response); } }
From source file:MSUmpire.LCMSPeakStructure.LCMSPeakDIAMS2.java
public LCMSPeakDIAMS2(String Filename, DIAPack parentDIA, InstrumentParameter parameter, XYData WindowMZ, XYData LastWindowMZ, SpectrumParserBase spectrumparser, int NoCPUs) { this.DIA_MZ_Range = WindowMZ; this.Last_MZ_Range = LastWindowMZ; this.WindowID = (int) Math.floor(WindowMZ.getX()) + "_" + (int) Math.floor(WindowMZ.getY()); this.SpectrumParser = spectrumparser; this.ScanCollectionName = FilenameUtils.getFullPath(Filename) + "/" + FilenameUtils.getBaseName(Filename) + "_" + (int) Math.floor(WindowMZ.getX()) + "_" + (int) Math.floor(WindowMZ.getY()); this.ParentmzXMLName = FilenameUtils.getFullPath(Filename) + "/" + FilenameUtils.getBaseName(Filename); this.parentDIA = parentDIA; this.parameter = parameter; this.MaxNoPeakCluster = parameter.MaxMS2NoPeakCluster; this.MinNoPeakCluster = parameter.MinMS2NoPeakCluster; this.StartCharge = parameter.MS2StartCharge; this.EndCharge = parameter.MS2EndCharge; this.MiniIntensity = parameter.MinMSMSIntensity; this.SNR = parameter.MS2SNThreshold; this.NoCPUs = NoCPUs; }
From source file:ee.ria.DigiDoc.activity.OpenExternalFileActivity.java
private ContainerFacade createContainer(List<Uri> uris) { if (!uris.isEmpty()) { List<Uri> containers = searchForContainers(uris); if (!containers.isEmpty()) { Uri containerUri = containers.get(0); uris.remove(containerUri);/*from w w w . j a v a2 s. c o m*/ try { return ContainerBuilder.aContainer(this).fromExternalContainer(containerUri).withDataFiles(uris) .build(); } catch (ContainerBuilder.ExternalContainerSaveException e) { Timber.e(e, "Failed to create container"); return null; } } String fileName = FileUtils.resolveFileName(uris.get(0), getContentResolver()); return ContainerBuilder.aContainer(this).withDataFiles(uris) .withContainerName(FilenameUtils.getBaseName(fileName) + "." + getContainerFormat()).build(); } return null; }