List of usage examples for org.apache.commons.io FilenameUtils getBaseName
public static String getBaseName(String filename)
From source file:it.lufraproini.cms.servlet.upload_user_img.java
private Map prendiInfoFile(HttpServletRequest request) throws ErroreGrave, IOException { Map infofile = new HashMap(); //riutilizzo codice prof. Della Penna per l'upload if (ServletFileUpload.isMultipartContent(request)) { // Funzioni delle librerie Apache per l'upload try {/*from w ww . j a v a 2 s. c om*/ FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List<FileItem> items; FileItem file = null; items = upload.parseRequest(request); for (FileItem item : items) { String name = item.getFieldName(); if (name.equals("file_to_upload")) { file = item; break; } } if (file == null || file.getName().equals("")) { throw new ErroreGrave("la form non ha inviato il campo file!"); } else { //informazioni String nome_e_path = file.getName(); String estensione = FilenameUtils.getExtension(FilenameUtils.getName(nome_e_path)); String nome_senza_estensione = FilenameUtils.getBaseName(FilenameUtils.getName(nome_e_path)); infofile.put("nome_completo", nome_senza_estensione + "." + estensione); infofile.put("estensione", estensione); infofile.put("nome_senza_estensione", nome_senza_estensione); infofile.put("dimensione", file.getSize()); infofile.put("input_stream", file.getInputStream()); infofile.put("content_type", file.getContentType()); } } catch (FileUploadException ex) { Logger.getLogger(upload_user_img.class.getName()).log(Level.SEVERE, null, ex); throw new ErroreGrave("errore libreria apache!"); } } return infofile; }
From source file:bear.main.JavaCompiler2.java
public List<File> compileScripts(File sourcesDir) { FileFilter filter = new SuffixFileFilter(extensions); final File[] files = sourcesDir.listFiles(filter); final ArrayList<String> params = newArrayListWithExpectedSize(files.length); if (!buildDir.exists()) { buildDir.mkdir();/*from www . j av a 2 s. c o m*/ } Collections.addAll(params, "-d", buildDir.getAbsolutePath()); List<File> javaFilesList = newArrayList(files); List<File> filesListToCompile = ImmutableList.copyOf(Iterables.filter(javaFilesList, new Predicate<File>() { @Override public boolean apply(File javaFile) { File classFile = new File(buildDir, FilenameUtils.getBaseName(javaFile.getName()) + ".class"); boolean upToDate = classFile.exists() && classFile.lastModified() > javaFile.lastModified(); if (upToDate) { logger.info("{} is up-to-date", javaFile); } return !upToDate; } })); if (filesListToCompile.isEmpty()) { logger.info("all files are up-to-date"); return javaFilesList; } final List<String> filePaths = Lists.transform(filesListToCompile, new Function<File, String>() { public String apply(File input) { return input.getAbsolutePath(); } }); params.addAll(filePaths); logger.info("compiling {}", params); final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); final int r = compiler.run(null, null, null, params.toArray(new String[params.size()])); if (r == 0) { logger.info("compilation OK."); } else { logger.info("compilation failed."); } return javaFilesList; }
From source file:com.splunk.shuttl.archiver.listers.ArchiveBucketsLister.java
private Bucket createBucketFromUriToBucket(URI uriToBucket) { String bucketIndex = pathResolver.resolveIndexFromUriToBucket(uriToBucket); String bucketName = FilenameUtils.getBaseName(UtilsURI.getPathByTrimmingEndingFileSeparator(uriToBucket)); return this.createBucketWithErrorHandling(uriToBucket, bucketIndex, bucketName); }
From source file:de.fhg.iais.asc.sipmaker.SipMakerFileSearcher.java
private File findHighestVersion(File versionsPath) { File bestFile = null;// ww w . j av a2 s . c o m int best = -2; for (File file : getVersionFiles(versionsPath)) { int v = NumberUtils.toInt(FilenameUtils.getBaseName(file.getName()), -1); if (v > best) { bestFile = file; best = v; } } return bestFile; }
From source file:MSUmpire.DIA.DIAAssignQuantUnit.java
@Override public void run() { PeakCluster targetCluster = null;//from www . ja va 2s .c o m //Get highest intensity peak cluster for (PeakCluster peakCluster : pepIonID.MS1PeakClusters) { if (targetCluster == null || targetCluster.PeakHeight[0] < peakCluster.PeakHeight[0]) { targetCluster = peakCluster; } } pepIonID.CreateQuantInstance(ms1lcms.MaxNoPeakCluster); if (targetCluster != null) { pepIonID.PeakArea = targetCluster.PeakArea; pepIonID.PeakHeight = targetCluster.PeakHeight; pepIonID.PeakClusterScore = targetCluster.MS1Score; pepIonID.PeakRT = targetCluster.PeakHeightRT[0]; pepIonID.ObservedMz = targetCluster.mz[0]; } else { //if no MS1 peak cluster found, use MS2 unfragmented peak cluster instead for (PeakCluster peakCluster : pepIonID.MS2UnfragPeakClusters) { if (targetCluster == null || targetCluster.PeakHeight[0] < peakCluster.PeakHeight[0]) { targetCluster = peakCluster; } } if (targetCluster != null) { pepIonID.PeakRT = targetCluster.PeakHeightRT[0]; pepIonID.ObservedMz = targetCluster.mz[0]; } } //pepIonID.PeakClusterIndex = targetCluster.Index; if (targetCluster != null && ms1lcms.datattype != SpectralDataType.DataType.pSMART) { MatchFragmentByTargetCluster(targetCluster); pepIonID.RemoveRedundantFrag(); if (pepIonID.FragmentPeaks.isEmpty() && Math.max(pepIonID.MaxProbability, pepIonID.TargetedProbability()) > 0.8f) { Logger.getRootLogger() .warn("Warning: " + pepIonID.ModSequence + "(MaxProb: " + pepIonID.MaxProbability + ") does not have matched fragment in " + FilenameUtils.getBaseName(ms1lcms.ParentmzXMLName)); //MatchFragment(); } pepIonID.ClearPepFragFactory(); } }
From source file:me.jaimegarza.syntax.test.java.TestLalr.java
@Test public void test01WithExecute() throws ParsingException, AnalysisException, OutputException, MalformedURLException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException { generateLanguageFile(expandedArgs);/*from w w w. jav a 2s. c o m*/ File source = new File(tmpLanguageFile); File sourceDir = source.getParentFile(); CompilationResult result = compileJavaFile(source, sourceDir); if (result.getErrors().length > 0) { for (CompilationProblem cr : result.getErrors()) { System.err.println(cr); } } Assert.assertEquals(result.getErrors().length, 0, "Syntax errors found trying to execute"); URL urls[] = new URL[1]; urls[0] = sourceDir.toURI().toURL(); URLClassLoader classLoader = URLClassLoader.newInstance(urls, this.getClass().getClassLoader()); String className = FilenameUtils.getBaseName(tmpLanguageFile); Class<?> clazz = classLoader.loadClass(className); Object parser = clazz.newInstance(); Method setVerbose = parser.getClass().getMethod("setVerbose", boolean.class); Method parse = parser.getClass().getMethod("parse"); Method getExpr = parser.getClass().getMethod("getExpr"); setVerbose.invoke(parser, true); Object o = parse.invoke(parser); Assert.assertTrue(o instanceof Integer); int rc = (Integer) o; Assert.assertEquals(rc, 1, "Parse did not succeed"); o = getExpr.invoke(parser); Assert.assertTrue(o instanceof String); String s = (String) o; Assert.assertEquals(s, "(abc)d", "string does not match"); }
From source file:com.silverpeas.importExport.control.ImportSettings.java
public String getPublicationName(String filename) { if (settings.getBoolean("publication.name.with.extension", false)) { return filename; }//from w w w. j a v a 2 s . co m return FilenameUtils.getBaseName(filename); }
From source file:io.gravitee.repository.couchbase.management.AbstractCouchbaseDBTest.java
@Transactional private void importJsonFile(File file) { try {/* ww w . j a v a2 s . com*/ final String documentType = FilenameUtils.getBaseName(file.getName()); LOG.info("Inserting document of type {}", documentType); String jsonFileContent = FileUtils.readFileToString(file); if (jsonFileContent.startsWith("[")) { JsonArray jsonArray = JsonArray.fromJson(jsonFileContent); jsonArray.forEach(jsonObject -> { String id = ((JsonObject) jsonObject).getString("_id"); JsonDocument document = JsonDocument.create(id, (JsonObject) jsonObject); if (!bucket.exists(id)) { bucket.insert(document); } else { LOG.debug("Document already exist in bucket, skipping"); } }); } else { JsonObject jsonObject = JsonObject.fromJson(jsonFileContent); String id = jsonObject.getString("_id"); JsonDocument document = JsonDocument.create(id, jsonObject); if (!bucket.exists(id)) { bucket.insert(document); } else { LOG.debug("Document already exist in bucket, skipping"); } } } catch (DocumentAlreadyExistsException e) { LOG.debug("Document already exist in bucket, skipping"); } catch (Exception e) { LOG.error("Fail to insert document : ", e); } }
From source file:me.jaimegarza.syntax.test.java.TestJavaLexerModes.java
@Test public void testJavaLexerModes() throws ParsingException, AnalysisException, OutputException, MalformedURLException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException { generateLanguageFile(args);//from w w w . j a v a2s . c o m File source = new File(tmpLanguageFile); File sourceDir = source.getParentFile(); CompilationResult result = compileJavaFile(source, sourceDir); if (result.getErrors().length > 0) { for (CompilationProblem problemo : result.getErrors()) { if (problemo.isError()) { System.err.println(problemo.toString()); } } Assert.fail("Errors during the compilation of the output java file"); } URL urls[] = new URL[1]; urls[0] = sourceDir.toURI().toURL(); URLClassLoader classLoader = URLClassLoader.newInstance(urls, this.getClass().getClassLoader()); String className = FilenameUtils.getBaseName(tmpLanguageFile); Class<?> clazz = classLoader.loadClass(className); Object parser = clazz.newInstance(); //Method setVerbose = parser.getClass().getMethod("setVerbose", boolean.class); Method parse = parser.getClass().getMethod("parse"); Method getOutput = parser.getClass().getMethod("getOutput"); //setVerbose.invoke(parser, true); Object o = parse.invoke(parser); Assert.assertTrue(o instanceof Integer); int rc = (Integer) o; Assert.assertEquals(rc, 1, "Parse did not succeed"); o = getOutput.invoke(parser); Assert.assertTrue(o instanceof String); String s = (String) o; Assert.assertEquals(s, "bacaab", "string does not match"); }
From source file:me.jaimegarza.syntax.test.java.TestJavaRegexTokenizer.java
@Test public void test01WithExecute() throws ParsingException, AnalysisException, OutputException, MalformedURLException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException { generateLanguageFile(expandedArgs);//from ww w. j a va2 s .com File source = new File(tmpLanguageFile); File sourceDir = source.getParentFile(); CompilationResult result = compileJavaFile(source, sourceDir); if (result.getErrors().length > 0) { for (CompilationProblem cr : result.getErrors()) { System.err.println(cr); } } Assert.assertEquals(result.getErrors().length, 0, "Syntax errors found trying to execute"); URL urls[] = new URL[1]; urls[0] = sourceDir.toURI().toURL(); URLClassLoader classLoader = URLClassLoader.newInstance(urls, this.getClass().getClassLoader()); String className = FilenameUtils.getBaseName(tmpLanguageFile); Class<?> clazz = classLoader.loadClass(className); Object parser = clazz.newInstance(); //Method setVerbose = parser.getClass().getMethod("setVerbose", boolean.class); Method parse = parser.getClass().getMethod("parse"); Method getExpr = parser.getClass().getMethod("getExpr"); //setVerbose.invoke(parser, true); Object o = parse.invoke(parser); Assert.assertTrue(o instanceof Integer); int rc = (Integer) o; Assert.assertEquals(rc, 1, "Parse did not succeed"); o = getExpr.invoke(parser); Assert.assertTrue(o instanceof String); String s = (String) o; Assert.assertEquals(s, "EABCDFGIA", "string does not match"); }