List of usage examples for org.apache.commons.io FilenameUtils getFullPath
public static String getFullPath(String filename)
From source file:org.codice.ddf.spatial.geocoding.extract.GeoNamesFileExtractorTest.java
@Test public void testExtractFromNonexistentFile() throws GeoEntryExtractionException, GeoNamesRemoteDownloadException { try {// w w w. jav a 2 s . co m geoNamesFileExtractor.getGeoEntries(FilenameUtils.getFullPath(VALID_TEXT_FILE_PATH) + "fake.txt", null); fail("Should have thrown a GeoEntryExtractionException because 'fake.txt' does not " + "exist."); } catch (GeoEntryExtractionException e) { assertThat(e.getCause(), instanceOf(FileNotFoundException.class)); } }
From source file:org.coinspark.wallet.CSMessageDatabase.java
public CSMessageDatabase(String FilePrefix, CSLogger CSLog, Wallet ParentWallet) { dirName = FilePrefix + MESSAGE_DIR_SUFFIX + File.separator; fileName = dirName + MESSAGE_DATABASE_FILENAME + ((CSMessageDatabase.testnet3) ? TESTNET3_FILENAME_SUFFIX : ""); // H2 will add .mv.db extension itself csLog = CSLog;// w ww. j a va 2 s.c o m wallet = ParentWallet; String folder = FilenameUtils.getFullPath(FilePrefix); String name = MESSAGE_BLOB_KEYSTORE_FILENAME + ((CSMessageDatabase.testnet3) ? TESTNET3_FILENAME_SUFFIX : "") + MESSAGE_MVSTORE_FILE_EXTENSION; String blobPath = FilenameUtils.concat(folder, name); boolean b = CSMessageDatabase.initBlobMap(blobPath); if (!b) { log.error("Message DB: Could not create BLOB storage map at: " + blobPath); return; } File dir = new File(dirName); if (!dir.exists()) { // Files.createDirectory(Paths.get(dirName)); try { dir.mkdir(); } catch (SecurityException ex) { log.error("Message DB: Cannot create files directory" + ex.getClass().getName() + " " + ex.getMessage()); return; } } String kvStoreFileName = dirName + MESSAGE_META_KEYSTORE_FILENAME + ((CSMessageDatabase.testnet3) ? TESTNET3_FILENAME_SUFFIX : "") + MESSAGE_MVSTORE_FILE_EXTENSION; kvStore = MVStore.open(kvStoreFileName); if (kvStore != null) { defMap = kvStore.openMap(MESSAGE_TXID_TO_META_MAP_NAME); errorMap = kvStore.openMap(MESSAGE_TXID_TO_ERROR_MAP_NAME); } // TODO?: This database URL could be passed in via constructor String databaseUrl = "jdbc:h2:file:" + fileName + ";USER=sa;PASSWORD=sa;AUTO_SERVER=TRUE"; try { connectionSource = new JdbcConnectionSource(databaseUrl); messageDao = DaoManager.createDao(connectionSource, CSMessage.class); TableUtils.createTableIfNotExists(connectionSource, CSMessage.class); messagePartDao = DaoManager.createDao(connectionSource, CSMessagePart.class); TableUtils.createTableIfNotExists(connectionSource, CSMessagePart.class); } catch (SQLException e) { e.printStackTrace(); } }
From source file:org.craftercms.engine.freemarker.RenderComponentDirective.java
protected SiteItem getComponent(String componentPath, Environment env) throws TemplateException { SiteItem currentPage = unwrap(KEY_CONTENT_MODEL, env.getVariable(CrafterPageView.KEY_CONTENT_MODEL), SiteItem.class, env); if (currentPage != null) { String basePath = FilenameUtils.getFullPath(currentPage.getStoreUrl()); URI baseUri = URI.create(basePath); try {//from ww w . ja v a 2s .c om componentPath = baseUri.resolve(componentPath).toString(); } catch (IllegalArgumentException e) { throw new TemplateException("Invalid relative component URL " + componentPath, e, env); } } SiteItem component; try { component = siteItemService.getSiteItem(componentPath); } catch (Exception e) { throw new TemplateException( "Unable to load component " + componentPath + " from the underlying repository", e, env); } if (component == null) { throw new TemplateException("No component found at path '" + componentPath + "'", env); } return component; }
From source file:org.craftercms.studio.impl.v1.service.asset.processing.AssetProcessingServiceImpl.java
private List<Map<String, Object>> writeOutputs(String site, Collection<Asset> outputs, String isImage, String allowedWidth, String allowedHeight, String allowLessSize, String draft, String unlock, String systemAsset) throws AssetProcessingException { List<Map<String, Object>> results = new ArrayList<>(); for (Asset output : outputs) { try {//from ww w. jav a 2 s . co m try (InputStream in = Files.newInputStream(output.getFilePath())) { Map<String, Object> result = contentService.writeContentAsset(site, FilenameUtils.getFullPath(output.getRepoPath()), FilenameUtils.getName(output.getRepoPath()), in, isImage, allowedWidth, allowedHeight, allowLessSize, draft, unlock, systemAsset); if (MapUtils.isNotEmpty(result)) { if (result.containsKey("error")) { throw new AssetProcessingException("Error writing output " + output, (Exception) result.get("error")); } else { results.add(result); } } } } catch (IOException | ServiceException e) { throw new AssetProcessingException("Error writing output " + output, e); } } return results; }
From source file:org.datavyu.util.OFileUtils.java
/** * Calculate the difference in directory levels between basePath and path. * basePath must be a predecessor of path. * basePath must be a directory.//w w w . j a v a2 s .co m * basePath and path must be valid paths of the same filesystem and mount * point. * basePath and path must be absolute paths. * Directories must have '/' at the end of the path. * * @param basePath * @param path * @return a positive integer >= 0 denoting the difference in directory * levels if the difference can be determined. -1 if the difference * cannot be determined. */ public static int levelDifference(final String basePath, final String path) { if ((basePath == null) || (path == null)) { throw new NullPointerException(); } File base = new File(FilenameUtils.normalize(basePath, true)); File ancestor = new File(FilenameUtils.getFullPath(FilenameUtils.normalize(path, true))); int diff = 0; while (!base.equals(ancestor)) { ancestor = ancestor.getParentFile(); if (ancestor != null) { diff++; } else { return -1; } } return diff; }
From source file:org.datavyu.views.DatavyuView.java
public void checkForAutosavedFile() { // Check for autosaved file (crash condition) try {/*from w w w. ja v a2 s . co m*/ File tempfile = File.createTempFile("test", ""); String path = FilenameUtils.getFullPath(tempfile.getPath()); tempfile.delete(); File folder = new File(path); File[] listOfFiles = folder.listFiles(); for (File f : listOfFiles) { if ((f.isFile()) && ((FilenameUtils.wildcardMatchOnSystem(f.getName(), "~*.opf")) || (FilenameUtils.wildcardMatchOnSystem(f.getName(), "~*.csv")))) { // the last time datavyu crashed // Show the Dialog if (JOptionPane.showConfirmDialog(null, "Openshapa has detected an unsaved file. Would you like recover this file ?", "OpenShapa", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { openRecoveredFile(f); this.saveAs(); } // delete the recovered file f.delete(); } } } catch (IOException ex) { java.util.logging.Logger.getLogger(DatavyuView.class.getName()).log(Level.SEVERE, null, ex); } // initialize autosave feature AutosaveC.setInterval(1); // five minutes }
From source file:org.dbunit.DatabaseEnvironment.java
public File getFile(String fileName) { String fullPath = FilenameUtils.getFullPath(fileName); String baseName = FilenameUtils.getBaseName(fileName); String extension = FilenameUtils.getExtension(fileName); File profileFile = new File(fullPath + baseName + "-" + _profile.getActiveProfile() + "." + extension); if (profileFile.exists()) { return profileFile; } else {//www .j a v a 2 s . c o m return new File(fileName); } }
From source file:org.dbunit.testutil.TestUtils.java
public static File getFileForDatabaseEnvironment(String originalFileName) throws Exception { String fullPath = FilenameUtils.getFullPath(originalFileName); String baseName = FilenameUtils.getBaseName(originalFileName); String extension = FilenameUtils.getExtension(originalFileName); File profileFile = new File(fullPath + baseName + "-" + getProfileName() + "." + extension); if (profileFile.exists()) { return profileFile; } else {/*from ww w .j a v a2 s.co m*/ return new File(originalFileName); } }
From source file:org.ebayopensource.turmeric.tools.codegen.util.ClassPathUtil.java
private static List<File> getJarClassPathRefs(File file) { List<File> refs = new ArrayList<File>(); JarFile jar = null;/* w w w . j a v a 2 s.co m*/ try { jar = new JarFile(file); Manifest manifest = jar.getManifest(); if (manifest == null) { // No manifest, no classpath. return refs; } Attributes attrs = manifest.getMainAttributes(); if (attrs == null) { /* * No main attributes. (not sure how that's possible, but we can skip this jar) */ return refs; } String classPath = attrs.getValue(Attributes.Name.CLASS_PATH); if (CodeGenUtil.isEmptyString(classPath)) { return refs; } String parentDir = FilenameUtils.getFullPath(file.getAbsolutePath()); File possible; for (String path : StringUtils.splitStr(classPath, ' ')) { possible = new File(path); if (!possible.isAbsolute()) { // relative path? possible = new File(FilenameUtils.normalize(parentDir + path)); } if (!refs.contains(possible)) { refs.add(possible); } } } catch (IOException e) { LOG.log(Level.WARNING, "Unable to load/read/parse Jar File: " + file.getAbsolutePath(), e); } finally { CodeGenUtil.closeQuietly(jar); } return refs; }
From source file:org.eclipse.skalli.core.storage.Historian.java
void historizeSingleFile(File file) throws IOException { if (historyFile == null) { File destdir = new File(FilenameUtils.getFullPath(file.getAbsolutePath())); historyFile = new File(destdir, HISTORY_FILE); }/*www . ja va 2 s.co m*/ InputStream in = null; OutputStream out = null; try { in = new BufferedInputStream(new FileInputStream(file)); out = new BufferedOutputStream(new FileOutputStream(historyFile, historyFile.exists())); String id = getNextEntryName(FilenameUtils.getBaseName(file.getAbsolutePath())); String header = MessageFormat.format("{0}:{1}:{2}", id, Long.toString(file.length()), //$NON-NLS-1$ Long.toString(System.currentTimeMillis())); out.write(header.getBytes("UTF-8")); //$NON-NLS-1$ out.write(CRLF.getBytes("UTF-8")); //$NON-NLS-1$ IOUtils.copy(in, out); out.write(CRLF.getBytes("UTF-8")); //$NON-NLS-1$ } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } }