List of usage examples for org.apache.commons.io FilenameUtils getFullPathNoEndSeparator
public static String getFullPathNoEndSeparator(String filename)
From source file:com.impetus.ankush.agent.AgentConf.java
/** * Load the properties from the default file. * //from w ww. ja v a 2 s . c o m * @throws IOException * * @throws FileNotFoundException */ public void load() throws IOException { File file = new File(fileName); if (!file.exists()) { String confPath = FilenameUtils.getFullPathNoEndSeparator(fileName); FileUtils.forceMkdir(new File(confPath)); FileUtils.touch(file); } this.properties = load(fileName); }
From source file:context.ui.control.workflow.WorkflowController.java
/** * * @param tabularOutput/*from ww w. j a v a 2s.c om*/ */ public void setTabularOutputDirectory(TabularData tabularOutput) { if (tabularOutput == null || tabularOutput.getPath() == null) { return; } String dirPath = FilenameUtils.getFullPathNoEndSeparator(tabularOutput.getPath().get()); basicOutputViewController.getOutputDirTextField().textProperty().set(dirPath); }
From source file:com.esri.geoevent.test.performance.report.XLSXReportWriter.java
@Override public void writeReport(String reportFile, List<String> testNames, List<String> columnNames, Map<String, List<FixtureStatistic>> stats) throws IOException { //create the parent directories - if needed createParentDirectoriesIfNeeded(reportFile); // rollover the file - keep backups rollOver(reportFile);/*from www .jav a2 s . co m*/ Workbook workbook = null; try { workbook = new XSSFWorkbook(); // header style CellStyle headerStyle = workbook.createCellStyle(); Font font = workbook.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); headerStyle.setFont(font); // copy the column names - add the test name as the first column List<String> columnNamesCopy = new ArrayList<String>(); columnNamesCopy.add("Test Name"); columnNamesCopy.addAll(columnNames); // create the sheet Sheet sheet = workbook.createSheet("Summary"); // create the header row int rowIndex = 0; Row headers = sheet.createRow(rowIndex); headers.setRowStyle(headerStyle); int cellIndex = 0; for (String columnName : columnNamesCopy) { Cell cell = headers.createCell(cellIndex); cell.setCellValue(columnName); cell.setCellStyle(headerStyle); cellIndex++; } for (String testName : testNames) { // get each test's fixture stats and sort them accordingly List<FixtureStatistic> fixtureStats = stats.get(testName); if (fixtureStats == null || fixtureStats.size() == 0) { continue; } Collections.sort(fixtureStats); rowIndex++; for (FixtureStatistic fixtureStat : fixtureStats) { Row data = sheet.createRow(rowIndex); cellIndex = 0; //write out the test name first Cell cell = data.createCell(cellIndex); cell.setCellValue(testName); cellIndex++; for (String columnName : columnNames) { cell = data.createCell(cellIndex); Object rawValue = fixtureStat.getStat(columnName); if (rawValue == null) { cell.setCellValue(""); } else { if (rawValue instanceof Integer) { cell.setCellValue((Integer) rawValue); } else if (rawValue instanceof Double) { cell.setCellValue((Double) rawValue); } else if (rawValue instanceof Long) { cell.setCellValue((Long) rawValue); } else if (rawValue instanceof Boolean) { cell.setCellValue((Boolean) rawValue); } else { cell.setCellValue(rawValue.toString()); } } // adjust column width to fit the content sheet.autoSizeColumn(cellIndex); cellIndex++; } //rowIndex++; } } //write out the total time if (getTotalTestingTime() != -1) { rowIndex = rowIndex + 2; Row data = sheet.createRow(rowIndex); Cell cell = data.createCell(0); cell.setCellValue("Total Testing Time:"); cell.setCellStyle(headerStyle); cell = data.createCell(1); cell.setCellValue(formatTime(getTotalTestingTime())); } } finally { // write out the file FileOutputStream out = null; try { String fullPath = FilenameUtils.getFullPathNoEndSeparator(reportFile); // create all non exists folders else you will hit FileNotFoundException for report file path new File(fullPath).mkdirs(); out = new FileOutputStream(reportFile); if (workbook != null) { workbook.write(out); } } finally { IOUtils.closeQuietly(out); } } }
From source file:de.tudarmstadt.ukp.dkpro.core.stanfordnlp.StanfordCoreferenceResolver.java
@Override public void initialize(UimaContext aContext) throws ResourceInitializationException { super.initialize(aContext); modelProvider = new ModelProviderBase<Coreferencer>() { {// w w w . j av a 2 s . c o m setContextObject(StanfordCoreferenceResolver.this); setDefault(ARTIFACT_ID, "${groupId}.stanfordnlp-model-coref-${language}-${variant}"); setDefault(LOCATION, "classpath:/${package}/lib/coref/${language}/${variant}/countries"); setDefault(VARIANT, "default"); // setOverride(LOCATION, modelLocation); // setOverride(LANGUAGE, language); // setOverride(VARIANT, variant); } @Override protected Coreferencer produceResource(URL aUrl) throws IOException { String base = FilenameUtils.getFullPathNoEndSeparator(aUrl.toString()) + "/"; Properties props = new Properties(); props.setProperty(Constants.SIEVES_PROP, sieves); props.setProperty(Constants.SCORE_PROP, String.valueOf(score)); props.setProperty(Constants.POSTPROCESSING_PROP, String.valueOf(postprocessing)); props.setProperty(Constants.SINGLETON_PROP, String.valueOf(singleton)); props.setProperty(Constants.SINGLETON_MODEL_PROP, base + "singleton.predictor.ser"); props.setProperty(Constants.MAXDIST_PROP, String.valueOf(maxdist)); // props.setProperty(Constants.BIG_GENDER_NUMBER_PROP, "false"); props.setProperty(Constants.REPLICATECONLL_PROP, "false"); props.setProperty(Constants.CONLL_SCORER, Constants.conllMentionEvalScript); // Cf. edu.stanford.nlp.dcoref.Dictionaries.Dictionaries(Properties) // props.getProperty(Constants.DEMONYM_PROP, DefaultPaths.DEFAULT_DCOREF_DEMONYM), props.setProperty(Constants.DEMONYM_PROP, base + "demonyms.txt"); // props.getProperty(Constants.ANIMATE_PROP, DefaultPaths.DEFAULT_DCOREF_ANIMATE), props.setProperty(Constants.ANIMATE_PROP, base + "animate.unigrams.txt"); // props.getProperty(Constants.INANIMATE_PROP, DefaultPaths.DEFAULT_DCOREF_INANIMATE), props.setProperty(Constants.INANIMATE_PROP, base + "inanimate.unigrams.txt"); // props.getProperty(Constants.MALE_PROP), props.setProperty(Constants.MALE_PROP, base + "male.unigrams.txt"); // props.getProperty(Constants.NEUTRAL_PROP), props.setProperty(Constants.NEUTRAL_PROP, base + "neutral.unigrams.txt"); // props.getProperty(Constants.FEMALE_PROP), props.setProperty(Constants.FEMALE_PROP, base + "female.unigrams.txt"); // props.getProperty(Constants.PLURAL_PROP), props.setProperty(Constants.PLURAL_PROP, base + "plural.unigrams.txt"); // props.getProperty(Constants.SINGULAR_PROP), props.setProperty(Constants.SINGULAR_PROP, base + "singular.unigrams.txt"); // props.getProperty(Constants.STATES_PROP, DefaultPaths.DEFAULT_DCOREF_STATES), props.setProperty(Constants.STATES_PROP, base + "state-abbreviations.txt"); //props.getProperty(Constants.GENDER_NUMBER_PROP, DefaultPaths.DEFAULT_DCOREF_GENDER_NUMBER); props.setProperty(Constants.GENDER_NUMBER_PROP, base + "gender.map.ser.gz"); // props.getProperty(Constants.COUNTRIES_PROP, DefaultPaths.DEFAULT_DCOREF_COUNTRIES), props.setProperty(Constants.COUNTRIES_PROP, base + "countries"); // props.getProperty(Constants.STATES_PROVINCES_PROP, DefaultPaths.DEFAULT_DCOREF_STATES_AND_PROVINCES), props.setProperty(Constants.STATES_PROVINCES_PROP, base + "statesandprovinces"); // The following properties are only relevant if the "CorefDictionaryMatch" sieve // is enabled. // PropertiesUtils.getStringArray(props, Constants.DICT_LIST_PROP, // new String[]{DefaultPaths.DEFAULT_DCOREF_DICT1, DefaultPaths.DEFAULT_DCOREF_DICT2, // DefaultPaths.DEFAULT_DCOREF_DICT3, DefaultPaths.DEFAULT_DCOREF_DICT4}), props.put(Constants.DICT_LIST_PROP, '[' + base + "coref.dict1.tsv" + ',' + base + "coref.dict2.tsv" + ',' + base + "coref.dict3.tsv" + ',' + base + "coref.dict4.tsv" + ']'); // props.getProperty(Constants.DICT_PMI_PROP, DefaultPaths.DEFAULT_DCOREF_DICT1), props.put(Constants.DICT_PMI_PROP, base + "coref.dict1.tsv"); // props.getProperty(Constants.SIGNATURES_PROP, DefaultPaths.DEFAULT_DCOREF_NE_SIGNATURES)); props.put(Constants.SIGNATURES_PROP, base + "ne.signatures.txt"); try { Coreferencer coref = new Coreferencer(); coref.corefSystem = new SieveCoreferenceSystem(props); coref.mentionExtractor = new MentionExtractor(coref.corefSystem.dictionaries(), coref.corefSystem.semantics()); return coref; } catch (Exception e) { throw new IOException(e); } } }; }
From source file:edu.udo.scaffoldhunter.model.clustering.evaluation.FileSaverMetaModule.java
/** * Construct and save the OrderedBySubsetSize CSV string / file * //w w w. j av a 2 s.c o m * @param results */ private void saveCSVOrderedBySubsetSize(Collection<EvaluationResult> results) { StringBuilder csvString = new StringBuilder(); // ordered keys of all results TreeSet<String> keys = Sets.newTreeSet(); for (EvaluationResult result : results) { keys.addAll(result.getResults().keySet()); } // create csv header csvString.append("subset size,"); for (String key : keys) { csvString.append(key); csvString.append(","); } csvString.deleteCharAt(csvString.length() - 1); // create csv data & store single result file (not storing // csv file at this point) for (EvaluationResult result : results) { csvString.append(System.getProperty("line.separator").toString()); csvString.append(result.getSubsetSize()); csvString.append(","); for (String key : keys) { String value = result.getResults().get(key); if (value != null) { csvString.append(value); } csvString.append(","); } csvString.deleteCharAt(csvString.length() - 1); } saveToFile( FilenameUtils.concat(FilenameUtils.getFullPathNoEndSeparator(path), FilenameUtils.getBaseName(path)) + FilenameUtils.EXTENSION_SEPARATOR + "csv", csvString.toString()); }
From source file:edu.udo.scaffoldhunter.model.clustering.evaluation.FileSaverMetaModule.java
private String getUniqueBaseName(EvaluationResult result) { count++;/*from w ww. j av a 2 s . c om*/ return FilenameUtils.concat(FilenameUtils.getFullPathNoEndSeparator(path), FilenameUtils.getBaseName(path)) + "-" + result.getMeasurement() + "_" + Integer.toString(count - 1); }
From source file:com.iisigroup.cap.log.TimeFolderSizeRollingFileAppender.java
public void zipFiles(List<String> fileList, String destUrl) throws IOException { FileUtils.forceMkdir(new File(FilenameUtils.getFullPathNoEndSeparator(destUrl))); BufferedInputStream origin = null; FileOutputStream fos = null;/* w w w . jav a 2 s.co m*/ BufferedOutputStream bos = null; ZipArchiveOutputStream out = null; byte data[] = new byte[BUFFER]; try { fos = new FileOutputStream(destUrl); bos = new BufferedOutputStream(fos); out = new ZipArchiveOutputStream(bos); for (String fName : fileList) { File file = new File(fName); FileInputStream fi = new FileInputStream(file); origin = new BufferedInputStream(fi, BUFFER); ZipArchiveEntry entry = new ZipArchiveEntry(file.getName()); out.putArchiveEntry(entry); int count; while ((count = origin.read(data, 0, BUFFER)) != -1) { out.write(data, 0, count); } out.closeArchiveEntry(); fi.close(); origin.close(); } } finally { if (out != null) { try { out.close(); } catch (IOException e) { } } if (bos != null) { try { bos.close(); } catch (IOException e) { } } if (fos != null) { try { fos.close(); } catch (IOException e) { } } if (origin != null) { try { origin.close(); } catch (IOException e) { } } } }
From source file:com.abiquo.nodecollector.domain.collectors.AbstractLibvirtCollector.java
/** * Create a {@link Disk} objet from an image value. * //from w w w. j a va 2 s . c o m * @param imagePath image where the disk is stored * @return a Disk object filled with the information */ private ResourceType createDiskFromImagePath(final String imagePath) { final ResourceType currentHardDisk = new ResourceType(); currentHardDisk.setResourceType(ResourceEnumType.HARD_DISK); currentHardDisk.setAddress(imagePath); try { long diskSize = aimcollector.getDiskFileSize(imagePath); currentHardDisk.setUnits(diskSize); } catch (AimException e) { currentHardDisk.setUnits(0L); } currentHardDisk.setResourceSubType(VirtualDiskEnumType.UNKNOWN.value()); currentHardDisk.setConnection(FilenameUtils.getFullPathNoEndSeparator(imagePath)); return currentHardDisk; }
From source file:com.nridge.core.app.mgr.AppMgr.java
private String deriveCfgPathName() throws NSException { String cfgFileName, cfgPathName, cfgPathFileName; String installPathName = getInsPathName(); if (mCmdLine == null) cfgFileName = APP_PROPERTY_FILE_NAME; else// w ww .java 2 s .c o m cfgFileName = mCmdLine.getOptionValue("cfgfile", APP_PROPERTY_FILE_NAME); // Did we get an absolute path/file name to cfgfile? File cfgFile = new File(cfgFileName); if (cfgFile.exists()) cfgPathName = FilenameUtils.getFullPathNoEndSeparator(cfgFileName); else { // Is our default path good enough to locate the property file? cfgPathFileName = String.format("%s%c%s", mCfgPathName, File.separatorChar, cfgFileName); cfgFile = new File(cfgPathFileName); if (cfgFile.exists()) cfgPathName = FilenameUtils.getFullPathNoEndSeparator(cfgFile.getAbsolutePath()); else { // Our we running from a maven source tree? cfgPathFileName = String.format("%s%csrc%cmain%cresources%c%s", installPathName, File.separatorChar, File.separatorChar, File.separatorChar, File.separatorChar, cfgFileName); cfgFile = new File(cfgPathFileName); if (cfgFile.exists()) cfgPathName = FilenameUtils.getFullPathNoEndSeparator(cfgFile.getAbsolutePath()); else { // Last chance - are we running from a standard install area? cfgPathFileName = String.format("cfg%c%s", File.separatorChar, cfgFileName); cfgFile = new File(cfgPathFileName); if (cfgFile.exists()) cfgPathName = FilenameUtils.getFullPathNoEndSeparator(cfgFile.getAbsolutePath()); else throw new NSException("Unable to locate application properties file: " + cfgPathFileName); } } } mCfgPathName = cfgPathName; return mCfgPathName; }
From source file:com.nridge.core.app.mgr.AppMgr.java
private String deriveCfgPathFileName() throws NSException { String cfgFileName, cfgPathFileName; if (mCmdLine == null) cfgFileName = APP_PROPERTY_FILE_NAME; else/*from w ww. j a va2 s . c om*/ cfgFileName = mCmdLine.getOptionValue("cfgfile", APP_PROPERTY_FILE_NAME); File cfgFile = new File(cfgFileName); if (cfgFile.exists()) { cfgPathFileName = cfgFileName; mCfgPathName = FilenameUtils.getFullPathNoEndSeparator(cfgFile.getAbsolutePath()); } else { cfgPathFileName = String.format("%s%c%s", deriveCfgPathName(), File.separatorChar, cfgFileName); } return cfgPathFileName; }