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


Java Path类代码示例

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


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

示例1: log

import java.nio.file.Path; //导入依赖的package包/类
public static void log (String message, @NotNull LogFile logFile, boolean override)
{
    try
    {
        Path pathToFile = Paths.get(pathToLogs.toString(), logFile.path());

        if (!Files.exists(pathToLogs) || !Files.isDirectory(pathToLogs)) Files.createDirectory(pathToLogs);
        if (!Files.exists(pathToFile) || !Files.isRegularFile(pathToFile)) Files.createFile(pathToFile);

        String oldContent = override ? "" : cat(logFile);
        String newContent = (oldContent.isEmpty()) ? message : oldContent + "\n" + message;

        BufferedWriter out = new BufferedWriter(new FileWriter(pathToFile.toString()));
        out.write(newContent);
        out.close();
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
}
 
开发者ID:AlexBolot,项目名称:PopulationSimulator,代码行数:22,代码来源:Logger.java

示例2: testPositionNegative

import java.nio.file.Path; //导入依赖的package包/类
@Test
public void testPositionNegative() throws Exception {
    Path tempDir = Files.createTempDirectory("jaffree");
    Path outputPath = tempDir.resolve(VIDEO_MP4.getFileName());

    FFmpegResult result = FFmpeg.atPath(BIN)
            .addInput(UrlInput
                    .fromPath(VIDEO_MP4)
                    .setPositionEof(-7, TimeUnit.SECONDS)
            )
            .addOutput(UrlOutput
                    .toPath(outputPath)
                    .copyAllCodecs())
            .execute();

    Assert.assertNotNull(result);

    double outputDuration = getDuration(outputPath);

    Assert.assertEquals(7.0, outputDuration, 0.5);
}
 
开发者ID:kokorin,项目名称:Jaffree,代码行数:22,代码来源:FFmpegTest.java

示例3: scanDirectory

import java.nio.file.Path; //导入依赖的package包/类
private void scanDirectory(File directory, String prefix, Set<File> ancestors, Collection<Path> collector)
    throws IOException {
  File canonical = directory.getCanonicalFile();
  if (ancestors.contains(canonical)) {
    // A cycle in the filesystem, for example due to a symbolic link.
    return;
  }
  File[] files = directory.listFiles();
  if (files == null) {
    return;
  }
  HashSet<File> objects = new HashSet<>();
  objects.addAll(ancestors);
  objects.add(canonical);
  Set<File> newAncestors = Collections.unmodifiableSet(objects);
  for (File f : files) {
    String name = f.getName();
    if (f.isDirectory()) {
      scanDirectory(f, prefix + name + "/", newAncestors, collector);
    } else {
      collector.add(f.toPath());
    }
  }
}
 
开发者ID:scalecube,项目名称:config,代码行数:25,代码来源:ClassPathConfigSource.java

示例4: Repository

import java.nio.file.Path; //导入依赖的package包/类
Repository(IStore store, String repository_name, final Path base_path) throws RepositoryException {

        if (!repositoryNameIsLegal(repository_name)) {
            throw new RepositoryException("Illegal repository name <" + repository_name + ">");
        }

        this.store = store;
        this.repository_name = repository_name;
        repository_path = base_path.resolve(repository_name);
        repository_directory = repository_path.toFile();

        bucket_cache = new HashMap<>();

        if (!repository_directory.exists()) {  // only if the repo doesn't exist - try and make the directory

            if (!repository_directory.mkdir()) {
                throw new RepositoryException("Directory " + repository_directory.getAbsolutePath() + " does not exist and cannot be created");
            }

        } else { // it does exist - check that it is a directory
            if (!repository_directory.isDirectory()) {
                throw new RepositoryException(repository_directory.getAbsolutePath() + " exists but is not a directory");
            }
        }
    }
 
开发者ID:stacs-srg,项目名称:storr,代码行数:26,代码来源:Repository.java

示例5: savePdfTablePagesDebugImages

import java.nio.file.Path; //导入依赖的package包/类
/**
 * Saves debug images of PDF pages from specified range and saves them in specified directory.
 *
 * @param document  PDF document instance
 * @param startPage first page in range to process (first page == 1)
 * @param endPage   last page in range
 * @param outputDir destination directory
 * @throws IOException
 */
public void savePdfTablePagesDebugImages(PDDocument document, int startPage, int endPage, Path outputDir) throws IOException {
    TableExtractor debugExtractor = new TableExtractor(settings);
    PDFRenderer renderer = new PDFRenderer(document);
    for (int page = startPage - 1; page < endPage; ++page) {
        PdfTableSettings debugSettings = PdfTableSettings.getBuilder()
                .setDebugImages(true)
                .setDebugFileOutputDir(outputDir)
                .setDebugFilename("page_" + (page + 1))
                .build();
        debugExtractor.setSettings(debugSettings);
        BufferedImage bi;
        synchronized (this) {
            bi = renderer.renderImageWithDPI(page, settings.getPdfRenderingDpi(), ImageType.RGB);
        }
        debugExtractor.getTableBoundingRectangles(bufferedImage2GrayscaleMat(bi));
    }
}
 
开发者ID:rostrovsky,项目名称:pdf-table,代码行数:27,代码来源:PdfTableReader.java

示例6: setup

import java.nio.file.Path; //导入依赖的package包/类
@BeforeClass
public void setup() {
    theFileSystem = FileSystems.getFileSystem(URI.create("jrt:/"));
    Path modulesPath = Paths.get(System.getProperty("java.home"),
            "lib", "modules");
    isExplodedBuild = Files.notExists(modulesPath);
    if (isExplodedBuild) {
        System.out.printf("%s doesn't exist.", modulesPath.toString());
        System.out.println();
        System.out.println("It is most probably an exploded build."
                + " Skip non-default FileSystem testing.");
        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 {
        fs = FileSystems.newFileSystem(URI.create("jrt:/"), env);
    } catch (IOException ioExp) {
        throw new RuntimeException(ioExp);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:Basic.java

示例7: testByteSource_size_ofSymlinkToDirectory

import java.nio.file.Path; //导入依赖的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:zugzug90,项目名称:guava-mock,代码行数:19,代码来源:MoreFilesTest.java

示例8: testJavaSE_Fail

import java.nio.file.Path; //导入依赖的package包/类
@Test
public void testJavaSE_Fail(Path base) throws Exception {
    Path src = base.resolve("src");
    tb.writeJavaFiles(src,
            "module m { requires java.se; }",
            "import com.sun.source.tree.Tree;\n" // not in java.se (in jdk.compiler)
            + "class Test {\n"
            + "    Tree t;\n"
            + "}");
    Path classes = base.resolve("classes");
    Files.createDirectories(classes);

    String log = new JavacTask(tb, Task.Mode.CMDLINE)
            .options("-XDrawDiagnostics")
            .files(findJavaFiles(src))
            .outdir(classes)
            .run(Task.Expect.FAIL)
            .writeAll()
            .getOutput(Task.OutputKind.DIRECT);

    if (!log.contains("Test.java:1:22: compiler.err.package.not.visible: com.sun.source.tree, (compiler.misc.not.def.access.does.not.read: m, com.sun.source.tree, jdk.compiler)"))
        throw new Exception("expected output not found");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:RequiresTransitiveTest.java

示例9: testReloadClasspath

import java.nio.file.Path; //导入依赖的package包/类
public void testReloadClasspath() {
    Function<String,String> prog = (s) -> String.format(
            "package pkg; public class A { public String toString() { return \"%s\"; } }\n", s);
    Compiler compiler = new Compiler();
    Path outDir = Paths.get("testClasspathDirectory");
    compiler.compile(outDir, prog.apply("A"));
    Path classpath = compiler.getPath(outDir);
    test(
            (a) -> assertCommand(a, "/env --class-path " + classpath,
                    "|  Setting new options and restoring state."),
            (a) -> assertMethod(a, "String foo() { return (new pkg.A()).toString(); }",
                    "()String", "foo"),
            (a) -> assertVariable(a, "String", "v", "foo()", "\"A\""),
            (a) -> {
                   if (!a) compiler.compile(outDir, prog.apply("Aprime"));
                   assertCommand(a, "/reload",
                    "|  Restarting and restoring state.\n" +
                    "-: String foo() { return (new pkg.A()).toString(); }\n" +
                    "-: String v = foo();\n");
                   },
            (a) -> assertCommand(a, "v", "v ==> \"Aprime\""),
            (a) -> evaluateExpression(a, "String", "foo()", "\"Aprime\""),
            (a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "Aprime")
    );
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:ToolReloadTest.java

示例10: main

import java.nio.file.Path; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    // create a zip file, and read it in as a byte array
    Path path = Files.createTempFile("bad", ".zip");
    try (OutputStream os = Files.newOutputStream(path);
            ZipOutputStream zos = new ZipOutputStream(os)) {
        ZipEntry e = new ZipEntry("x");
        zos.putNextEntry(e);
        zos.write((int) 'x');
    }
    int len = (int) Files.size(path);
    byte[] data = new byte[len];
    try (InputStream is = Files.newInputStream(path)) {
        is.read(data);
    }
    Files.delete(path);

    // year, month, day are zero
    testDate(data.clone(), 0, LocalDate.of(1979, 11, 30));
    // only year is zero
    testDate(data.clone(), 0 << 25 | 4 << 21 | 5 << 16, LocalDate.of(1980, 4, 5));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:ZeroDate.java

示例11: testModuleNotInModuleSrcPath

import java.nio.file.Path; //导入依赖的package包/类
@Test
public void testModuleNotInModuleSrcPath(Path base) throws Exception {
    Path src = base.resolve("src");
    Path m = src.resolve("m");
    Files.createDirectories(m);
    Path extra = base.resolve("m");
    tb.writeJavaFiles(extra, "module m {}");
    Path classes = base.resolve("classes");
    Files.createDirectories(classes);

    String log = new JavacTask(tb)
            .options("-XDrawDiagnostics", "--module-source-path", src.toString())
            .outdir(classes)
            .files(findJavaFiles(extra))
            .run(Task.Expect.FAIL)
            .writeAll()
            .getOutput(Task.OutputKind.DIRECT);
    if (!log.contains("module-info.java:1:1: compiler.err.module.not.found.on.module.source.path"))
        throw new Exception("expected output not found");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ModulesAndModuleSourcePathTest.java

示例12: testReportNoBranch

import java.nio.file.Path; //导入依赖的package包/类
@Test
public void testReportNoBranch() throws Exception {
	Path path = Paths.get("target", "coverage", "HtmlReportCoverageHandlerTest", "testReportNoBranch");

	Files.deleteIfExists(path.resolve("covertest/HtmlReportCoverageHandlerTest/testReportNoBranch.html"));

	// カバレッジ用インスタンスをクリア
	Field field = AbstractAgent.class.getDeclaredField("coverageHandlerRef");
	field.setAccessible(true);
	@SuppressWarnings("unchecked")
	AtomicReference<CoverageHandler> ref = (AtomicReference<CoverageHandler>) field.get(null);

	System.setProperty(SqlAgent.KEY_SQL_COVERAGE + ".dir", path.toString());
	CoverageHandler before = ref.get();
	ref.set(new HtmlReportCoverageHandler());
	try (SqlAgent agent = config.agent()) {
		agent.query("covertest/HtmlReportCoverageHandlerTest/testReportNoBranch").collect();
	}

	assertThat(Files.readAllLines(path.resolve("covertest/HtmlReportCoverageHandlerTest/testReportNoBranch.html"))
			.size(), is(61));

	ref.set(before);
	System.clearProperty(SqlAgent.KEY_SQL_COVERAGE + ".dir");
}
 
开发者ID:future-architect,项目名称:uroborosql,代码行数:26,代码来源:HtmlReportCoverageHandlerTest.java

示例13: launchCompiler

import java.nio.file.Path; //导入依赖的package包/类
public static OutputAnalyzer launchCompiler(String libName, String item, List<String> extraopts,
        List<String> compList) {
    Path file = null;
    if (compList != null && !compList.isEmpty()) {
        file = Paths.get(METHODS_LIST_FILENAME);
        try {
            Files.write(file, compList, StandardOpenOption.CREATE);
        } catch (IOException e) {
            throw new Error("Couldn't write " + METHODS_LIST_FILENAME + " " + e, e);
        }
    }
    List<String> args = new ArrayList<>();
    args.add("--compile-with-assertions");
    args.add("--output");
    args.add(libName);
    if (file != null) {
        args.add("--compile-commands");
        args.add(file.toString());
    }
    args.add("--class-name");
    args.add(item);
    String linker = resolveLinker();
    if (linker != null) {
        args.add("--linker-path");
        args.add(linker);
    }
    // Execute with asserts
    args.add("-J-ea");
    args.add("-J-esa");
    return launchJaotc(args, extraopts);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:AotCompiler.java

示例14: createDirectory

import java.nio.file.Path; //导入依赖的package包/类
@Override
public void createDirectory(Path dir, FileAttribute<?>... attrs)
    throws IOException
{
    triggerEx(dir, "createDirectory");
    Files.createDirectory(unwrap(dir), attrs);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:FaultyFileSystem.java

示例15: testSingleModuleOptionWithNoModuleOnSourcePath

import java.nio.file.Path; //导入依赖的package包/类
@Test
public void testSingleModuleOptionWithNoModuleOnSourcePath(Path base) throws Exception {
    Path src = base.resolve("src");
    Path mod1 = Paths.get(src.toString(), "m1");
    execNegativeTask("--source-path", mod1.toString(),
             "--module", "m1");
    assertMessagePresent("module m1 not found on source path");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:Modules.java


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