List of usage examples for java.nio.file FileSystem getRootDirectories
public abstract Iterable<Path> getRootDirectories();
From source file:Main.java
public static void main(String[] args) throws IOException { FileSystem fileSystem = FileSystems.getDefault(); Iterable<Path> dirs = fileSystem.getRootDirectories(); for (Path name : dirs) { System.out.println(name); }/*www . j a v a 2s . co m*/ fileSystem.close(); }
From source file:Main.java
public static void main(String[] args) { FileSystem fs = FileSystems.getDefault(); System.out.println("Read-only file system: " + fs.isReadOnly()); System.out.println("File name separator: " + fs.getSeparator()); for (FileStore store : fs.getFileStores()) { printDetails(store);// ww w.j a v a2s. co m } for (Path root : fs.getRootDirectories()) { System.out.println(root); } }
From source file:Test.java
public static void main(String[] args) { FileSystem fileSystem = FileSystems.getDefault(); FileSystemProvider provider = fileSystem.provider(); System.out.println("Provider: " + provider.toString()); System.out.println("Open: " + fileSystem.isOpen()); System.out.println("Read Only: " + fileSystem.isReadOnly()); Iterable<Path> rootDirectories = fileSystem.getRootDirectories(); System.out.println();/* www . j a va 2 s . c o m*/ System.out.println("Root Directories"); for (Path path : rootDirectories) { System.out.println(path); } Iterable<FileStore> fileStores = fileSystem.getFileStores(); System.out.println(); System.out.println("File Stores"); for (FileStore fileStore : fileStores) { System.out.println(fileStore.name()); } }
From source file:org.schedulesdirect.grabber.ProgramCache.java
/** * Get the ProgramCache for the given File * @param src The File to get the cache for * @return The cache for the given File/*from www. j ava2 s. c om*/ * @throws IOException On any IO error */ synchronized static public ProgramCache get(FileSystem src) throws IOException { Iterator<Path> itr = src.getRootDirectories().iterator(); Path root = null; if (itr.hasNext()) { Path p = itr.next(); if (itr.hasNext()) throw new IOException("Cannot create ProgramCache for unrecognized file system type!"); root = p; } ProgramCache cache = CACHE.get(root.toString()); if (cache == null) { cache = new ProgramCache(src); CACHE.put(root.toString(), cache); } return cache; }
From source file:fr.mby.opa.pics.web.controller.UploadPicturesController.java
protected List<Path> processArchive(final MultipartFile multipartFile) throws IOException { final List<Path> archivePictures = new ArrayList<>(128); // We copy the archive in a tmp file final File tmpFile = File.createTempFile(multipartFile.getName(), ".tmp"); multipartFile.transferTo(tmpFile);//from w w w . ja v a2 s .co m // final InputStream archiveInputStream = multipartFile.getInputStream(); // Streams.copy(archiveInputStream, new FileOutputStream(tmpFile), true); // archiveInputStream.close(); final Path tmpFilePath = tmpFile.toPath(); final FileSystem archiveFs = FileSystems.newFileSystem(tmpFilePath, null); final Iterable<Path> rootDirs = archiveFs.getRootDirectories(); for (final Path rootDir : rootDirs) { Files.walkFileTree(rootDir, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(final Path path, final BasicFileAttributes attrs) throws IOException { final boolean isDirectory = Files.isDirectory(path); if (!isDirectory) { final String contentType = Files.probeContentType(path); if (contentType != null && contentType.startsWith("image/")) { archivePictures.add(path); } } return super.visitFile(path, attrs); } }); } return archivePictures; }
From source file:org.easyrec.utils.io.TreeCopy.java
/** * Resolve a path against another path with a potentially different * {@link FileSystem} or {@link FileSystemProvider} * * <p>{@link Path#resolve(Path)} will refuse to operate if its argument is * issued from a different provider (with a {@link * ProviderMismatchException}); moreover, if the argument is issued from the * same provider but is on a different filesystem, the result of the * resolution may be on the argument's filesystem, not the caller's.</p> * * <p>This method will attempt to resolve the second path against the first * so that the result is <em>always</em> associated to the filesystem (and * therefore provider) of the first argument. For the resolution to operate, * the following conditions must be met for {@code path2}:</p> * * <ul>/*from ww w. j a va 2 s . com*/ * <li>if it is not absolute, it must not have a root;</li> * <li>if it is absolute, it must have a root, and the string * representation of this root must match a string representation of one * possible root of the first path's filesystem.</li> * </ul> * * <p>If the conditions above are not satisfied, this method throws an * {@link UnresolvablePathException} (unchecked).</p> * * <p>If both paths are issued from the same filesystem, this method will * delegate to {@code path1}'s {@code .resolve()}; if they are from * different filesystems but share the same provider, this method returns: * </p> * * <pre> * path1.resolve(path1.getFileSystem().getPath(path2.toString())) * </pre> * * <p>This means that for instance it is possible to resolve a Unix path * against a Windows path, or the reverse, as long as the second path is * not absolute (the root paths of both filesystems are incompatible):</p> * * <ul> * <li>resolving {@code foo/bar/baz} against {@code c:} will return * {@code c:\foo\bar\baz};</li> * <li>resolving {@code baz\quux} against {@code /foo/bar} will return * {@code /foo/bar/baz/quux}.</li> * </ul> * * @param path1 the first path * @param path2 the second path * @return the resolved path * @throws UnresolvablePathException see description * @throws InvalidPathException {@code path2} is from a different provider, * and one of its name elements is invalid according to {@code path1}'s * filesystem * * @see FileSystem#getPath(String, String...) * @see FileSystem#getRootDirectories() */ @SuppressWarnings("ObjectEquality") private Path resolve(final Path path1, final Path path2) throws IOException { final FileSystem fs1 = Objects.requireNonNull(path1).getFileSystem(); final FileSystem fs2 = Objects.requireNonNull(path2).getFileSystem(); if (fs1 == fs2) return path1.resolve(path2); if (fs1.provider() == fs2.provider()) return path1.resolve(fs1.getPath(path2.toString())); final boolean isAbsolute = path2.isAbsolute(); final Path root2 = path2.getRoot(); final String errmsg = isAbsolute ? "path to resolve is absolute but has no root" : "path to resolve is not absolute but has a root"; // Always tricky to read an xor... if (isAbsolute ^ root2 != null) throw new IOException(errmsg); Path ret; if (isAbsolute) { /* * Check if the root of path2 is compatible with path1 */ final String path2Root = root2.toString(); boolean foundRoot = false; for (final Path root1 : fs1.getRootDirectories()) if (root1.toString().equals(path2Root)) foundRoot = true; if (!foundRoot) throw new IOException("root of path to resolve " + "is incompatible with source path"); ret = fs1.getPath(path2Root); } else { /* * Since the empty path is defined as having one empty name * component, which is rather awkward, we don't want to take the * risk of triggering bugs in FileSystem#getPath(); instead, check * that the string representation of path2 is empty, and if it is, * just return path1. */ if (path2.toString().isEmpty()) return path1; ret = path1; } for (final Path element : path2) ret = ret.resolve(element.toString()); return ret; }
From source file:org.testeditor.fixture.swt.SwtBotFixture.java
/** * Cleans the Workspace of the AUT and creates a demo Project. * /*from ww w . j a v a2 s . c o m*/ * @throws IOException * on reset the workspace. * @throws URISyntaxException * on reset the workspace. */ private void prepareAUTWorkspace() throws IOException, URISyntaxException { File wsPathFile = new File(getWorkspacePath()); Path wsPath = wsPathFile.toPath(); if (wsPathFile.exists()) { Files.walkFileTree(wsPath, getDeleteFileVisitor()); LOGGER.info("Removed AUT_WS: " + getWorkspacePath()); } Files.createDirectory(wsPath); Map<String, String> env = new HashMap<String, String>(); env.put("create", "true"); FileSystem fs = FileSystems.newFileSystem(getClass().getResource("/DemoWebTests.zip").toURI(), env); Iterable<Path> rootDirectories = fs.getRootDirectories(); for (Path root : rootDirectories) { DirectoryStream<Path> directoryStream = Files.newDirectoryStream(root); for (Path path : directoryStream) { if (path.getFileName().startsWith("DemoWebTests.zip")) { LOGGER.info("Found DemoWebTest."); Files.copy(path, Paths.get(wsPath.toString(), "DemoWebTests.zip")); URI uriDemoZip = new URI("jar:" + Paths.get(wsPath.toString(), "/DemoWebTests.zip").toUri()); LOGGER.info(uriDemoZip); FileSystem zipFs = FileSystems.newFileSystem(uriDemoZip, env); copyFolder(zipFs.getPath("/"), Paths.get(getWorkspacePath())); zipFs.close(); } } } fs.close(); LOGGER.info("Created Demoproject in: " + getWorkspacePath()); }