List of usage examples for org.apache.commons.io FilenameUtils getName
public static String getName(String filename)
From source file:DownloadFileFromURL.java
public static void main(String[] args) throws Exception { urlList.add("http://downloads.solarwinds.com/solarwinds/Release/Management/pg11.TXT"); urlList.add("http://downloads.solarwinds.com/solarwinds/Release/Management/lorem.TXT"); urlList.add("http://downloads.solarwinds.com/solarwinds/Release/Management/pg1661.TXT"); urlList.add("http://downloads.solarwinds.com/solarwinds/Release/Management/cacerts"); urlList.add("http://downloads.solarwinds.com/solarwinds/Release/Management/eula.rtf"); urlList.add("http://downloads.solarwinds.com/solarwinds/Release/Management/Story.JPG"); urlList.add("http://downloads.solarwinds.com/solarwinds/Release/Management/solarwinds.png"); for (int iUrl = 0; iUrl < urlList.size(); iUrl++) { try {/*from w w w . j a v a 2 s .com*/ String urlString = urlList.get(iUrl); //All File Locations go here url = new URL(urlString); } catch (MalformedURLException ex) { Logger.getLogger(DownloadFileFromURL.class.getName()).log(Level.SEVERE, null, ex); } try { // open all the url connections here. con = url.openConnection(); } catch (IOException ex) { Logger.getLogger(DownloadFileFromURL.class.getName()).log(Level.SEVERE, null, ex); } dis = new DataInputStream(con.getInputStream()); fileData = new byte[con.getContentLength()]; for (int q = 0; q < fileData.length; q++) { fileData[q] = dis.readByte(); } dis.close(); // close the data input stream String fName = FilenameUtils.getName(url.getPath()); fos = new FileOutputStream(new File(fName)); //FILE Save Location goes here fos.write(fileData); // write out the file we want to save. fos.close(); // close the output stream writer } // end of for }
From source file:es.uam.eps.ir.ranksys.examples.RerankerExample.java
public static void main(String[] args) throws Exception { String trainDataPath = args[0]; String featurePath = args[1]; String recIn = args[2];// w w w. j av a2 s . c o m int cutoff = 100; PreferenceData<Long, Long> trainData = SimplePreferenceData .load(SimpleRatingPreferencesReader.get().read(trainDataPath, lp, lp)); FeatureData<Long, String, Double> featureData = SimpleFeatureData .load(SimpleFeaturesReader.get().read(featurePath, lp, sp)); Map<String, Supplier<Reranker<Long, Long>>> rerankersMap = new HashMap<>(); rerankersMap.put("MMR", () -> { double lambda = 0.5; ItemDistanceModel<Long> dist = new JaccardFeatureItemDistanceModel<>(featureData); return new MMR<>(lambda, cutoff, dist); }); rerankersMap.put("xQuAD", () -> { double lambda = 0.5; IntentModel<Long, Long, String> intentModel = new FeatureIntentModel<>(trainData, featureData); AspectModel<Long, Long, String> aspectModel = new ScoresAspectModel<>(intentModel); return new XQuAD<>(aspectModel, lambda, cutoff, true); }); rerankersMap.put("RxQuAD", () -> { double alpha = 0.5; double lambda = 0.5; IntentModel<Long, Long, String> intentModel = new FeatureIntentModel<>(trainData, featureData); AspectModel<Long, Long, String> aspectModel = new ScoresRelevanceAspectModel<>(intentModel); return new AlphaXQuAD<>(aspectModel, alpha, lambda, cutoff, true); }); rerankersMap.put("PM", () -> { double alpha = 0.5; double lambda = 0.9; BinomialModel<Long, Long, String> binomialModel = new BinomialModel<>(false, Stream.empty(), trainData, featureData, alpha); return new PM<>(featureData, binomialModel, lambda, cutoff); }); RecommendationFormat<Long, Long> format = new SimpleRecommendationFormat<>(lp, lp); rerankersMap.forEach(Unchecked.biConsumer((name, rerankerSupplier) -> { String recOut = Paths.get(Paths.get(recIn).getParent().toString(), String.format("%s-%s", name, FilenameUtils.getName(recIn))).toString(); System.out.printf("running %s, output to %s\n", name, recOut); Reranker<Long, Long> reranker = rerankerSupplier.get(); try (RecommendationFormat.Writer<Long, Long> writer = format.getWriter(recOut)) { format.getReader(recIn).readAll().map(rec -> reranker.rerankRecommendation(rec, cutoff)) .forEach(Unchecked.consumer(writer::write)); } })); }
From source file:dataflow.examples.TransferFiles.java
public static void main(String[] args) throws IOException, URISyntaxException { Options options = PipelineOptionsFactory.fromArgs(args).withValidation().as(Options.class); List<FilePair> filePairs = new ArrayList<FilePair>(); URI ftpInput = new URI(options.getInput()); FTPClient ftp = new FTPClient(); ftp.connect(ftpInput.getHost());/*from w w w .j ava2s. c o m*/ // After connection attempt, you should check the reply code to verify // success. int reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { ftp.disconnect(); logger.error("FTP server refused connection."); throw new RuntimeException("FTP server refused connection."); } ftp.login("anonymous", "someemail@gmail.com"); String ftpPath = ftpInput.getPath(); FTPFile[] files = ftp.listFiles(ftpPath); URI gcsUri = null; if (options.getOutput().endsWith("/")) { gcsUri = new URI(options.getOutput()); } else { gcsUri = new URI(options.getOutput() + "/"); } for (FTPFile f : files) { logger.info("File: " + f.getName()); FilePair p = new FilePair(); p.server = ftpInput.getHost(); p.ftpPath = f.getName(); // URI ftpURI = new URI("ftp", p.server, f.getName(), ""); p.gcsPath = gcsUri.resolve(FilenameUtils.getName(f.getName())).toString(); filePairs.add(p); } ftp.logout(); Pipeline p = Pipeline.create(options); PCollection<FilePair> inputs = p.apply(Create.of(filePairs)); inputs.apply(ParDo.of(new FTPToGCS()).named("CopyToGCS")) .apply(AvroIO.Write.withSchema(FilePair.class).to(options.getOutput())); p.run(); }
From source file:com.kamike.misc.FsNameUtils.java
public static String getName(String prefix, String disk, String filename, String fid, String uid) { String name = FilenameUtils.getName(filename); Date date = new Date(System.currentTimeMillis()); String extension = FilenameUtils.getExtension(name); return getName(prefix, disk, getShortDate(date), name, fid, uid, extension); }
From source file:jodtemplate.util.Utils.java
public static String getRelsPath(final String path) { final String fullPath = FilenameUtils.getFullPath(path); final String fileName = FilenameUtils.getName(path); return fullPath + "_rels/" + fileName + ".rels"; }
From source file:com.streamsets.pipeline.lib.el.FileEL.java
@ElFunction(prefix = "file", name = "fileName", description = "Returns just file name from given path.") public static String fileName(@ElParam("filePath") String filePath) { if (isEmpty(filePath)) { return null; }//from w w w. j a va 2s . c o m return FilenameUtils.getName(filePath); }
From source file:ch.cyberduck.core.PathNormalizer.java
public static String name(final String path) { final String normalized = normalize(path, true); if (String.valueOf(Path.DELIMITER).equals(normalized)) { return path; }//from w w w. j av a 2 s . com return FilenameUtils.getName(normalized); }
From source file:com.splunk.shuttl.archiver.util.UtilsPath.java
public static String getNameOfPath(String path) { return FilenameUtils.getName(FilenameUtils.normalizeNoEndSeparator(path)); }
From source file:com.fileOperations.TXTtoPDF.java
/** * creates PDF from text document//ww w .j a v a 2 s .com * * @param filePath String * @param fileName String * @return String - new File Name */ public static String createPDF(String filePath, String fileName) { String txtFile = filePath + fileName; String pdfFile = filePath + FilenameUtils.removeExtension(fileName) + ".pdf"; File attachmentLocation = new File(filePath); if (!attachmentLocation.exists()) { attachmentLocation.mkdirs(); } makePDF(pdfFile, getTextfromTXT(txtFile)); new File(txtFile).delete(); return FilenameUtils.getName(pdfFile); }
From source file:net.grinder.util.GrinderClassPathUtils.java
/** * Construct classPath for grinder from given classpath string. * // ww w. ja va 2s. com * @param classPath * classpath string * @param logger * logger * @return classpath optimized for grinder. */ public static String filterClassPath(String classPath, Logger logger) { List<String> classPathList = new ArrayList<String>(); for (String eachClassPath : checkNotNull(classPath).split(File.pathSeparator)) { String filename = FilenameUtils.getName(eachClassPath); if (isNotJarOrUselessJar(filename)) { continue; } logger.trace("classpath :" + eachClassPath); classPathList.add(eachClassPath); } return StringUtils.join(classPathList, File.pathSeparator); }