当前位置: 首页>>代码示例>>Java>>正文


Java FileSystem类代码示例

本文整理汇总了Java中java.nio.file.FileSystem的典型用法代码示例。如果您正苦于以下问题:Java FileSystem类的具体用法?Java FileSystem怎么用?Java FileSystem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FileSystem类属于java.nio.file包,在下文中一共展示了FileSystem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onTest

import java.nio.file.FileSystem; //导入依赖的package包/类
@Test
public void onTest() throws Exception {
    File testZip = new File("test.zip");
    JarFile jarFile = new JarFile(testZip);
    jarFile.stream().forEach((jarEntry -> {
        System.out.println(jarEntry.getName());
        if (jarEntry.getName().lastIndexOf('/') != -1) {
            System.out.println( "parent -> " + jarEntry.getName().substring(0, jarEntry
                    .getName()
                    .lastIndexOf('/')));
        }
    }));
    System.out.println("Filesystems");
    FileSystem fileSystem = FileSystems.newFileSystem(testZip.toPath(), null);
    Path meow = fileSystem.getPath("meow/");
    Files.list(meow).forEach((path) -> System.out.println(path.getFileName()));
}
 
开发者ID:PizzaCrust,项目名称:Passion,代码行数:18,代码来源:JavaTesting.java

示例2: testExtractBatchSpreadsheetWithArea

import java.nio.file.FileSystem; //导入依赖的package包/类
@Test
public void testExtractBatchSpreadsheetWithArea() throws ParseException, IOException {
    FileSystem fs = FileSystems.getDefault();
    String expectedCsv = UtilsForTesting.loadCsv("src/test/resources/technology/tabula/csv/spreadsheet_no_bounding_frame.csv");
    Path tmpFolder = Files.createTempDirectory("tabula-java-batch-test");
    tmpFolder.toFile().deleteOnExit();

    Path copiedPDF = tmpFolder.resolve(fs.getPath("spreadsheet.pdf"));
    Path sourcePDF = fs.getPath("src/test/resources/technology/tabula/spreadsheet_no_bounding_frame.pdf");
    Files.copy(sourcePDF, copiedPDF);
    copiedPDF.toFile().deleteOnExit();

    this.csvFromCommandLineArgs(new String[]{
            "-b", tmpFolder.toString(),
            "-p", "1", "-a",
            "150.56,58.9,654.7,536.12", "-f",
            "CSV"
    });

    Path csvPath = tmpFolder.resolve(fs.getPath("spreadsheet.csv"));
    assertTrue(csvPath.toFile().exists());
    assertArrayEquals(expectedCsv.getBytes(), Files.readAllBytes(csvPath));
}
 
开发者ID:redmyers,项目名称:484_P7_1-Java,代码行数:24,代码来源:TestCommandLineApp.java

示例3: validate

import java.nio.file.FileSystem; //导入依赖的package包/类
static void validate(Module module) throws IOException {
    ModuleDescriptor md = module.getDescriptor();

    // read m1/module-info.class
    FileSystem fs = FileSystems.newFileSystem(URI.create("jrt:/"),
                                              Collections.emptyMap());
    Path path = fs.getPath("/", "modules", module.getName(), "module-info.class");
    ModuleDescriptor md1 = ModuleDescriptor.read(Files.newInputStream(path));


    // check the module descriptor of a system module and read from jimage
    checkPackages(md.packages(), "p1", "p2");
    checkPackages(md1.packages(), "p1", "p2");

    try (InputStream in = Files.newInputStream(path)) {
        checkModuleTargetAttribute(in, "p1");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:Main.java

示例4: fetchFailsGracefully

import java.nio.file.FileSystem; //导入依赖的package包/类
@Test
public void fetchFailsGracefully() throws Exception {

    final FileSystem fs = Jimfs.newFileSystem();

    final RecipeSource recipeSource = LazyCookbookRecipeSource.of(
        fs.getPath(System.getProperty("user.home"), ".buckaroo", "buckaroo-recipes"));

    final CountDownLatch latch = new CountDownLatch(1);

    recipeSource.fetch(RecipeIdentifier.of(Identifier.of("nosuchorg"), Identifier.of("nosuchrecipe")))
        .result()
        .subscribe(x -> {

        }, error -> {
            latch.countDown();
        });

    latch.await(5000L, TimeUnit.MILLISECONDS);
}
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:21,代码来源:LazyCookbookRecipeSourceTest.java

示例5: main

import java.nio.file.FileSystem; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    FileSystem fs = FileSystems.getDefault();
    if (fs.getClass().getModule() == Object.class.getModule())
        throw new RuntimeException("FileSystemProvider not overridden");

    // exercise the file system
    Path dir = Files.createTempDirectory("tmp");
    if (dir.getFileSystem() != fs)
        throw new RuntimeException("'dir' not in default file system");
    System.out.println("created: " + dir);

    Path foo = Files.createFile(dir.resolve("foo"));
    if (foo.getFileSystem() != fs)
        throw new RuntimeException("'foo' not in default file system");
    System.out.println("created: " + foo);

    // exercise interop with java.io.File
    File file = foo.toFile();
    Path path = file.toPath();
    if (path.getFileSystem() != fs)
        throw new RuntimeException("'path' not in default file system");
    if (!path.equals(foo))
        throw new RuntimeException(path + " not equal to " + foo);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:Main.java

示例6: testDeleteRecursively_nonDirectoryFile

import java.nio.file.FileSystem; //导入依赖的package包/类
public void testDeleteRecursively_nonDirectoryFile() throws IOException {
  try (FileSystem fs = newTestFileSystem(SECURE_DIRECTORY_STREAM)) {
    Path file = fs.getPath("dir/a");
    assertTrue(Files.isRegularFile(file, NOFOLLOW_LINKS));

    MoreFiles.deleteRecursively(file);

    assertFalse(Files.exists(file, NOFOLLOW_LINKS));

    Path symlink = fs.getPath("/symlinktodir");
    assertTrue(Files.isSymbolicLink(symlink));

    Path realSymlinkTarget = symlink.toRealPath();
    assertTrue(Files.isDirectory(realSymlinkTarget, NOFOLLOW_LINKS));

    MoreFiles.deleteRecursively(symlink);

    assertFalse(Files.exists(symlink, NOFOLLOW_LINKS));
    assertTrue(Files.isDirectory(realSymlinkTarget, NOFOLLOW_LINKS));
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:22,代码来源:MoreFilesTest.java

示例7: testNewFileSystemWithJavaHome

import java.nio.file.FileSystem; //导入依赖的package包/类
@Test
public void testNewFileSystemWithJavaHome() throws Exception {
    if (isExplodedBuild) {
        System.out.println("Skip testNewFileSystemWithJavaHome"
                + " since this is an exploded build");
        return;
    }

    Map<String, String> env = new HashMap<>();
    // set java.home property to be underlying java.home
    // so that jrt-fs.jar loading is exercised.
    env.put("java.home", System.getProperty("java.home"));
    try (FileSystem fs = FileSystems.newFileSystem(URI.create("jrt:/"), env)) {
        checkFileSystem(fs);
        // jrt-fs.jar classes are loaded by another (non-boot) loader in this case
        assertNotNull(fs.provider().getClass().getClassLoader());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:Basic.java

示例8: testByteSource_size_ofSymlinkToDirectory

import java.nio.file.FileSystem; //导入依赖的package包/类
public void testByteSource_size_ofSymlinkToDirectory() throws IOException {
  try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) {
    Path dir = fs.getPath("dir");
    Files.createDirectory(dir);
    Path link = fs.getPath("link");
    Files.createSymbolicLink(link, dir);

    ByteSource source = MoreFiles.asByteSource(link);

    assertThat(source.sizeIfKnown()).isAbsent();

    try {
      source.size();
      fail();
    } catch (IOException expected) {
    }
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:19,代码来源:MoreFilesTest.java

示例9: resolverWorksWithGitHub2

import java.nio.file.FileSystem; //导入依赖的package包/类
@Test
public void resolverWorksWithGitHub2() throws Exception {

    final FileSystem fs = Jimfs.newFileSystem();

    final RecipeSource recipeSource = GitProviderRecipeSource.of(
        fs,
        GitHubGitProvider.of());

    final Single<ResolvedDependencies> task = AsyncDependencyResolver.resolve(
        recipeSource,
        ImmutableList.of(Dependency.of(
            RecipeIdentifier.of("github", "njlr", "test-lib-e"),
            AnySemanticVersion.of())))
        .result();

    final ResolvedDependencies resolved =
        task.timeout(120, TimeUnit.SECONDS).blockingGet();

    assertTrue(resolved.dependencies.containsKey(
        RecipeIdentifier.of("github", "njlr", "test-lib-e")));
}
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:23,代码来源:AsyncDependencyResolverTest.java

示例10: getDirectory

import java.nio.file.FileSystem; //导入依赖的package包/类
private static Path getDirectory(FileSystem fileSystem, String propertyName, String... folders) {
    Objects.requireNonNull(fileSystem);
    Objects.requireNonNull(propertyName);
    Objects.requireNonNull(folders);

    Path directory;

    String directoryName = System.getProperty(propertyName);
    if (directoryName != null) {
        directory = fileSystem.getPath(directoryName);
    } else {
        directory = fileSystem.getPath(System.getProperty("user.home"), folders);
    }

    return directory;

}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:18,代码来源:PlatformConfig.java

示例11: test

import java.nio.file.FileSystem; //导入依赖的package包/类
@Test
public void test() throws IOException {
    try (FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix())) {
        InMemoryPlatformConfig platformConfig = new InMemoryPlatformConfig(fileSystem);
        MapModuleConfig moduleConfig = platformConfig.createModuleConfig("load-flow-action-simulator");
        moduleConfig.setClassProperty("load-flow-factory", LoadFlowFactoryMock.class);
        moduleConfig.setStringProperty("max-iterations", "15");
        moduleConfig.setStringProperty("ignore-pre-contingency-violations", "true");

        LoadFlowActionSimulatorConfig config = LoadFlowActionSimulatorConfig.load(platformConfig);

        assertEquals(LoadFlowFactoryMock.class, config.getLoadFlowFactoryClass());
        config.setLoadFlowFactoryClass(AnotherLoadFlowFactoryMock.class);
        assertEquals(AnotherLoadFlowFactoryMock.class, config.getLoadFlowFactoryClass());

        assertEquals(15, config.getMaxIterations());
        config.setMaxIterations(10);
        assertEquals(10, config.getMaxIterations());

        assertTrue(config.isIgnorePreContingencyViolations());
        config.setIgnorePreContingencyViolations(false);
        assertFalse(config.isIgnorePreContingencyViolations());
    }
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:25,代码来源:LoadFlowActionSimulatorConfigTest.java

示例12: test8069211

import java.nio.file.FileSystem; //导入依赖的package包/类
static void test8069211() throws Exception {
    // create a new filesystem, copy this file into it
    Map<String, Object> env = new HashMap<String, Object>();
    env.put("create", "true");
    Path fsPath = getTempPath();
    try (FileSystem fs = newZipFileSystem(fsPath, env);) {
        OutputStream out = Files.newOutputStream(fs.getPath("/foo"));
        out.write("hello".getBytes());
        out.close();
        out.close();
    }
    try (FileSystem fs = newZipFileSystem(fsPath, new HashMap<String, Object>())) {
        if (!Arrays.equals(Files.readAllBytes(fs.getPath("/foo")),
                           "hello".getBytes())) {
            throw new RuntimeException("entry close() failed");
        }
    } catch (Exception x) {
        throw new RuntimeException("entry close() failed", x);
    } finally {
        Files.delete(fsPath);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:ZipFSTester.java

示例13: testUnix

import java.nio.file.FileSystem; //导入依赖的package包/类
@Test
public void testUnix() throws Exception {
    final FileSystem fileSystem = newUnixFileSystem();
    final Path path = fileSystem.getPath("/var/log/syslog");
    final PathSet pathSet = new SinglePathSet(path.toString(), fileSystem);

    assertEquals(path.getParent(), pathSet.getRootPath());
    assertTrue(pathSet.isInSet(path));
    assertTrue("Path list should be empty without any files in the file system",
            pathSet.getPaths().isEmpty());

    Files.createDirectories(path.getParent());
    Files.createFile(path);

    assertEquals("Path list should not be empty after creating the file",
            ImmutableSet.of(path), pathSet.getPaths());
}
 
开发者ID:DevOpsStudio,项目名称:Re-Collector,代码行数:18,代码来源:SinglePathSetTest.java

示例14: z2zmove

import java.nio.file.FileSystem; //导入依赖的package包/类
private static void z2zmove(FileSystem src, FileSystem dst, String path)
    throws IOException
{
    Path srcPath = src.getPath(path);
    Path dstPath = dst.getPath(path);

    if (Files.isDirectory(srcPath)) {
        if (!Files.exists(dstPath))
            mkdirs(dstPath);
        try (DirectoryStream<Path> ds = Files.newDirectoryStream(srcPath)) {
            for (Path child : ds) {
                z2zmove(src, dst,
                        path + (path.endsWith("/")?"":"/") + child.getFileName());
            }
        }
    } else {
        //System.out.println("moving..." + path);
        Path parent = dstPath.getParent();
        if (parent != null && Files.notExists(parent))
            mkdirs(parent);
        Files.move(srcPath, dstPath);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:ZipFSTester.java

示例15: mockPath

import java.nio.file.FileSystem; //导入依赖的package包/类
protected Path mockPath(Path parent, String name, long size) {
	FileSystem fileSystem = parent.getFileSystem();
	Path subPath = mock(Path.class);
	File subPathToFile = mock(File.class);
	when(subPath.toFile()).thenReturn(subPathToFile);
	when(subPathToFile.length()).thenReturn(size);
	when(subPathToFile.exists()).thenReturn(true);
	when(subPath.getFileSystem()).thenReturn(fileSystem);
	when(subPath.resolve(anyString())).thenAnswer(invoke -> {
		String childName = (String) invoke.getArguments()[0];
		return mockPath(subPath, childName);
	});
	when(subPath.getParent()).thenReturn(parent);
	when(fileSystem.getPath(parent.toString(), name)).thenReturn(subPath);
	String fullPath = (parent.toString() + "/" + name).replace("//", "/");
	when(fileSystem.getPath(fullPath)).thenReturn(subPath);
	when(subPath.toString()).thenReturn(fullPath);
	Path subPathFileName = mock(Path.class);
	when(subPathFileName.toString()).thenReturn(name);
	when(subPath.getFileName()).thenReturn(subPathFileName);
	return subPath;
}
 
开发者ID:tfiskgul,项目名称:mux2fs,代码行数:23,代码来源:Fixture.java


注:本文中的java.nio.file.FileSystem类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。