use of java.nio.file.FileSystem in project lucene-solr by apache.
the class TestIOUtils method testNVME.
public void testNVME() throws Exception {
assumeFalse("windows is not supported", Constants.WINDOWS);
Path dir = createTempDir();
dir = FilterPath.unwrap(dir).toRealPath();
// fake ssd
FileStore root = new MockFileStore(dir.toString() + " (/dev/nvme0n1p1)", "btrfs", "/dev/nvme0n1p1");
// make a fake /dev/nvme0n1p1 for it
Path devdir = dir.resolve("dev");
Files.createDirectories(devdir);
Files.createFile(devdir.resolve("nvme0n1p1"));
// make a fake /sys/block/nvme0n1/queue/rotational file for it
Path sysdir = dir.resolve("sys").resolve("block").resolve("nvme0n1").resolve("queue");
Files.createDirectories(sysdir);
try (OutputStream o = Files.newOutputStream(sysdir.resolve("rotational"))) {
o.write("0\n".getBytes(StandardCharsets.US_ASCII));
}
// As test for the longest path match, add some other devices (that have no queue/rotational), too:
Files.createFile(dir.resolve("sys").resolve("block").resolve("nvme0"));
Files.createFile(dir.resolve("sys").resolve("block").resolve("dummy"));
Files.createFile(dir.resolve("sys").resolve("block").resolve("nvm"));
Map<String, FileStore> mappings = Collections.singletonMap(dir.toString(), root);
FileSystem mockLinux = new MockLinuxFileSystemProvider(dir.getFileSystem(), mappings, dir).getFileSystem(null);
Path mockPath = mockLinux.getPath(dir.toString());
assertFalse(IOUtils.spinsLinux(mockPath));
}
use of java.nio.file.FileSystem in project lucene-solr by apache.
the class TestIOUtils method testNfsSpins.
public void testNfsSpins() throws Exception {
Path dir = createTempDir();
dir = FilterPath.unwrap(dir).toRealPath();
// fake nfs
FileStore root = new MockFileStore(dir.toString() + " (somenfsserver:/some/mount)", "nfs", "somenfsserver:/some/mount");
Map<String, FileStore> mappings = Collections.singletonMap(dir.toString(), root);
FileSystem mockLinux = new MockLinuxFileSystemProvider(dir.getFileSystem(), mappings, dir).getFileSystem(null);
Path mockPath = mockLinux.getPath(dir.toString());
assertTrue(IOUtils.spinsLinux(mockPath));
}
use of java.nio.file.FileSystem in project lucene-solr by apache.
the class TestIOUtils method testRotatingPlatters.
public void testRotatingPlatters() throws Exception {
assumeFalse("windows is not supported", Constants.WINDOWS);
Path dir = createTempDir();
dir = FilterPath.unwrap(dir).toRealPath();
// fake ssd
FileStore root = new MockFileStore(dir.toString() + " (/dev/zzz1)", "reiser4", "/dev/zzz1");
// make a fake /dev/zzz1 for it
Path devdir = dir.resolve("dev");
Files.createDirectories(devdir);
Files.createFile(devdir.resolve("zzz1"));
// make a fake /sys/block/zzz/queue/rotational file for it
Path sysdir = dir.resolve("sys").resolve("block").resolve("zzz").resolve("queue");
Files.createDirectories(sysdir);
try (OutputStream o = Files.newOutputStream(sysdir.resolve("rotational"))) {
o.write("1\n".getBytes(StandardCharsets.US_ASCII));
}
Map<String, FileStore> mappings = Collections.singletonMap(dir.toString(), root);
FileSystem mockLinux = new MockLinuxFileSystemProvider(dir.getFileSystem(), mappings, dir).getFileSystem(null);
Path mockPath = mockLinux.getPath(dir.toString());
assertTrue(IOUtils.spinsLinux(mockPath));
}
use of java.nio.file.FileSystem in project logging-log4j2 by apache.
the class ResolverUtilTest method createJar.
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);
}
}
use of java.nio.file.FileSystem in project beam by apache.
the class ApexYarnLauncher method createJar.
/**
* Create a jar file from the given directory.
* @param dir source directory
* @param jarFile jar file name
* @throws IOException when file cannot be created
*/
public static void createJar(File dir, File jarFile) throws IOException {
final Map<String, ?> env = Collections.singletonMap("create", "true");
if (jarFile.exists() && !jarFile.delete()) {
throw new RuntimeException("Failed to remove " + jarFile);
}
URI uri = URI.create("jar:" + jarFile.toURI());
try (final FileSystem zipfs = FileSystems.newFileSystem(uri, env)) {
File manifestFile = new File(dir, JarFile.MANIFEST_NAME);
Files.createDirectory(zipfs.getPath("META-INF"));
try (final OutputStream out = Files.newOutputStream(zipfs.getPath(JarFile.MANIFEST_NAME))) {
if (!manifestFile.exists()) {
new Manifest().write(out);
} else {
FileUtils.copyFile(manifestFile, out);
}
}
final java.nio.file.Path root = dir.toPath();
Files.walkFileTree(root, new java.nio.file.SimpleFileVisitor<Path>() {
String relativePath;
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
relativePath = root.relativize(dir).toString();
if (!relativePath.isEmpty()) {
if (!relativePath.endsWith("/")) {
relativePath += "/";
}
if (!relativePath.equals("META-INF/")) {
final Path dstDir = zipfs.getPath(relativePath);
Files.createDirectory(dstDir);
}
}
return super.preVisitDirectory(dir, attrs);
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
String name = relativePath + file.getFileName();
if (!JarFile.MANIFEST_NAME.equals(name)) {
try (final OutputStream out = Files.newOutputStream(zipfs.getPath(name))) {
FileUtils.copyFile(file.toFile(), out);
}
}
return super.visitFile(file, attrs);
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
relativePath = root.relativize(dir.getParent()).toString();
if (!relativePath.isEmpty() && !relativePath.endsWith("/")) {
relativePath += "/";
}
return super.postVisitDirectory(dir, exc);
}
});
}
}
Aggregations