Refine search
public JrtfsCodeBase(ICodeBaseLocator codeBaseLocator, @Nonnull String fileName) { super(codeBaseLocator); this.fileName = fileName; URL url; try { url = Paths.get(fileName).toUri().toURL(); URLClassLoader loader = new URLClassLoader(new URL[] { url }); fs = FileSystems.newFileSystem(URI.create("jrt:/"), Collections.emptyMap(), loader); root = fs.getPath("modules"); packageToModuleMap = createPackageToModuleMap(fs); } catch (IOException e) { e.printStackTrace(); } }
public FileSystemWatcher(String[] classPath) throws IOException { watchService = FileSystems.getDefault().newWatchService(); for (String entry : classPath) { Path path = Paths.get(entry); File file = path.toFile(); if (file.exists()) { if (file.isDirectory()) { register(path); } } } }
@Signature public static boolean match(String path, String pattern) { PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher(pattern); return pathMatcher.matches(Paths.get(path)); }
private static void updateZip(File zip, File entry, String entryName) throws IOException { Map<String, String> env = new HashMap<>(); String uriPath = "jar:" + zip.toURI().toString(); URI uri = URI.create(uriPath); try (FileSystem fs = FileSystems.newFileSystem(uri, env)) { fs.provider().checkAccess(fs.getPath(entryName), AccessMode.READ); Path target = fs.getPath(entryName); Path source = entry.toPath(); Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { throw e; } }
@Signature(@Arg("pattern")) public Memory matches(Environment env, Memory... args) { FileSystem aDefault = FileSystems.getDefault(); PathMatcher pathMatcher = aDefault.getPathMatcher(args[0].toString()); return pathMatcher.matches(aDefault.getPath(file.getPath())) ? Memory.TRUE : Memory.FALSE; }
protected String readSchemaFileAsString(String filePath) throws IOException { try { URI uri = this.getClass().getClassLoader().getResource(filePath).toURI(); String[] array = uri.toString().split("!"); Path path; if (array.length > 1) { LOG.info("Creating fs for {}", array[0]); FileSystem fs; try { fs = FileSystems.newFileSystem(URI.create(array[0]), new HashMap<String, String>()); } catch (FileSystemAlreadyExistsException e) { fs = FileSystems.getFileSystem(URI.create(array[0])); } path = fs.getPath(array[1]); } else { path = Paths.get(uri); } return new String(Files.readAllBytes(path)); } catch (URISyntaxException e) { LOG.error("Can't generate configs {}", e); } return null; }
@Test public void testRead() throws IOException { Files.write(Paths.get(URI.create("gs://bucket/angel")), ALONE.getBytes(UTF_8)); try (FileSystem fs = CloudStorageFileSystem.forBucket("bucket")) { assertThat(new String(Files.readAllBytes(fs.getPath("/angel")), UTF_8)).isEqualTo(ALONE); } }
try Path path = Paths.get(suspendFileFolderPath); watchService = FileSystems.getDefault().newWatchService(); path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE); } catch (IOException e1)
static void createJar(final URI jarURI, final File workDir, final File f) throws Exception { final Map<String, String> env = new HashMap<>(); env.put("create", "true"); final URI uri = URI.create("jar:file://" + jarURI.getRawPath()); try (FileSystem zipfs = FileSystems.newFileSystem(uri, env)) { final Path path = zipfs.getPath(workDir.toPath().relativize(f.toPath()).toString()); if (path.getParent() != null) { Files.createDirectories(path.getParent()); } Files.copy(f.toPath(), path, StandardCopyOption.REPLACE_EXISTING ); } }
if (location.getScheme().equals("jar")) { try { fileSystem = FileSystems.getFileSystem(location); } catch (FileSystemNotFoundException e) { fileSystem = FileSystems.newFileSystem(location, Collections.<String, String>emptyMap()); myPath = fileSystem.getPath(dir); } else { myPath = Paths.get(location); Stream<Path> files = Files.walk(myPath, 1); for (Path path : (Iterable<Path>) () -> files.iterator()) { System.out.println(path); final String name = path.getFileName().toString(); File fwConfig = new File(firmwareConfig, name); if (name.endsWith(".json")) { boolean copyFile = !fwConfig.exists(); ControllerSettings jarSetting = getSettingsForStream(Files.newInputStream(path)); if (fileSystem != null) { try { fileSystem.close(); } catch (IOException ex) { logger.log(Level.SEVERE, "Problem closing filesystem.", ex);
Path path = FileSystems.getDefault().getPath(userDir, "target", "classes"); if (Files.exists(path)){ cp.add(path.toString()); path = FileSystems.getDefault().getPath(userDir, "build", "classes","java", "main"); if (Files.exists(path)){ cp.add(path.toString()); File libDir = Paths.get(userDir, "../lib").toFile();
Files.createFile( testDirectory.file( "neo4j.conf" ).toPath() ); Files.write( Paths.get( run.getAbsolutePath(), "neo4j.pid" ), String.valueOf( pid ).getBytes() ); final URI uri = URI.create( "jar:file:" + report.toUri().getRawPath() ); try ( FileSystem fs = FileSystems.newFileSystem( uri, Collections.emptyMap() ) ) String threadDump = new String( Files.readAllBytes( fs.getPath( "threaddump.txt" ) ) ); assertThat( threadDump, containsString( DiagnosticsReportCommandIT.class.getCanonicalName() ) );
if (uri.getScheme().equals("jar")) { fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap()); myPath = fileSystem.getPath("/" + path); } else { myPath = Paths.get(uri); return Files.walk(myPath, 1).flatMap(next -> { if (next.equals(myPath)) { return Stream.of(); return Stream.of(CharMatcher.is('/').trimFrom(next.getFileName().toString())); }).collect(Collectors.toList()); } finally { if (fileSystem != null) { fileSystem.close(); } finally { if (fileSystem != null) { fileSystem.close();
private void addJarManifest(String uberJar, MavenProject project, String mainClass) throws IOException { Path path = Paths.get(uberJar); URI uri = URI.create("jar:" + path.toUri()); String user = System.getProperty("user.name"); String manifestContent = IO.load("manifest-template.mf") .replace("$user", user) .replace("$java", Msc.javaVersion()) .replace("$name", project.getName()) .replace("$version", project.getVersion()) .replace("$groupId", project.getGroupId()) .replace("$organization", project.getOrganization() != null ? U.or(project.getOrganization().getName(), "?") : "?") .replace("$url", U.or(project.getUrl(), "?")) .replace("$main", U.safe(mainClass)); try (FileSystem fs = FileSystems.newFileSystem(uri, U.map())) { Path manifest = fs.getPath("META-INF/MANIFEST.MF"); try (Writer writer = Files.newBufferedWriter(manifest, StandardCharsets.UTF_8, StandardOpenOption.CREATE)) { writer.write(manifestContent); } } }
@Test public void checkDefaultOptions() throws IOException { // 1. We get the normal default if we don't do anything special. Path path = Paths.get(URI.create("gs://bucket/file")); CloudStorageFileSystem gcs = (CloudStorageFileSystem) path.getFileSystem(); assertThat(gcs.config().maxChannelReopens()).isEqualTo(0); // 2(a). Override the default, and see it reflected. CloudStorageFileSystemProvider.setDefaultCloudStorageConfiguration( CloudStorageConfiguration.builder().maxChannelReopens(123).build()); Path path2 = Paths.get(URI.create("gs://newbucket/file")); CloudStorageFileSystem gcs2 = (CloudStorageFileSystem) path2.getFileSystem(); assertThat(gcs2.config().maxChannelReopens()).isEqualTo(123); // 2(b) ...even reflected if we try to open a file. try (FileSystem fs = CloudStorageFileSystem.forBucket("bucket")) { CloudStorageFileSystem csfs = (CloudStorageFileSystem) fs; assertThat(csfs.config().maxChannelReopens()).isEqualTo(123); Files.write(fs.getPath("/angel"), ALONE.getBytes(UTF_8)); path2 = Paths.get(URI.create("gs://bucket/angel")); try (SeekableByteChannel seekableByteChannel = Files.newByteChannel(path2)) { CloudStorageReadChannel cloudChannel = (CloudStorageReadChannel) seekableByteChannel; assertThat(cloudChannel.maxChannelReopens).isEqualTo(123); } } // 4. Clean up. CloudStorageFileSystemProvider.setDefaultCloudStorageConfiguration(null); Path path3 = Paths.get(URI.create("gs://newbucket/file")); CloudStorageFileSystem gcs3 = (CloudStorageFileSystem) path3.getFileSystem(); assertThat(gcs3.config().maxChannelReopens()).isEqualTo(0); }
private void writeChunkStores() throws IOException { Path chunksPath = storagePathProvider.getWorldTempPath(); Files.createDirectories(chunksPath); if (storeChunksInZips) { Map<Vector3i, FileSystem> newChunkZips = Maps.newHashMap(); if (zip == null) { Path targetPath = storagePathProvider.getChunkZipTempPath(chunkZipPos); Files.deleteIfExists(targetPath); zip = FileSystems.newFileSystem(URI.create("jar:" + targetPath.toUri()), CREATE_ZIP_OPTIONS); newChunkZips.put(chunkZipPos, zip); Path chunkPath = zip.getPath(storagePathProvider.getChunkFilename(chunkPos)); CompressedChunkBuilder compressedChunkBuilder = entry.getValue(); byte[] compressedChunk = compressedChunkBuilder.buildEncodedChunk(); try (BufferedOutputStream bos = new BufferedOutputStream(Files.newOutputStream(chunkPath))) { bos.write(compressedChunk); final FileSystem zip = chunkZipEntry.getValue(); if (Files.isRegularFile(oldChunkZipPath)) { try (FileSystem oldZip = FileSystems.newFileSystem(oldChunkZipPath, null)) { for (Path root : oldZip.getRootDirectories()) { Files.walkFileTree(root, new SimpleFileVisitor<Path>() { @Override zip.close();
@Test public void testRelativize_willWorkWithRecursiveCopy() throws IOException { // See: http://stackoverflow.com/a/10068306 try (FileSystem fsSource = FileSystems.getFileSystem(URI.create("gs://hello")); FileSystem fsTarget = FileSystems.getFileSystem(URI.create("gs://cat"))) { Path targetPath = fsTarget.getPath("/some/folder/"); Path sourcePath = fsSource.getPath("/sloth/"); Path file = fsSource.getPath("/sloth/file.txt"); assertThat((Object) targetPath.resolve(sourcePath.relativize(file))) .isEqualTo(fsTarget.getPath("/some/folder/file.txt")); } }
synchronized (this) { if (uri.getScheme().equals("jar")) { FileSystem fileSystem = null; try { try { fileSystem = FileSystems.getFileSystem(uri); } catch (FileSystemNotFoundException e) { fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap(), classLoader); pathObject = fileSystem.getPath(path); return pathObject == null || Files.isDirectory(pathObject); } finally { if (fileSystem != null && fileSystem.isOpen()) { try { fileSystem.close(); } catch (IOException e) { if (LOG.isDebugEnabled()) { } else if (uri.getScheme().equals("file")) { pathObject = Paths.get(uri); return pathObject == null || Files.isDirectory(pathObject);
@SuppressWarnings("ConstantConditions") public static Path getResourceRoot() throws IOException, URISyntaxException { final URI uri = GeneratorTest.class.getClassLoader().getResource("product.avro").toURI(); if ("jar".equals(uri.getScheme())) { final FileSystem fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap(), null); return fileSystem.getPath("path/to/folder/inside/jar").getParent(); } else { return Paths.get(uri).getParent(); } } }