List of usage examples for org.apache.commons.io FilenameUtils concat
public static String concat(String basePath, String fullFilenameToAdd)
From source file:jenkins.plugins.coverity.CoverityLauncher.java
/** * Sets the value of environment variable "COV_IDIR" and creates necessary directories. This variable is used as argument of "--dir" for * cov-build./*from w w w.jav a 2s . c o m*/ * * If the environment variable has already being set then that value is used. Otherwise, the value of * this variable is set to either a temporary directory or the idir specified on the UI under the * Intermediate Directory option. * * Notice this variable must be resolved before running cov-build. Also this method creates necessary directories. */ public void setupIntermediateDirectory(@Nonnull AbstractBuild<?, ?> build, @Nonnull TaskListener listener, @Nonnull Node node) { Validate.notNull(build, AbstractBuild.class.getName() + " object can't be null"); Validate.notNull(listener, TaskListener.class.getName() + " object can't be null"); Validate.notNull(node, Node.class.getName() + " object can't be null"); Validate.notNull(envVars, EnvVars.class.getName() + " object can't be null"); if (!envVars.containsKey("COV_IDIR")) { FilePath temp; InvocationAssistance invocationAssistance = CoverityUtils.getInvocationAssistance(build); try { if (invocationAssistance == null || invocationAssistance.getIntermediateDir() == null || invocationAssistance.getIntermediateDir().isEmpty()) { FilePath coverityDir = node.getRootPath().child("coverity"); coverityDir.mkdirs(); temp = coverityDir.createTempDir("temp-", null); } else { // Gets a not null nor empty intermediate directory. temp = resolveIntermediateDirectory(build, listener, node, invocationAssistance.getIntermediateDir()); if (temp != null) { File idir = new File(temp.getRemote()); String workspace = envVars.get("WORKSPACE"); if (idir != null && !idir.isAbsolute() && !StringUtils.isEmpty(workspace)) { String path = FilenameUtils.concat(workspace, temp.getRemote()); if (!StringUtils.isEmpty(path)) { temp = new FilePath(temp.getChannel(), path); } } temp.mkdirs(); } } if (invocationAssistance != null) { build.addAction(new CoverityTempDir(temp, invocationAssistance.getIntermediateDir() == null)); } else { build.addAction(new CoverityTempDir(temp, true)); } } catch (IOException e) { throw new RuntimeException("Error while creating temporary directory for Coverity", e); } catch (InterruptedException e) { throw new RuntimeException("Interrupted while creating temporary directory for Coverity"); } if (temp != null) { envVars.put("COV_IDIR", temp.getRemote()); } } }
From source file:net.sf.jvifm.ui.shell.QuickRunShell.java
public boolean doCommand() { String cmd = null;/*from w w w . java2 s . c om*/ String[] args = new String[] {}; /* if (completeOptions != null && completeOptions.length > 0) { cmd = getCompletionText(); } else { */ cmd = txtCommand.getText(); int argsRealBegin = cmd.indexOf(" ", argsBeginIndex); if (argsRealBegin > 0) { // arg String arg = cmd.substring(argsRealBegin + 1); cmd = cmd.substring(0, argsRealBegin).trim(); args = arg.split("\\s+"); } ShortcutsManager scm = ShortcutsManager.getInstance(); if (scm.isShortCut(cmd)) { Shortcut cc = scm.findByName(cmd); Command command = new SystemCommand(cc.getText(), args, true); command.setPwd(Main.fileManager.getActivePanel().getPwd()); commandRunner.run(command); return true; } String newPath = FilenameUtils.concat(pwd, cmd); newPath = FilenameUtils.normalizeNoEndSeparator(newPath); File file = null; try { file = new File(newPath); } catch (Exception e) { return false; } if (file != null && file.exists()) { if (file.isFile()) { // Util.openFileWithDefaultApp(newPath); Command command = new SystemCommand(newPath, args, true); command.setPwd(Main.fileManager.getActivePanel().getPwd()); commandRunner.run(command); return true; } FileManager fileManager = Main.fileManager; FileLister activeLister = fileManager.getActivePanel(); fileManager.activeGUI(); activeLister.visit(newPath); return true; } String abPath = findExecuteInSysPath(cmd); if (abPath != null) { Command command = new SystemCommand(abPath, args, false, true); command.setPwd(Main.fileManager.getActivePanel().getPwd()); commandRunner.run(command); return true; } return false; }
From source file:es.urjc.mctwp.pacs.impl.DcmStorageServerImpl.java
/** * Callback that stores DICOM received file into FS *///w w w . j av a 2 s . com protected void doCStore(Association as, int pcid, DicomObject rq, PDVInputStream dataStream, String tsuid, DicomObject rsp) throws IOException, DicomServiceException { //Is modality allowed? Command cmd = getCommand(ModalityAllowed.class); ((ModalityAllowed) cmd).setModality(as.getCallingAET()); cmd = runCommand(cmd); if (((ModalityAllowed) cmd).getResult()) try { //Get Dicom object String cuid = rq.getString(Tag.AffectedSOPClassUID); String iuid = rq.getString(Tag.AffectedSOPInstanceUID); BasicDicomObject fmi = new BasicDicomObject(); fmi.initFileMetaInformation(cuid, iuid, tsuid); //Store temporary dicom file String filename = iuid + ".dcm"; File file = new File(FilenameUtils.concat(tempDirectory.getAbsolutePath(), filename)); FileOutputStream fos = new FileOutputStream(file); BufferedOutputStream bos = new BufferedOutputStream(fos, bufferSize); DicomOutputStream dos = new DicomOutputStream(bos); dos.writeFileMetaInformation(fmi); dataStream.copyTo(dos); dos.close(); //Store into persistent space ArrayList<File> files = new ArrayList<File>(); files.add(file); imc.storeTemporalImages(as.getCallingAET(), files); file.delete(); } catch (Exception e) { throw new DicomServiceException(rq, Status.ProcessingFailure, e.getMessage()); } //Wait if there is delay configured if (rspDelay > 0) try { Thread.sleep(rspDelay); } catch (InterruptedException e) { } }
From source file:com.enioka.jqm.tools.ClientApiTest.java
/** * Temp dir should be removed after run/*w w w . ja va 2 s .c o m*/ */ @Test public void testTempDir() throws Exception { int i = JqmSimpleTest.create(em, "pyl.EngineApiTmpDir").run(this); File tmpDir = new File(FilenameUtils.concat(TestHelpers.node.getTmpDirectory(), "" + i)); Assert.assertFalse(tmpDir.isDirectory()); }
From source file:com.enderville.enderinstaller.util.InstallScript.java
/** * If the install fails, restore everything that we backed up. * * @throws IOException/*from w w w . ja v a 2 s .com*/ */ private static void restoreBackup() throws IOException { //TODO what other folders to restore? FileUtils.copyFile(new File(InstallerConfig.getMinecraftJar() + ".backup"), new File(InstallerConfig.getMinecraftJar())); File mods = new File(InstallerConfig.getMinecraftModsFolder()); File modsBackup = new File(InstallerConfig.getMinecraftModsFolder() + "_backup"); if (modsBackup.exists()) { FileUtils.deleteDirectory(mods); FileUtils.copyDirectory(modsBackup, mods); } for (String name : otherThingsToBackup) { String fname = FilenameUtils .normalize(FilenameUtils.concat(InstallerConfig.getMinecraftFolder(), name)); String fnameBackup = fname + "_backup"; File f = new File(fname); File backup = new File(fnameBackup); if (backup.exists()) { FileUtils.copyDirectory(backup, f); } } }
From source file:edu.cornell.med.icb.goby.modes.TestSplicedSamHelper.java
public void testSamToCompactTrickCase3() throws IOException { SAMToCompactMode importer = new SAMToCompactMode(); importer.setInputFile("test-data/splicedsamhelper/tricky-spliced-3.sam"); final String outputFilename = FilenameUtils.concat(BASE_TEST_DIR, "spliced-output-alignment-3"); importer.setOutputFile(outputFilename); importer.execute();/*from www. j av a 2 s . c o m*/ AlignmentReader reader = new AlignmentReaderImpl(outputFilename); assertTrue(reader.hasNext()); Alignments.AlignmentEntry first = reader.next(); assertEquals(0, first.getQueryIndex()); assertEquals(0, first.getFragmentIndex()); assertEquals(170769 - 1, first.getPosition()); assertTrue(first.hasPairAlignmentLink()); assertFalse(first.hasSplicedForwardAlignmentLink()); Assert.assertEquals(1, first.getPairAlignmentLink().getFragmentIndex()); Assert.assertEquals(216048 - 1, first.getPairAlignmentLink().getPosition()); assertFalse(first.hasSplicedBackwardAlignmentLink()); Alignments.AlignmentEntry second = reader.next(); assertEquals(0, second.getQueryIndex()); assertEquals(1, second.getFragmentIndex()); assertTrue(second.hasPairAlignmentLink()); Assert.assertEquals(0, second.getPairAlignmentLink().getFragmentIndex()); assertTrue("second must have spliced forward link", second.hasSplicedForwardAlignmentLink()); assertFalse("second must have spliced backward link", second.hasSplicedBackwardAlignmentLink()); }
From source file:es.urjc.mctwp.image.impl.dicom.DicomImagePlugin.java
/** * Obtains a png file from a singleImage * // w ww .j av a2s. co m * @param single * @return * @throws ImageException */ private File toPng(SingleImageDicomImpl single) throws ImageException { File result = null; File source = null; try { // Prepare output file source = single.getContent(); String base = source.getParent(); String pre = ImageUtils.getFileName(source); result = new File(FilenameUtils.concat(base, pre + ".png")); // Check if thumbnails exists. Like a cache of thumbnails if ((!result.exists()) || (!result.isFile()) || (result.length() == 0)) { // Delete a possible erroneus thumbanil file if (result.exists()) result.delete(); // Execute transformation and scale String cmd = medconPath + " " + options + " -f " + source.getAbsolutePath() + " -o " + result.getAbsolutePath(); exec(cmd, true); scaleThumbnail(result); } } catch (Exception e) { if (result.exists()) result.delete(); logger.error(e.getMessage()); throw new ImageException(e); } return result; }
From source file:com.mosso.client.cloudfiles.sample.FilesCopy.java
/** * * @param folder//from w ww.jav a 2 s . c om * @return null if the input is not a folder otherwise a zip file containing all the files in the folder with nested folders skipped. * @throws IOException */ public static File zipFolder(File folder) throws IOException { byte[] buf = new byte[1024]; int len; // Create the ZIP file String filenameWithZipExt = folder.getName() + ZIPEXTENSION; File zippedFile = new File(FilenameUtils.concat(SYSTEM_TMP.getAbsolutePath(), filenameWithZipExt)); ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zippedFile)); if (folder.isDirectory()) { File[] files = folder.listFiles(); for (File f : files) { if (!f.isDirectory()) { FileInputStream in = new FileInputStream(f); // Add ZIP entry to output stream. out.putNextEntry(new ZipEntry(f.getName())); // Transfer bytes from the file to the ZIP file while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } // Complete the entry out.closeEntry(); in.close(); } else logger.warn("Skipping nested folder: " + f.getAbsoluteFile()); } out.flush(); out.close(); } else { logger.warn("The folder name supplied is not a folder!"); System.err.println("The folder name supplied is not a folder!"); return null; } return zippedFile; }
From source file:com.expedia.tesla.compiler.Compiler.java
private String getOutputPath(String fullName) throws IOException { int idx = fullName.lastIndexOf('.'); String shortName = idx == -1 ? fullName : fullName.substring(idx + 1); String fileName = shortName;/*from ww w . j a va 2 s . co m*/ switch (this.language) { case LANG_JAVA: fileName = fullName.replace('.', File.separatorChar) + ".java"; break; case LANG_CSHARP: fileName += ".cs"; break; case LANG_CPP: fileName += ".h"; break; default: fileName += '.' + this.language; break; } File file = new File(FilenameUtils.concat(this.outputDir.getAbsolutePath(), fileName)); Util.forceMkdirParent(file); return file.getAbsolutePath(); }
From source file:com.enioka.jqm.tools.JobManagerHandler.java
private Integer addDeliverable(String path, String fileLabel) throws IOException { Deliverable d = null;//from w w w . j a v a 2s. c om EntityManager em = Helpers.getNewEm(); try { this.ji = em.find(JobInstance.class, ji.getId()); String outputRoot = this.ji.getNode().getDlRepo(); String ext = FilenameUtils.getExtension(path); String relDestPath = "" + ji.getJd().getApplicationName() + "/" + ji.getId() + "/" + UUID.randomUUID() + "." + ext; String absDestPath = FilenameUtils.concat(outputRoot, relDestPath); String fileName = FilenameUtils.getName(path); FileUtils.moveFile(new File(path), new File(absDestPath)); jqmlogger.debug("A deliverable is added. Stored as " + absDestPath + ". Initial name: " + fileName); em.getTransaction().begin(); d = Helpers.createDeliverable(relDestPath, fileName, fileLabel, this.ji.getId(), em); em.getTransaction().commit(); } finally { em.close(); } return d.getId(); }