List of usage examples for org.apache.commons.io FilenameUtils getName
public static String getName(String filename)
From source file:massbank.svn.SVNOperation.java
public boolean addEntry(String[] srcFilePaths, String destSubDirName) { String destPath = workCopyPath + File.separator; if (!destSubDirName.equals("")) { destPath += destSubDirName + File.separator; }/* ww w . j a v a 2s. co m*/ try { for (String path : srcFilePaths) { FileUtils.copyFileToDirectory(new File(path), new File(destPath)); String name = FilenameUtils.getName(path); this.svnClient.add(destPath + name); } } catch (Exception e) { e.printStackTrace(); return false; } return true; }
From source file:ca.on.oicr.pde.workflows.GATKGenotypeGVCFsWorkflow.java
@Override public Map<String, SqwFile> setupFiles() { List<String> inputFilesList = Arrays.asList(StringUtils.split(getProperty("input_files"), ",")); Set<String> inputFilesSet = new HashSet<>(inputFilesList); if (inputFilesList.size() != inputFilesSet.size()) { throw new RuntimeException("Duplicate files detected in input_files"); }/*ww w .j ava 2 s . c o m*/ if ((inputFilesSet.size() % 2) != 0) { throw new RuntimeException("Each GVCF should have a corresponding index"); } Map<String, String> gvcfs = new HashMap<>(); Map<String, String> gvcfIndexes = new HashMap<>(); for (String f : inputFilesSet) { if (f == null || f.isEmpty()) { } else if (f.endsWith("g.vcf.gz")) { gvcfs.put(StringUtils.removeEnd(f, "g.vcf.gz"), f); } else if (f.endsWith("g.vcf.gz.tbi")) { gvcfIndexes.put(StringUtils.removeEnd(f, "g.vcf.gz.tbi"), f); } else { throw new RuntimeException("Unsupported input file: [" + f + "]"); } } int id = 0; for (Entry<String, String> e : gvcfs.entrySet()) { String key = e.getKey(); String gvcfFilePath = e.getValue(); String gvcfIndexFilePath = gvcfIndexes.get(key); if (gvcfIndexFilePath == null) { throw new RuntimeException("Missing index for " + FilenameUtils.getName(gvcfFilePath)); } SqwFile gvcf = this.createFile("file_in_" + id++); gvcf.setSourcePath(gvcfFilePath); gvcf.setType("application/g-vcf-gz"); gvcf.setIsInput(true); SqwFile gvcfIndex = this.createFile("file_in_" + id++); gvcfIndex.setSourcePath(gvcfIndexFilePath); gvcfIndex.setType("application/tbi"); gvcfIndex.setIsInput(true); //FIXME: this seems to work for now, it would be better to be able to set the provisionedPath as //bai.getProvisionedPath != bai.getOutputPath ... //at least with seqware 1.1.0, setting output path changes where the output file will be stored, //but the commonly used get provisioned path will return the incorrect path to the file gvcfIndex.setOutputPath(FilenameUtils.getPath(gvcf.getProvisionedPath())); inputFiles.add(gvcf.getProvisionedPath()); } return this.getFiles(); }
From source file:com.atlassian.theplugin.util.CodeNavigationUtil.java
/** * Note: must be run from event dispatch thread or inside read-action only! * * @param project project//from w w w .j a va 2 s. c om * @param filePath filePath * @return collection of matching PsiFiles */ @Nullable public static Collection<PsiFile> findPsiFiles(final Project project, final String filePath) { // find files (do not care about path - IDEA7 compatibility) final PsiFile[] psifiles = IdeaVersionFacade.getInstance().getFiles(FilenameUtils.getName(filePath), project); return CodeNavigationUtil.getMatchingFiles(filePath, psifiles); }
From source file:io.github.retz.cli.CommandGetFile.java
@Override public int handle(ClientCLIConfig fileConfig, boolean verbose) throws Throwable { LOG.debug("Configuration: {}", fileConfig.toString()); try (Client webClient = Client.newBuilder(fileConfig.getUri()) .setAuthenticator(fileConfig.getAuthenticator()).checkCert(!fileConfig.insecure()) .setVerboseLog(verbose).build()) { if (verbose) { LOG.info("Getting file {} (offset={}, length={}) of a job(id={})", filename, offset, length, id); }/*from ww w . j a v a2 s . c o m*/ if (isBinary) { if ("-".equals(resultDir)) { LOG.error("--binary must be with -R option, to download the file."); return -1; } else if (poll) { LOG.error("--binary cannot work with --poll"); return -1; } String fullpath = FilenameUtils.concat(resultDir, FilenameUtils.getName(filename)); LOG.info("Binary mode: ignoring offset and length but downloading while file to '{}/{}'.", resultDir, filename); try (FileOutputStream out = new FileOutputStream(fullpath)) { ClientHelper.getWholeBinaryFile(webClient, id, filename, out); return 0; } } Date start = Calendar.getInstance().getTime(); Callable<Boolean> timedout; if (timeout > 0) { timedout = () -> { Date now = Calendar.getInstance().getTime(); long diff = now.getTime() - start.getTime(); return diff / 60 > timeout * 60; }; } else { timedout = () -> false; } OutputStream out = this.tentativeOutputStream(webClient, resultDir, filename); if (length < 0) { try { ClientHelper.getWholeFileWithTerminator(webClient, id, filename, poll, out, timedout); } catch (TimeoutException e) { webClient.kill(id); LOG.error("Job(id={}) has been killed due to timeout after {} minute(s)", id, timeout); return -1; } return 0; } Response res = webClient.getFile(id, filename, offset, length); if (res instanceof GetFileResponse) { GetFileResponse getFileResponse = (GetFileResponse) res; if (getFileResponse.job().isPresent()) { Job job = getFileResponse.job().get(); if (getFileResponse.file().isPresent()) { if (verbose) { LOG.info("offset={}", getFileResponse.file().get().offset()); } out.write(getFileResponse.file().get().data().getBytes(UTF_8)); } else if (verbose) { LOG.info("Job: {}", job); } if (out != null && "-".equals(resultDir)) { out.close(); } return 0; } else { LOG.error("No such job: id={}", id); } } else { ErrorResponse errorResponse = (ErrorResponse) res; LOG.error("Error: {}", errorResponse.status()); } } return -1; }
From source file:dynamicrefactoring.domain.TestExport.java
/** * Comprueba que el proceso de exportacin de la refactorizacin dinmica * Rename Class a un directorio temporal "./temp" se ha realizado * correctamente.//from ww w . j a v a 2 s .c om * * @throws XMLRefactoringReaderException * XMLRefactoringReaderException. * @throws IOException * IOException. */ @Test public void testExportRefactoring() throws XMLRefactoringReaderException, IOException { // Primero exportamos la refactorizacin Rename Class a un directorio // temporal que luego eliminaremos ExportImportUtilities.exportRefactoring(TEMP_DIR, RENAME_CLASS_XML_FILE, false); JDOMXMLRefactoringReaderImp reader = new JDOMXMLRefactoringReaderImp(); for (String element : RefactoringMechanismInstance.getMechanismListClassNames( reader.getDynamicRefactoringDefinition(new File(RENAME_CLASS_XML_FILE)).getAllMechanisms())) { String name = FilenameUtils.getName(PluginStringUtils.splitGetLast(element, ".")); String namefolder = FilenameUtils.getName(new File(RENAME_CLASS_XML_FILE).getParent()); File resultFile = new File( TEMP_DIR + File.separatorChar + namefolder + File.separatorChar + name + ".class"); assertEquals(true, resultFile.exists()); } }
From source file:edu.wisc.doit.tcrypt.controller.EncryptController.java
@RequestMapping(value = "/encryptFile", method = RequestMethod.POST) public ModelAndView encryptFile(@RequestParam("fileToEncrypt") MultipartFile file, @RequestParam("selectedServiceName") String serviceName, HttpServletResponse response) throws Exception { if (file.isEmpty()) { ModelAndView modelAndView = encryptTextInit(); modelAndView.addObject("selectedServiceName", serviceName); return modelAndView; }//w ww . j av a 2 s . c o m final FileEncrypter fileEncrypter = this.getFileEncrypter(serviceName); final String filename = FilenameUtils.getName(file.getOriginalFilename()); response.setHeader("Content-Type", "application/x-tar"); response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + ".tar" + "\""); final long size = file.getSize(); try (final InputStream inputStream = file.getInputStream(); final ServletOutputStream outputStream = response.getOutputStream()) { fileEncrypter.encrypt(filename, (int) size, inputStream, outputStream); } return null; }
From source file:ca.on.oicr.pde.workflows.GATKHaplotypeCallerWorkflow.java
@Override public Map<String, SqwFile> setupFiles() { List<String> inputFilesList = Arrays.asList(StringUtils.split(getProperty("input_files"), ",")); Set<String> inputFilesSet = new HashSet<>(inputFilesList); if (inputFilesList.size() != inputFilesSet.size()) { throw new RuntimeException("Duplicate files detected in input_files"); }// w w w .j a v a 2 s .co m if ((inputFilesSet.size() % 2) != 0) { throw new RuntimeException("Each bam should have a corresponding index"); } Map<String, String> bams = new HashMap<>(); Map<String, String> bais = new HashMap<>(); for (String f : inputFilesSet) { String fileExtension = FilenameUtils.getExtension(f); String fileKey = FilenameUtils.removeExtension(f); if (null != fileExtension) { switch (fileExtension) { case "bam": bams.put(fileKey, f); break; case "bai": if (fileKey.endsWith(".bam")) { fileKey = FilenameUtils.removeExtension(fileKey); } bais.put(fileKey, f); break; default: throw new RuntimeException("Unsupported input file type"); } } } int id = 0; for (Entry<String, String> e : bams.entrySet()) { String key = e.getKey(); String bamFilePath = e.getValue(); String baiFilePath = bais.get(key); if (baiFilePath == null) { throw new RuntimeException("Missing index for " + FilenameUtils.getName(bamFilePath)); } SqwFile bam = this.createFile("file_in_" + id++); bam.setSourcePath(bamFilePath); bam.setType("application/bam"); bam.setIsInput(true); SqwFile bai = this.createFile("file_in_" + id++); bai.setSourcePath(baiFilePath); bai.setType("application/bam-index"); bai.setIsInput(true); //FIXME: this seems to work for now, it would be better to be able to set the provisionedPath as //bai.getProvisionedPath != bai.getOutputPath ... //at least with seqware 1.1.0, setting output path changes where the output file will be stored, //but the commonly used get provisioned path will return the incorrect path to the file bai.setOutputPath(FilenameUtils.getPath(bam.getProvisionedPath())); inputBamFiles.add(bam.getProvisionedPath()); } return this.getFiles(); }
From source file:ddf.catalog.source.solr.ConfigurationFileProxy.java
/** * Writes the solr configuration files out of the bundle onto the disk. This method requires * that the dataDirectoryPath has been set. If the code is run in an OSGi container, it will * automatically have a default dataDirectory location set and will not require setting * dataDirectory ahead of time.//from w w w. j a v a 2s. com */ public void writeBundleFilesTo(File configDir) { if (bundleContext != null && configDir != null) { boolean directoriesMade = configDir.mkdirs(); LOGGER.info("Solr Config directories made? " + directoriesMade); @SuppressWarnings("rawtypes") Enumeration entries = bundleContext.getBundle().findEntries(SOLR_CONFIG_LOCATION_IN_BUNDLE, "*.*", false); while (entries.hasMoreElements()) { URL resourceURL = (URL) (entries.nextElement()); LOGGER.debug("Found " + resourceURL); InputStream inputStream = null; try { inputStream = resourceURL.openStream(); String fileName = FilenameUtils.getName(resourceURL.getPath()); File currentFile = new File(configDir, fileName); if (!currentFile.exists()) { FileOutputStream outputStream = null; try { outputStream = new FileOutputStream(currentFile); long byteCount = IOUtils.copyLarge(inputStream, outputStream); LOGGER.debug("Wrote out " + byteCount + " bytes."); } finally { IOUtils.closeQuietly(outputStream); } } } catch (IOException e) { LOGGER.warn(e); } finally { IOUtils.closeQuietly(inputStream); } } } }
From source file:de.mpg.imeji.logic.item.ItemController.java
@Override public List<Item> updateBatch(List<Item> l, User user) throws ImejiException { if (l != null && !l.isEmpty()) { for (final Item item : l) { prepareUpdate(item, user);/*from www.j a va2 s .c o m*/ item.setFilename(FilenameUtils.getName(item.getFilename())); } cleanItem(l); createMissingStatement(l); validateMetadata(l, Method.UPDATE); WRITER.update(J2JHelper.cast2ObjectList(l), user, true); } return l; }
From source file:com.epam.ngb.cli.TestHttpServer.java
/** * Enables file registration on the server *//*from w w w .j a v a 2s .co m*/ public void addFileRegistration(Long refId, String path, String index, String name, Long fileId, Long fileBioId, BiologicalDataItemFormat format) { onRequest().havingMethodEqualTo(HTTP_POST) .havingPathEqualTo(String.format(REGISTRATION_URL, format.name().toLowerCase())) .havingBodyEqualTo(TestDataProvider.getRegistrationJson(refId, path, name, index, null)).respond() .withBody(TestDataProvider.getFilePayloadJson(fileId, fileBioId, format, path, name == null ? FilenameUtils.getName(path) : name)) .withStatus(HTTP_STATUS_OK); }