List of usage examples for org.apache.commons.io FilenameUtils getBaseName
public static String getBaseName(String filename)
From source file:MSUmpire.BaseDataStructure.InstrumentParameter.java
public void WriteParamSerialization(String mzXMLFileName) { try {//from w ww. ja v a 2 s .c o m Logger.getRootLogger().info("Writing parameter to file:" + FilenameUtils.getFullPath(mzXMLFileName) + FilenameUtils.getBaseName(mzXMLFileName) + "_params.ser..."); FileOutputStream fout = new FileOutputStream(FilenameUtils.getFullPath(mzXMLFileName) + FilenameUtils.getBaseName(mzXMLFileName) + "_params.ser", false); ObjectOutputStream oos = new ObjectOutputStream(fout); oos.writeObject(this); oos.close(); fout.close(); } catch (Exception ex) { Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex)); } }
From source file:MSUmpire.DIA.RTMappingExtLib.java
private void GenerateRTMapPNG(XYSeriesCollection xySeriesCollection, XYSeries series, float R2) throws IOException { String pngfile = FilenameUtils.getFullPath(TargetLCMS.mzXMLFileName) + "/" + FilenameUtils.getBaseName(TargetLCMS.mzXMLFileName) + "_" + libManager.LibID + "_RTMap.png"; FileWriter writer = new FileWriter(FilenameUtils.getFullPath(TargetLCMS.mzXMLFileName) + "/" + FilenameUtils.getBaseName(TargetLCMS.mzXMLFileName) + "_" + libManager.LibID + "_RTMap.txt"); XYSeries smoothline = new XYSeries("RT fitting curve"); for (XYZData data : regression.PredictYList) { smoothline.add(data.getX(), data.getY()); writer.write(data.getX() + "\t" + data.getY() + "\n"); }// w ww .java 2s. co m writer.close(); xySeriesCollection.addSeries(smoothline); xySeriesCollection.addSeries(series); JFreeChart chart = ChartFactory.createScatterPlot("Retention time mapping: R2=" + R2, "Normalized RT (" + libManager.LibID + ")", "RT:" + FilenameUtils.getBaseName(TargetLCMS.mzXMLFileName), xySeriesCollection, PlotOrientation.VERTICAL, true, true, false); XYPlot xyPlot = (XYPlot) chart.getPlot(); xyPlot.setDomainCrosshairVisible(true); xyPlot.setRangeCrosshairVisible(true); XYItemRenderer renderer = xyPlot.getRenderer(); renderer.setSeriesPaint(1, Color.blue); renderer.setSeriesPaint(0, Color.BLACK); renderer.setSeriesShape(1, new Ellipse2D.Double(0, 0, 3, 3)); renderer.setSeriesStroke(1, new BasicStroke(3.0f)); renderer.setSeriesStroke(0, new BasicStroke(3.0f)); xyPlot.setBackgroundPaint(Color.white); ChartUtilities.saveChartAsPNG(new File(pngfile), chart, 1000, 600); }
From source file:com.orange.wro.taglib.config.WroConfig.java
/** * TODO: we could use the property file generated by the "groupNameMappingFile" * maven configuration property./*from ww w .j ava 2 s. c o m*/ * However, it's difficult to make it work with WTP and m2e-wro4j eclipse plugin. */ private void loadMinimizedFiles() { @SuppressWarnings("unchecked") Set<String> resourcePaths = servletContext.getResourcePaths(options.getWroBaseUrl()); if (resourcePaths == null) { return; } for (String path : resourcePaths) { String basename = FilenameUtils.getBaseName(path); // We don't add '-min' to our files, but I think thats what the substring was for. String groupName = basename.replace("-min", ""); if (groups.containsKey(groupName)) { String type = FilenameUtils.getExtension(path); FilesGroup group = groups.get(groupName); group.putMinimizedFile(ResourceType.get(type), path); } } }
From source file:com.tocsi.images.ImageListBean.java
public void handleFileUpload(FileUploadEvent event) { if (event.getFile() != null) { try {//from ww w . j a v a 2 s. c o m UploadedFile uf = (UploadedFile) event.getFile(); File folder = new File(GlobalsBean.destOriginal); //File folderThumb = new File(destThumbnail); String filename = FilenameUtils.getBaseName(uf.getFileName()); String extension = FilenameUtils.getExtension(uf.getFileName()); File file = File.createTempFile(filename + "-", "." + extension, folder); //File fileThumb = File.createTempFile(filename + "-", "." + extension, folderThumb); //resize image here BufferedImage originalImage = ImageIO.read(uf.getInputstream()); InputStream is = uf.getInputstream(); if (originalImage.getWidth() > 700) { //resize image if image's width excess 700px BufferedImage origImage = Scalr.resize(originalImage, Scalr.Method.QUALITY, Scalr.Mode.FIT_TO_WIDTH, 640, (int) ((originalImage.getHeight() / ((double) (originalImage.getWidth() / 700.0)))), Scalr.OP_ANTIALIAS); ByteArrayOutputStream os = new ByteArrayOutputStream(); ImageIO.write(origImage, extension, os); is = new ByteArrayInputStream(os.toByteArray()); } //create thumbnail BufferedImage thumbnail = Scalr.resize(ImageIO.read(uf.getInputstream()), 150); ByteArrayOutputStream osThumb = new ByteArrayOutputStream(); ImageIO.write(thumbnail, extension, osThumb); InputStream isThumbnail = new ByteArrayInputStream(osThumb.toByteArray()); try (InputStream input = is) { Files.copy(input, file.toPath(), StandardCopyOption.REPLACE_EXISTING); } try (InputStream input = isThumbnail) { Files.copy(input, Paths.get(GlobalsBean.destThumbnail + GlobalsBean.separator + file.getName()), StandardCopyOption.REPLACE_EXISTING); } //File chartFile = new File(file.getAbsolutePath()); //chart = new DefaultStreamedContent(new FileInputStream(chartFile), "image/jpg"); ImageBean ib = new ImageBean(); ib.setFilename(file.getName()); ib.setThumbFile(file.getName()); ib.setImageFileLocation(GlobalsBean.destOriginal + GlobalsBean.separator + file.getName()); imageList.add(ib); } catch (IOException | IllegalArgumentException | ImagingOpException ex) { Utilities.displayError(ex.getMessage()); } } }
From source file:com.hightern.fckeditor.tool.UtilsFile.java
/** * Iterates over a base name and returns the first non-existent file.<br /> * This method extracts a file's base name, iterates over it until the first non-existent appearance with <code>basename(n).ext</code>. Where n is a positive integer starting from one. * //w w w.j a v a 2 s . co m * @param file * base file * @return first non-existent file */ public static File getUniqueFile(final File file) { if (!file.exists()) { return file; } File tmpFile = new File(file.getAbsolutePath()); final File parentDir = tmpFile.getParentFile(); int count = 1; final String extension = FilenameUtils.getExtension(tmpFile.getName()); final String baseName = FilenameUtils.getBaseName(tmpFile.getName()); do { tmpFile = new File(parentDir, baseName + "(" + count++ + ")." + extension); } while (tmpFile.exists()); return tmpFile; }
From source file:edu.si.services.beans.edansidora.IdsPushBean.java
public void createAndPush(Exchange exchange) throws EdanIdsException { try {/* w w w. ja v a 2 s .c o m*/ out = exchange.getIn(); inputLocation = new File(out.getHeader("CamelFileAbsolutePath", String.class)); // get a list of files from current directory if (inputLocation.isFile()) { inputLocation = inputLocation.getParentFile(); LOG.debug("Input File Location: " + inputLocation); } deploymentId = out.getHeader("SiteId", String.class); String assetName = "ExportEmammal_emammal_image_" + deploymentId; String pushDirPath = pushLocation + "/" + assetName + "/"; File assetXmlFile = new File(pushDirPath + assetName + ".xml"); if (!assetXmlFile.getParentFile().exists()) { assetXmlFile.getParentFile().mkdirs(); } else { LOG.warn("IDS files for deployment: {} already exists!!", deploymentId); } LOG.debug("IDS Write Asset Files to: {}", assetXmlFile); LOG.debug("IDS inputLocation = {}", inputLocation); LOG.debug("IDS deploymentId = {}", deploymentId); File files[] = inputLocation.listFiles(); LOG.debug("Input file list: " + Arrays.toString(files)); int completed = 0; StringBuilder assetXml = new StringBuilder(); assetXml.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n<Assets>"); try (BufferedWriter writer = new BufferedWriter(new FileWriter(assetXmlFile))) { for (int i = 0; i < files.length; i++) { String fileName = files[i].getName(); LOG.debug("Started file: {} has ext = {}", files[i], FilenameUtils.getExtension(fileName)); // Do not include the manifest file if (!FilenameUtils.getExtension(fileName).contains("xml") && !ignored.containsKey(FilenameUtils.getBaseName(fileName))) { LOG.debug("Adding File {}", fileName); File sourceImageFile = new File(files[i].getPath()); File destImageFile = new File(pushDirPath + "emammal_image_" + fileName); LOG.debug("Copying image asset from {} to {}", sourceImageFile, destImageFile); FileUtils.copyFile(sourceImageFile, destImageFile); assetXml.append("\r\n <Asset Name=\""); assetXml.append(FilenameUtils.getName(destImageFile.getPath())); assetXml.append( "\" IsPublic=\"Yes\" IsInternal=\"No\" MaxSize=\"3000\" InternalMaxSize=\"4000\">"); assetXml.append(FilenameUtils.getBaseName(destImageFile.getPath())); assetXml.append("</Asset>"); } else { LOG.debug("Deployment Manifest XML Found! Skipping {}", files[i]); } } assetXml.append("\r\n</Assets>"); writer.write(assetXml.toString()); LOG.info("Completed: {} of {}, Wrote Asset XML File to: {}", completed++, files.length, assetXmlFile); out.setHeader("idsPushDir", assetXmlFile.getParent()); } catch (Exception e) { throw new EdanIdsException("IdsPushBean error during createAndPush", e); } } catch (Exception e) { throw new EdanIdsException(e); } }
From source file:edu.jhuapl.openessence.config.AppInitializer.java
private List<PropertySource<?>> getPropertySources(Collection<Resource> resources) { List<PropertySource<?>> propertySources = new ArrayList<PropertySource<?>>(); for (Resource r : resources) { String filename = r.getFilename(); if (filename == null) { throw new IllegalArgumentException("Cannot have resource with no file"); }/*from w w w .j a v a 2 s . c om*/ String name = FilenameUtils.getBaseName(r.getFilename()); Properties source; try { source = PropertiesLoaderUtils.loadProperties(r); } catch (IOException e) { throw new IllegalStateException(e); } propertySources.add(new PropertiesPropertySource(name, source)); try { log.info("Adding file {} as property source named '{}'", r.getFile(), name); } catch (IOException e) { throw new IllegalStateException(e); } } return propertySources; }
From source file:de.uzk.hki.da.convert.TiffConversionStrategy.java
@Override public List<Event> convertFile(WorkArea wa, ConversionInstruction ci) { List<Event> resultEvents = new ArrayList<Event>(); String input = wa.toFile(ci.getSource_file()).getAbsolutePath(); String[] commandAsArray;/*from ww w . j a v a 2 s . c o m*/ String prunedError = ""; FormatCmdLineExecutor cle = new FormatCmdLineExecutor(cliConnector, knownErrors); try { // Codec identification is done by subformatidentification ImageMagickSubformatIdentifier imsf = new ImageMagickSubformatIdentifier(); imsf.setKnownFormatCommandLineErrors(knownErrors); imsf.setCliConnector(cliConnector); if (imsf.identify(new File(input), prune).indexOf("None") >= 0) return resultEvents; // create subfolder if necessary Path.make(wa.dataPath(), object.getNameOfLatestBRep(), ci.getTarget_folder()).toFile().mkdirs(); commandAsArray = new String[] { "convert", "+compress", input, generateTargetFilePath(wa, ci) }; logger.debug("Try to Execute conversion command: " + StringUtils.join(commandAsArray, ",")); cle.setPruneExceptions(prune); try { cle.execute(commandAsArray); } catch (UserFileFormatException ufe) { if (!ufe.isWasPruned()) throw ufe; prunedError = " " + ufe.getKnownError().getError_name() + " ISSUED WAS PRUNED BY USER!"; } } catch (IOException e1) { throw new RuntimeException(e1); } File result = new File(generateTargetFilePath(wa, ci)); String baseName = FilenameUtils.getBaseName(result.getAbsolutePath()); String extension = FilenameUtils.getExtension(result.getAbsolutePath()); logger.info("Finding files matching wildcard expression \"" + baseName + "*." + extension + "\" in order to check them and test if conversion was successful"); List<File> results = findFilesWithWildcard(new File(FilenameUtils.getFullPath(result.getAbsolutePath())), baseName + "*." + extension); for (File f : results) { DAFile daf = new DAFile(object.getNameOfLatestBRep(), StringUtilities.slashize(ci.getTarget_folder()) + f.getName()); logger.debug("new dafile:" + daf); Event e = new Event(); e.setType("CONVERT"); e.setDetail(StringUtilities.createString(commandAsArray) + prunedError); e.setSource_file(ci.getSource_file()); e.setTarget_file(daf); e.setDate(new Date()); resultEvents.add(e); } return resultEvents; }
From source file:com.doplgangr.secrecy.filesystem.encryption.AES_ECB_Crypter.java
@Override public String getDecryptedFileName(File file) throws SecrecyCipherStreamException, FileNotFoundException { String name = FilenameUtils.getBaseName(file.getName()); try {//from w w w . j av a2s . c o m name = Base64Coder.decodeString(name); //if name is invalid, return original name } catch (IllegalArgumentException ignored) { } name += "." + FilenameUtils.getExtension(file.getName()); return name; }
From source file:net.mitnet.tools.pdf.book.publisher.ui.gui.BaseBookPublisherGUI.java
protected void publishBook() { File inputDir = getInputDir(); File outputDir = getOutputDir(); File outputBookDir = getOutputDir().getParentFile(); String outputBookName = FilenameUtils.getBaseName(outputDir.getName()) + "-book" + FileExtensionConstants.PDF_EXTENSION; File outputBookFile = new File(outputBookDir, outputBookName); String metaTitle = null;// ww w .j ava 2s. c o m try { metaTitle = outputBookFile.getName(); metaTitle = FilenameUtils.getBaseName(metaTitle); } catch (Exception e) { System.err.println("Error defining meta title"); } String metaVersionId = "" + new Date().getTime(); System.out.println("Input dir is " + inputDir); System.out.println("Output dir is " + outputDir); System.out.println("Output book file is " + outputBookFile); if (inputDir.isDirectory() && outputDir.isDirectory()) { try { setStatusMessage("Publishing book ..."); System.out.println("Processing files in input dir " + inputDir + " ..."); BookPublisherConfig config = buildBookPublisherConfig(); config.setMetaTitle(metaTitle); config.setMetaVersionId(metaVersionId); BookPublisher bookPublisher = new BookPublisher(); bookPublisher.setConfig(config); bookPublisher.publish(inputDir, outputDir, outputBookFile); // setStatusMessage("Finished publishing book."); String fileName = outputBookFile.getName(); setStatusMessage("Finished publishing book " + fileName); } catch (Exception ex) { setStatusMessage("Error publishing book: " + ex.getMessage()); } } else { setStatusMessage("Source or output folder is invalid."); } }