List of usage examples for org.apache.commons.io FilenameUtils concat
public static String concat(String basePath, String fullFilenameToAdd)
From source file:au.org.ala.delta.io.OutputFileManager.java
protected File createFile(String fileName) { File parent = null;//from w ww . ja v a 2s .c o m if (_context.getFile() != null) { parent = _context.getFile().getParentFile(); } if (parent == null) { parent = new File(System.getProperty("user.dir")); } File file = new File(fileName); if (!file.isAbsolute()) { file = new File(FilenameUtils.concat(parent.getAbsolutePath(), fileName)); } return file; }
From source file:io.wcm.devops.conga.generator.EnvironmentGenerator.java
private void generateFile(RoleFile roleFile, String dir, String fileName, Map<String, Object> config, File nodeDir, Template template, String roleName, String roleVariantName, String templateName) { File file = new File(nodeDir, dir != null ? FilenameUtils.concat(dir, fileName) : fileName); boolean duplicateFile = generatedFilePaths.contains(FileUtil.getCanonicalPath(file)); if (file.exists()) { file.delete();//from www . j a v a 2 s.co m } // skip file if condition does not evaluate to a non-empty string or is "false" if (StringUtils.isNotEmpty(roleFile.getCondition())) { String condition = VariableStringResolver.resolve(roleFile.getCondition(), config); if (StringUtils.isBlank(condition) || StringUtils.equalsIgnoreCase(condition, "false")) { return; } } FileGenerator fileGenerator = new FileGenerator(environmentName, roleName, roleVariantName, templateName, nodeDir, file, roleFile, config, template, pluginManager, version, dependencyVersions, log); try { fileGenerator.generate(); generatedFilePaths.add(FileUtil.getCanonicalPath(file)); if (duplicateFile) { log.warn("File was generated already, check for file name clashes: " + FileUtil.getCanonicalPath(file)); } } catch (ValidationException ex) { throw new GeneratorException( "File validation failed " + FileUtil.getCanonicalPath(file) + " - " + ex.getMessage()); } catch (Throwable ex) { throw new GeneratorException( "Unable to generate file: " + FileUtil.getCanonicalPath(file) + "\n" + ex.getMessage(), ex); } }
From source file:es.urjc.mctwp.image.impl.collection.fs.ImageContentCollectionFSImpl.java
/** * It resolves properly collection file directory. * /*from ww w. ja va2 s . c om*/ * @param colName * @param temporal * @return */ private File getProperCollection(String colName, boolean temporal) { String basePath = temporal ? tmpcoll.getAbsolutePath() : basedir.getAbsolutePath(); return new File(FilenameUtils.concat(basePath, colName)); }
From source file:edu.cornell.med.icb.goby.alignments.TestSkipTo.java
@Test public void testEmptyAlignment() throws IOException { final String basename = "align-skip-to-3"; final AlignmentWriterImpl writer = new AlignmentWriterImpl(FilenameUtils.concat(BASE_TEST_DIR, basename)); writer.setNumAlignmentEntriesPerChunk(numEntriesPerChunk); final int numTargets = 3; final int[] targetLengths = new int[numTargets]; for (int referenceIndex = 0; referenceIndex < numTargets; referenceIndex++) { targetLengths[referenceIndex] = 1000; }/* w ww .j a v a2 s. com*/ writer.setTargetLengths(targetLengths); // we write this alignment sorted: writer.setSorted(true); writer.close(); writer.printStats(System.out); final AlignmentReader reader = new AlignmentReaderImpl(FilenameUtils.concat(BASE_TEST_DIR, basename)); final Alignments.AlignmentEntry c = reader.skipTo(2, 0); assertNull(c); assertFalse(reader.hasNext()); }
From source file:com.abiquo.api.services.stub.TarantinoJobCreator.java
/** * Add the secondary hard disks./* www . j ava 2 s . co m*/ * * @param virtualMachine virtual machine object. * @param vmDesc definition to send. */ @Transactional(readOnly = true, propagation = Propagation.REQUIRED) private void secondaryHardDisksDefinition(final VirtualMachine virtualMachine, final VirtualMachineDescriptionBuilder vmDesc) { List<DiskManagement> hardDisks = virtualMachine.getDisks(); String datastore; if (virtualMachine.getDatastore().getDirectory() != null && !StringUtils.isEmpty(virtualMachine.getDatastore().getDirectory())) { datastore = FilenameUtils.concat(virtualMachine.getDatastore().getRootPath(), virtualMachine.getDatastore().getDirectory()); } else { datastore = virtualMachine.getDatastore().getRootPath(); } DiskControllerType cntrlType = getDiskController(virtualMachine.getHypervisor().getType(), false, false); for (DiskManagement imHard : hardDisks) { vmDesc.addSecondaryHardDisk(imHard.getSizeInMb() * 1048576, imHard.getSequence(), datastore, cntrlType); } }
From source file:es.urjc.mctwp.image.impl.collection.fs.ImageContentCollectionFSImpl.java
/** * It stores properly a single file.//from w w w. j av a 2 s . c o m * * @param collection * @param file * @throws ImageCollectionException * @throws IOException */ private void storeFile(File collection, File file) throws ImageCollectionException, IOException { File dest = new File(FilenameUtils.concat(collection.getAbsolutePath(), file.getName())); FileUtils.copyFile(file, dest); }
From source file:edu.cornell.med.icb.goby.alignments.TestReadWriteAlignments.java
/** * Validate that the the alignment header constant query length * ({@link edu.cornell.med.icb.goby.alignments.Alignments.AlignmentHeader#hasConstantQueryLength()}) * is set to false when queries of the same length get appended. * @throws IOException if there is a problem reading or writing the alignment *///w w w.j a va 2s . co m @Test public void nonConstantQueryLengths() throws IOException { final int[] queryLengths = { 11, 21, 12, 42 }; final AlignmentWriter writer = new AlignmentWriterImpl( FilenameUtils.concat(BASE_TEST_DIR, "non-constant-query-lengths")); int queryIndex = 0; for (final int queryLength : queryLengths) { final Alignments.AlignmentEntry.Builder builder = Alignments.AlignmentEntry.newBuilder(); builder.setQueryLength(queryLength); builder.setQueryIndex(queryIndex++); builder.setTargetIndex(42); builder.setPosition(0); builder.setMatchingReverseStrand(true); final Alignments.AlignmentEntry entry = builder.build(); writer.appendEntry(entry); } writer.close(); final AlignmentReaderImpl reader = new AlignmentReaderImpl( FilenameUtils.concat(BASE_TEST_DIR, "non-constant-query-lengths")); for (final Alignments.AlignmentEntry entry : reader) { assertEquals(queryLengths[entry.getQueryIndex()], entry.getQueryLength()); } reader.readHeader(); assertFalse("query length must not be constant", reader.isConstantQueryLengths()); assertEquals("Number of queries do not match", 4, reader.getNumberOfQueries()); }
From source file:com.enioka.jqm.tools.Loader.java
private void endOfRun() { // Register end date as soon as possible to be as exact as possible (sending mails may take time for example) endDate = GregorianCalendar.getInstance(Locale.getDefault()); // This block is needed for external payloads, as the single runner may forcefully call endOfRun. synchronized (this) { if (!isDone) { isDone = true;/*w w w . java2 s .co m*/ } else { return; } } // Release the slot so as to allow other job instances to run (first op!) if (p != null) { p.decreaseNbThread(this.job.getId()); } // Send e-mail before releasing the slot - it may be long if (job.getEmail() != null) { try { Helpers.sendEndMessage(job); } catch (Exception e) { jqmlogger.warn("An e-mail could not be sent. No impact on the engine.", e); } } // Clean class loader ClassLoaderLeakCleaner.clean(Thread.currentThread().getContextClassLoader()); // Clean JDBC connections ClassLoaderLeakCleaner.cleanJdbc(Thread.currentThread()); // Restore class loader if (this.classLoaderToRestoreAtEnd != null) { Thread.currentThread().setContextClassLoader(classLoaderToRestoreAtEnd); jqmlogger.trace("Class Loader was correctly restored"); } // Clean temp dir (if it exists) File tmpDir = new File(FilenameUtils.concat(node.getTmpDirectory(), "" + job.getId())); if (tmpDir.isDirectory()) { try { if (FileUtils.deleteQuietly(tmpDir)) { jqmlogger.trace("temp directory was removed"); } else { jqmlogger.warn("Could not remove temp directory " + tmpDir.getAbsolutePath() + "for this job instance. There may be open handlers remaining open."); } } catch (Exception e) { jqmlogger.warn("Could not remove temp directory for unusual reasons", e); } } // Unregister MBean if (p != null && this.p.getEngine().loadJmxBeans) { try { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); mbs.unregisterMBean(name); } catch (Exception e) { jqmlogger.error("Could not unregister JobInstance JMX bean", e); } } // Unregister logger unregisterLogger(); // Part needing DB connection with specific failure handling code. endOfRunDb(); }
From source file:edu.scripps.fl.pubchem.xmltool.gui.PubChemXMLCreatorGUI.java
public void mouseClicked(MouseEvent e) { try {//from w ww . j a v a2 s. c om if (e.getClickCount() > 0) { setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); if (e.getSource() == jtpExample) { URL url = getClass().getClassLoader().getResource("ExampleExcel.xlsx"); File tmpFile = File.createTempFile("example", ".xlsx"); FileUtils.copyURLToFile(url, tmpFile); tmpFile.deleteOnExit(); Desktop.getDesktop().open(tmpFile); } else if (e.getSource() == jtpExcelTemplate) { File saveFile = gc.fileChooser(jtfFileExcel, ".xlsx", "save"); if (saveFile != null) { URL url = getClass().getClassLoader().getResource("ExcelTemplate_withBAO.xlsx"); OutputStream out = new FileOutputStream(saveFile, true); IOUtils.copy(url.openStream(), out); String output = FilenameUtils.concat(FilenameUtils.getFullPath(saveFile.toString()), FilenameUtils.getBaseName(saveFile.toString())); Desktop.getDesktop().open(new File(saveFile.toString())); } } else if (e.getSource() == jtfFileTemplate && jtfFileTemplate.getText().equals(template)) { jtfFileTemplate.setText(""); } else if (e.getSource() == this) { if (jtfFileTemplate.getText().equals("")) { jtfFileTemplate.setText(template); } } } setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } catch (Throwable throwable) { SwingGUI.handleError(this, throwable); } }
From source file:edu.cornell.med.icb.goby.alignments.TestMerge.java
@Test public void testIgnoreTooManyHits2() throws IOException { synchronized (this) { // make the too many hits info: final AlignmentTooManyHitsWriter tmhWriter = new AlignmentTooManyHitsWriter( FilenameUtils.concat(BASE_TEST_DIR, "align-102"), 4); // tmhWriter will only write entries if numHits > thresh tmhWriter.getNewAmbiguousLocation().setAtLeastNumberOfHits(5); tmhWriter.getNewAmbiguousLocation().setQueryIndex(0); tmhWriter.append();/*from ww w . ja va 2 s . c o m*/ tmhWriter.getNewAmbiguousLocation().setAtLeastNumberOfHits(15); tmhWriter.getNewAmbiguousLocation().setQueryIndex(1); tmhWriter.append(); tmhWriter.close(); final Merge merger = new Merge(3); final List<File> inputFiles; final String outputFile; final String basename; final int count; inputFiles = new ArrayList<File>(); inputFiles.add(new File(FilenameUtils.concat(BASE_TEST_DIR, "align-102"))); inputFiles.add(new File(FilenameUtils.concat(BASE_TEST_DIR, "align-102"))); outputFile = FilenameUtils.concat(BASE_TEST_DIR, "out-103-merged"); merger.setK(30); merger.merge(inputFiles, outputFile); // With k=3 and twice the same input file, the merge should keep twice the queries with best score: basename = outputFile; count = countAlignmentEntries(basename); assertEquals(count, (numQueries102 - 2) * 2/* two queries excluded because of too many hits with k=30 > alignerThreshold */); } }