List of usage examples for java.io File toURI
public URI toURI()
From source file:io.wcm.maven.plugins.i18n.readers.JsonI18nReader.java
@Override public Map<String, String> read(File sourceFile) throws IOException { String fileContent = IOUtils.toString(sourceFile.toURI().toURL(), CharEncoding.UTF_8); try {/*from w w w. j a v a2 s . co m*/ JSONObject root = new JSONObject(fileContent); Map<String, String> map = new HashMap<String, String>(); parseJson(root, map, ""); return map; } catch (JSONException ex) { throw new IOException("Unable to read JSON from " + sourceFile.getAbsolutePath(), ex); } }
From source file:msi.gaml.statements.SaveStatement.java
public static void saveShapeFile(final IScope scope, final String path, final List<? extends IShape> agents, /* final String featureTypeName, */final String specs, final Map<String, IExpression> attributes, final IProjection gis) throws IOException, SchemaException, GamaRuntimeException { // AD 11/02/15 Added to allow saving to new directories if (agents == null || agents.isEmpty()) return;//ww w . j av a 2 s .com final File f = new File(path); createParents(f); final ShapefileDataStore store = new ShapefileDataStore(f.toURI().toURL()); // The name of the type and the name of the feature source shoud now be // the same. final SimpleFeatureType type = DataUtilities.createType(store.getFeatureSource().getEntry().getTypeName(), specs); store.createSchema(type); // AD: creation of a FeatureWriter on the store. try (FeatureWriter fw = store.getFeatureWriter(Transaction.AUTO_COMMIT)) { // AD Builds once the list of agent attributes to evaluate final Collection<IExpression> attributeValues = attributes == null ? Collections.EMPTY_LIST : attributes.values(); for (final IShape ag : agents) { final SimpleFeature ff = (SimpleFeature) fw.next(); boolean ok = buildFeature(scope, ff, ag, gis, attributeValues); if (!ok) { continue; } } // store.dispose(); if (gis != null) { writePRJ(scope, path, gis); } } catch (final ClassCastException e) { throw GamaRuntimeException.error( "Cannot save agents/geometries with different types of geometries (point, line, polygon) in a same shapefile", scope); } finally { store.dispose(); } }
From source file:com.google.mr4c.content.RelativeContentFactory.java
public Path toPath(URI uri) { File file = toFile(uri); return new Path(file.toURI()); }
From source file:com.temenos.interaction.loader.detector.ClassLoaderCreatingAction.java
/** * @param fe the file event with the directory to search for the specified file extensions *///from w ww.j a v a 2 s . co m @Override public void execute(FileEvent<File> fe) { Collection<File> files = FileUtils.listFiles(fe.getResource(), extensions.toArray(new String[] {}), true); Set<URL> urls = new HashSet(); for (File f : files) { try { urls.add(f.toURI().toURL()); } catch (MalformedURLException ex) { // TODO: log properly } } ParentLastURLClassloader classloader = new ParentLastURLClassloader(urls.toArray(new URL[] {})); for (Action<ClassLoader> listener : listeners) { listener.execute(classloader); } }
From source file:azkaban.storage.LocalStorage.java
private String createRelativePath(File targetFile) { return rootDirectory.toURI().relativize(targetFile.toURI()).getPath(); }
From source file:com.googlecode.flyway.core.util.scanner.FileSystemLocationScanner.java
/** * Converts this file into a resource name on the classpath. * @param classPathRootOnDisk The location of the classpath root on disk, with a trailing slash. * @param file The file.//from w w w.j ava 2 s. c o m * @return The resource name on the classpath. * @throws IOException when the file could not be read. */ private String toResourceNameOnClasspath(String classPathRootOnDisk, File file) throws IOException { String fileName = URLDecoder.decode(file.toURI().toURL().getFile(), "UTF-8"); //Cut off the part on disk leading to the root of the classpath //This leaves a resource name starting with the scanRootLocation, // with no leading slash, containing subDirs and the fileName. return fileName.substring(classPathRootOnDisk.length()); }
From source file:com.textocat.textokit.commons.cpe.FileDirectoryCollectionReader.java
private URI getURIForMetadata(File f) { URI fURI = f.toURI(); if (setRelativeURI) { URI dirURI = directory.toURI(); return dirURI.relativize(fURI); } else {// ww w .j a v a 2 s .c o m return fURI; } }
From source file:com.stehno.sanctuary.core.remote.S3RemoteStore.java
private String extractBucketName(File directory) { String name = directory.toURI().toString(); name = name.substring(name.lastIndexOf(':') + 1); name = name.replace("/", ""); name = name.replace(".", ""); name = name.replace("-", ""); name = name.replace(" ", ""); return BUCKET_NAME_PREFIX + name.toLowerCase(); }
From source file:io.inkstand.scribble.rules.TemporaryFileExample.java
@Test public void testZipStructure() throws Exception { //prepare/*from w w w. j a va2 s.c om*/ //act File f = file.getFile(); //assert assertTrue(f.exists()); try (InputStream is = f.toURI().toURL().openStream()) { String content = IOUtils.toString(is); assertEquals("content1", content); } }
From source file:org.hawkular.apm.tests.dockerized.TestScenariosFinder.java
public String readFile(File file) throws IOException { byte[] bytes = Files.readAllBytes(Paths.get(file.toURI())); return new String(bytes); }