List of usage examples for org.apache.commons.io FilenameUtils getBaseName
public static String getBaseName(String filename)
From source file:de.tudarmstadt.ukp.clarin.webanno.brat.dao.DaoUtilsTest.java
@SuppressWarnings("resource") @Test/*w w w. j a v a 2 s. c om*/ public void testZipFolder() { File toBeZippedFiles = new File("src/test/resources"); File zipedFiles = new File("target/" + toBeZippedFiles.getName() + ".zip"); try { ZipUtils.zipFolder(toBeZippedFiles, zipedFiles); } catch (Exception e) { LOG.info("Zipping fails" + ExceptionUtils.getRootCauseMessage(e)); } FileInputStream fs; try { fs = new FileInputStream(zipedFiles); ZipInputStream zis = new ZipInputStream(fs); ZipEntry zE; while ((zE = zis.getNextEntry()) != null) { for (File toBeZippedFile : toBeZippedFiles.listFiles()) { if ((FilenameUtils.getBaseName(toBeZippedFile.getName())) .equals(FilenameUtils.getBaseName(zE.getName()))) { // Extract the zip file, save it to temp and compare ZipFile zipFile = new ZipFile(zipedFiles); ZipEntry zipEntry = zipFile.getEntry(zE.getName()); InputStream is = zipFile.getInputStream(zipEntry); File temp = File.createTempFile("temp", ".txt"); OutputStream out = new FileOutputStream(temp); IOUtils.copy(is, out); FileUtils.contentEquals(toBeZippedFile, temp); } } zis.closeEntry(); } } catch (FileNotFoundException e) { LOG.info("zipped file not found " + ExceptionUtils.getRootCauseMessage(e)); } catch (IOException e) { LOG.info("Unable to get file " + ExceptionUtils.getRootCauseMessage(e)); } }
From source file:launcher.Download.java
/** * This method is for downloading a file from a URL. * @param fileurl The URL that the download needs to occur * @throws IOException /*from w ww. ja v a 2 s . com*/ */ public static void fileDownload(String fileurl) throws IOException { //init var URL dl = null; File fl = null; String x = null; OutputStream os = null; InputStream is = null; ProgressListener progressListener = new ProgressListener(); try { //string to the URL dl = new URL(fileurl); //grab file name String fileName = FilenameUtils.getBaseName(fileurl); String extension = FilenameUtils.getExtension(fileurl); //storage location fl = new File( System.getProperty("user.home").replace("\\", "/") + "/Desktop/" + fileName + "." + extension); //file stream output at storage location os = new FileOutputStream(fl); is = dl.openStream(); //new instance of DownloadCountingOutputStream DownloadCountingOutputStream dcount = new DownloadCountingOutputStream(os); dcount.setListener(progressListener); // this line give you the total length of source stream as a double. filesize = Double.parseDouble(dl.openConnection().getHeaderField("Content-Length")); //return filename filename = fileName; // begin transfer by writing to dcount for download progress count. *not os.* IOUtils.copy(is, dcount); } catch (Exception e) { System.out.println(e); } finally { if (os != null) { os.close(); } if (is != null) { is.close(); } } }
From source file:com.legstar.protobuf.cobol.AbstractTest.java
/** * This is our chance to remove reference files that are no longer used by a * test case. This happens when test cases are renamed or removed. * /* w w w. j a va 2 s. co m*/ * @throws IOException */ protected void cleanOldReferences() throws IOException { if (!getReferenceFolder().exists()) { return; } Method[] methods = getClass().getDeclaredMethods(); for (File refFile : FileUtils.listFiles(getReferenceFolder(), new String[] { REF_FILE_EXT }, false)) { boolean found = false; for (int i = 0; i < methods.length; i++) { if (methods[i].getName().equals(FilenameUtils.getBaseName(refFile.getName()))) { found = true; break; } } if (!found) { refFile.delete(); } } String[] dirs = getReferenceFolder().list(DirectoryFileFilter.INSTANCE); for (String dir : dirs) { boolean found = false; for (int i = 0; i < methods.length; i++) { if (methods[i].getName().equals(dir)) { found = true; break; } } if (!found && !dir.equals(".svn")) { FileUtils.deleteDirectory(new File(getReferenceFolder(), dir)); } } }
From source file:com.chingo247.structureapi.plan.document.PlanDocumentGenerator.java
public void generate(File targetFolder) { // Scan the folder called 'SchematicToPlan' for schematic files Iterator<File> it = FileUtils.iterateFiles(targetFolder, new String[] { "schematic" }, true); System.out.println("Files: " + targetFolder.listFiles().length); int count = 0; long start = System.currentTimeMillis(); // Generate Plans while (it.hasNext()) { File schematic = it.next(); Document d = DocumentHelper.createDocument(); d.addElement(Elements.ROOT).addElement(Elements.SETTLERCRAFT).addElement(Elements.SCHEMATIC) .setText(schematic.getName()); File plan = new File(schematic.getParent(), FilenameUtils.getBaseName(schematic.getName()) + ".xml"); try {/* ww w. ja v a2s. c om*/ XMLWriter writer = new XMLWriter(new FileWriter(plan)); writer.write(d); writer.close(); StructurePlan sp = new StructurePlan(); PlanDocument pd = new PlanDocument(structureAPI.getPlanDocumentManager(), plan); pd.putPluginElement("SettlerCraft", new PlanDocumentPluginElement("SettlerCraft", pd, (Element) d.selectSingleNode("StructurePlan/SettlerCraft"))); sp.load(pd); if (sp.getCategory().equals("Default") && !schematic.getParentFile().getName().equals(targetFolder.getName())) { sp.setCategory(schematic.getParentFile().getName()); } sp.save(); } catch (DocumentException ex) { Logger.getLogger(StructurePlanManager.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException | StructureDataException ex) { Logger.getLogger(StructurePlanManager.class.getName()).log(Level.SEVERE, null, ex); } count++; } if (count > 0) { StructureAPI.print("Generated " + count + " plans in " + (System.currentTimeMillis() - start) + "ms"); } }
From source file:net.pms.dlna.ZippedEntry.java
@Override public String getSystemName() { return FilenameUtils.getBaseName(file.getAbsolutePath()) + "." + FilenameUtils.getExtension(zeName); }
From source file:hudson.plugins.mercurial.MercurialSCMHeadEvent.java
@NonNull @Override// w w w . j a v a 2 s . co m public String getSourceName() { // doesn't matter what we return here as we never match a navigator. return FilenameUtils.getBaseName(payload.getUrl().getPath()); }
From source file:net.sf.jvifm.control.CopyCommand.java
protected void doFileOperator(String src, String dst, String fileName) throws Exception { if (Thread.currentThread().isInterrupted()) return;/*w ww . j a v a 2 s .c o m*/ String baseName = FilenameUtils.getName(src); updateStatusInfo("copying file " + baseName); // if is same file, make a copy if (fileModelManager.isSameFile(src, dst)) { dst = FilenameUtils.concat(dst, FilenameUtils.getBaseName(src) + "(1)." + FilenameUtils.getExtension(src)); new File(dst).createNewFile(); } fileModelManager.cp(src, dst); }
From source file:com.stanley.captioner.MainFrame.java
public void caption() { Converter converter = new Converter(); Configuration config = new Configuration(); config.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us"); config.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict"); config.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin"); for (int i = 0; i < videoTable.getRowCount(); i++) { String videoInPath = (String) videoTable.getValueAt(i, 0); File videoIn = new File(videoInPath); String videoInDirPath = videoIn.getParent(); String audioOutPath = FilenameUtils.concat(videoInDirPath, FilenameUtils.getBaseName(videoInPath) + ".wav"); File audioOut = new File(audioOutPath); tempFiles.add(audioOut);//from www.j a v a2s. c o m String outputPath = outputDirectoryField.getText(); String textOutPath = FilenameUtils.concat(outputPath, FilenameUtils.getBaseName(videoInPath) + ".txt"); File textOut = new File(textOutPath); String videoOutPath = FilenameUtils.concat(outputPath, FilenameUtils.getBaseName(videoInPath) + ".mp4"); File videoOut = new File(videoOutPath); System.out.println(videoInPath); System.out.println(audioOutPath); System.out.println(outputPath); System.out.println(textOutPath); System.out.println(videoOutPath); converter.videoToAudio(videoIn, audioOut); Transcriber transcriber = new Transcriber(audioOut, config, textOut, videoIn, quickTestCheckBox.isSelected()); transcriber.start(); //Converter.imagesFromVideo(videoIn); //Converter.videoFromImages(videoIn, videoOut); } }
From source file:com.frostwire.search.ScrapedTorrentFileSearchResult.java
public ScrapedTorrentFileSearchResult(T parent, String filePath, long fileSize, String referrerUrl, String cookie) {// w ww . j av a 2 s . c om super(parent); this.filePath = filePath; this.filename = FilenameUtils.getName(this.filePath); this.displayName = FilenameUtils.getBaseName(this.filename); this.referrerUrl = referrerUrl; this.cookie = cookie; this.size = fileSize; }
From source file:com.googlecode.dex2jar.tools.ApkSign.java
@Override protected void doCommandLine() throws Exception { if (remainingArgs.length != 1) { usage();//from www . j a v a 2 s. c o m return; } File apkIn = new File(remainingArgs[0]); if (!apkIn.exists()) { System.err.println(apkIn + " is not exists"); usage(); return; } if (output == null) { if (apkIn.isDirectory()) { output = new File(apkIn.getName() + "-signed.apk"); } else { output = new File(FilenameUtils.getBaseName(apkIn.getName()) + "-signed.apk"); } } if (output.exists() && !forceOverwrite) { System.err.println(output + " exists, use --force to overwrite"); usage(); return; } File realJar; if (apkIn.isDirectory()) { realJar = File.createTempFile("d2j", ".jar"); realJar.deleteOnExit(); System.out.println("zipping " + apkIn + " -> " + realJar); OutHandler out = FileOut.create(realJar, true); try { new FileWalker().withStreamHandler(new OutAdapter(out)).walk(apkIn); } finally { IOUtils.closeQuietly(out); } } else { realJar = apkIn; } CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate) certificateFactory .generateCertificate(ApkSign.class.getResourceAsStream("ApkSign.cer")); KeyFactory rSAKeyFactory = KeyFactory.getInstance("RSA"); PrivateKey privateKey = rSAKeyFactory.generatePrivate( new PKCS8EncodedKeySpec(IOUtils.toByteArray(ApkSign.class.getResourceAsStream("ApkSign.private")))); Class<?> clz; try { clz = Class.forName("com.android.signapk.SignApk"); } catch (ClassNotFoundException cnfe) { System.err.println("please run d2j-apk-sign in a sun compatible JRE (contains sun.security.*)"); return; } Method m = clz.getMethod("sign", X509Certificate.class, PrivateKey.class, boolean.class, File.class, File.class); m.setAccessible(true); System.out.println("sign " + realJar + " -> " + output); m.invoke(null, cert, privateKey, this.signWhole, realJar, output); }