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


Java Path.toUri方法代码示例

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


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

示例1: loadAsResource

import java.nio.file.Path; //导入方法依赖的package包/类
@Override
public Resource loadAsResource(String filename) {
    try {
        Path file = load(filename);
        Resource resource = new UrlResource(file.toUri());
        if(resource.exists() || resource.isReadable()) {
            return resource;
        }
        else {
            throw new StorageFileNotFoundException("Could not read file: " + filename);

        }
    } catch (MalformedURLException e) {
        throw new StorageFileNotFoundException("Could not read file: " + filename, e);
    }
}
 
开发者ID:Yuiffy,项目名称:file-download-upload-zip-demo,代码行数:17,代码来源:FileSystemStorageService.java

示例2: loadAsResource

import java.nio.file.Path; //导入方法依赖的package包/类
@Override
public Resource loadAsResource(UserSessionFile userSessionFile) {
    if (userSessionFile == null) {
        throw new StorageException(
            "Cannot retrieve file when userSessionFile is null!");
    }
    try {
        Path file = load(userSessionFile);
        Resource resource = new UrlResource(file.toUri());
        if (resource.exists() || resource.isReadable()) {
            return resource;
        } else {
            throw new StorageFileNotFoundException(
                "Could not read file: " + userSessionFile.getFilename());

        }
    } catch (MalformedURLException e) {
        throw new StorageFileNotFoundException(
            "Could not read file: " + userSessionFile.getFilename(), e);
    }
}
 
开发者ID:nilshoffmann,项目名称:jmzTab-m,代码行数:22,代码来源:FileSystemStorageService.java

示例3: pathHandlingTest

import java.nio.file.Path; //导入方法依赖的package包/类
@Test
public void pathHandlingTest() {
    System.setProperty("nashorn.persistent.code.cache", codeCache);
    final NashornScriptEngineFactory fac = new NashornScriptEngineFactory();

    fac.getScriptEngine(ENGINE_OPTIONS_NOOPT);

    final Path expectedCodeCachePath = FileSystems.getDefault().getPath(oldUserDir + File.separator + codeCache);
    final Path actualCodeCachePath = FileSystems.getDefault().getPath(System.getProperty(
                        "nashorn.persistent.code.cache")).toAbsolutePath();
    // Check that nashorn code cache is created in current working directory
    assertEquals(actualCodeCachePath, expectedCodeCachePath);
    // Check that code cache dir exists and it's not empty
    final File file = new File(actualCodeCachePath.toUri());
    assertTrue(file.exists(), "No code cache directory was created!");
    assertTrue(file.isDirectory(), "Code cache location is not a directory!");
    assertFalse(file.list().length == 0, "Code cache directory is empty!");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:CodeStoreAndPathTest.java

示例4: loadAsResource

import java.nio.file.Path; //导入方法依赖的package包/类
@Override
public Resource loadAsResource(String filename) {
    try {
        Path file = this.rootLocation.resolve(filename);
        Resource resource = new UrlResource(file.toUri());
        if (resource.exists() || resource.isReadable()) {
            return resource;
        } else {
            throw new UploadFileNotFoundException(
                    "Could not read file: " + filename);

        }
    } catch (MalformedURLException e) {
        throw new UploadFileNotFoundException("Could not read file: " + filename, e);
    }
}
 
开发者ID:itdl,项目名称:AIweb,代码行数:17,代码来源:UploadServiceImpl.java

示例5: writeToXmlFile

import java.nio.file.Path; //导入方法依赖的package包/类
/**
 * Construct a logcfg.xml file from the object model and save it to specified
 * location (put in the conctructor or a setter)
 *
 * @return written file by the specified location
 */
public File writeToXmlFile() throws IOException {
    File logFile = null;
    for (Path path : cfgPaths) {
        logFile = new File(path.toUri());
        fsys.writeInNewFile(content, path.toString());
    }
    return logFile;
}
 
开发者ID:ripreal,项目名称:V8LogScanner,代码行数:15,代码来源:LogBuilder.java

示例6: loadAsResource

import java.nio.file.Path; //导入方法依赖的package包/类
public Resource loadAsResource(String filename) {
    try {
        Path file = load(filename);
        Resource resource = new UrlResource(file.toUri());
        if(resource.exists() || resource.isReadable()) {
            return resource;
        }
        else {
            throw new SIIStemTechnicalException("Could not read file: " + filename);

        }
    } catch (MalformedURLException e) {
        throw new SIIStemTechnicalException("Could not read file: " + filename, e);
    }
}
 
开发者ID:TraineeSIIp,项目名称:PepSIIrup-2017,代码行数:16,代码来源:FileSystemStorageService.java

示例7: loadAsResource

import java.nio.file.Path; //导入方法依赖的package包/类
@Override
public Resource loadAsResource(String filepath) {
    try {
        Path file = load(filepath);
        Resource resource = new UrlResource(file.toUri());
        if(resource.exists() || resource.isReadable()) {
            return resource;
        }else {
            throw new StorageFileNotFoundException("Couldn't read file: " + filepath);
        }
    } catch (MalformedURLException e) {
        throw new StorageFileNotFoundException("Couldn't read file: " + filepath);
    }
}
 
开发者ID:chaokunyang,项目名称:amanda,代码行数:15,代码来源:FileSystemStorageService.java

示例8: contains

import java.nio.file.Path; //导入方法依赖的package包/类
private boolean contains(Collection<Path> searchPath, Path file) throws IOException {

        if (searchPath == null) {
            return false;
        }

        Path enclosingJar = null;
        if (file.getFileSystem().provider() == fsInfo.getJarFSProvider()) {
            URI uri = file.toUri();
            if (uri.getScheme().equals("jar")) {
                String ssp = uri.getSchemeSpecificPart();
                int sep = ssp.lastIndexOf("!");
                if (ssp.startsWith("file:") && sep > 0) {
                    enclosingJar = Paths.get(URI.create(ssp.substring(0, sep)));
                }
            }
        }

        Path nf = normalize(file);
        for (Path p : searchPath) {
            Path np = normalize(p);
            if (np.getFileSystem() == nf.getFileSystem()
                    && Files.isDirectory(np)
                    && nf.startsWith(np)) {
                return true;
            }
            if (enclosingJar != null
                    && Files.isSameFile(enclosingJar, np)) {
                return true;
            }
        }

        return false;
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:Locations.java

示例9: newJarModule

import java.nio.file.Path; //导入方法依赖的package包/类
/**
 * Creates a ModuleReference to a possibly-patched module in a modular JAR.
 */
static ModuleReference newJarModule(ModuleInfo.Attributes attrs,
                                    ModulePatcher patcher,
                                    Path file) {
    URI uri = file.toUri();
    Supplier<ModuleReader> supplier = () -> new JarModuleReader(file, uri);
    HashSupplier hasher = (a) -> ModuleHashes.computeHash(file, a);
    return newModule(attrs, uri, supplier, patcher, hasher);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:ModuleReferences.java

示例10: newJModModule

import java.nio.file.Path; //导入方法依赖的package包/类
/**
 * Creates a ModuleReference to a module in a JMOD file.
 */
static ModuleReference newJModModule(ModuleInfo.Attributes attrs, Path file) {
    URI uri = file.toUri();
    Supplier<ModuleReader> supplier = () -> new JModModuleReader(file, uri);
    HashSupplier hasher = (a) -> ModuleHashes.computeHash(file, a);
    return newModule(attrs, uri, supplier, null, hasher);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:ModuleReferences.java

示例11: loadAsResource

import java.nio.file.Path; //导入方法依赖的package包/类
@Override
public Resource loadAsResource(String filename) {
    try {
        Path file = load(filename);
        Resource resource = new UrlResource(file.toUri());
        if (resource.exists() || resource.isReadable()) {
            return resource;
        } else {
            throw new StorageFileNotFoundException("Could not read chart: " + filename);

        }
    } catch (MalformedURLException e) {
        throw new StorageFileNotFoundException("Could not read chart: " + filename, e);
    }
}
 
开发者ID:robinhowlett,项目名称:handycapper,代码行数:16,代码来源:FileSystemStorageService.java

示例12: readClass

import java.nio.file.Path; //导入方法依赖的package包/类
private ClassInstance readClass(Path path, Predicate<ClassNode> nameObfuscated) {
	ClassNode cn = ClassEnvironment.readClass(path);

	return new ClassInstance(ClassInstance.getId(cn.name), path.toUri(), this, cn, nameObfuscated.test(cn));
}
 
开发者ID:sfPlayer1,项目名称:Matcher,代码行数:6,代码来源:ClassFeatureExtractor.java

示例13: updateBuilding

import java.nio.file.Path; //导入方法依赖的package包/类
@Override
public String updateBuilding(Building building, Floor floor, File floorMapFile) throws IOException {

    AssertParam.throwIfNull(building, "building");
    AssertParam.throwIfNull(floor, "floor");
    AssertParam.throwIfNull(floorMapFile, "floorMapFile");

    String buildingName = building.getBuildingName();
    if (buildingName == null || buildingName.isEmpty()) {
        buildingName = "DefaultBuildingName";
    }


    boolean fileWriteLocalFsSuccess = doInitialImageFolderSetup(buildingName);

    String localTargetFileName = replaceFileEnding(floorMapFile, PersistencyConstants.IMAGE_TARGET_FILE_ENDING);
    String separator = File.separator;
    Path localFilePath = Paths.get(String.format("%s%s%s%s%s%s%s", PersistencyConstants.LOCAL_RESOURCE_DIR, separator,
            PersistencyConstants.LOCAL_MAPS_DIR, separator, buildingName, separator, localTargetFileName));
    File localFile = new File(localFilePath.toUri());

    if (!Files.exists(localFilePath)) {
        OutputStream outputStream = new FileOutputStream(localFilePath.toFile());
        BufferedImage bufferedImage = ImageIO.read(floorMapFile);
        fileWriteLocalFsSuccess = ImageIO.write(bufferedImage, PersistencyConstants.IMAGE_TARGET_FILE_ENDING, outputStream);
    }


    if (fileWriteLocalFsSuccess) {
        String cleanFloorMapPath = String.format("%s%s%s%s%s", PersistencyConstants.LOCAL_MAPS_DIR, separator,
                building.getBuildingName(), separator, localFile.getName());
        floor.setFloorMapPath(cleanFloorMapPath);
        String cleanFloorMapUrl = String.format("building%s?%s=%d", TransmissionConstants.GET_FLOOR_MAP_REST_URL,
                TransmissionConstants.FLOOR_IDENTIFIER_PARAM, floor.getId());
        floor.setFloorMapUrl(cleanFloorMapUrl);
    }

    boolean fileWriteDatabaseSuccess = buildingRepository.save(building) != null;
    boolean operationSuccessful = fileWriteLocalFsSuccess && fileWriteDatabaseSuccess;

    if (operationSuccessful) {
        return ResponseConstants.FLOOR_UPDATE_SUCCESS;
    } else {
        if (!fileWriteLocalFsSuccess) {
            return ResponseConstants.FLOOR_UPDATE_FAILURE_LOCAL_WRITE;
        } else {
            return ResponseConstants.FLOOR_UPDATE_FAILURE_DB_WRITE;
        }

    }

}
 
开发者ID:ProjectIndoor,项目名称:projectindoorweb,代码行数:53,代码来源:PersistencyServiceImpl.java

示例14: of

import java.nio.file.Path; //导入方法依赖的package包/类
@PublicAPI(usage = ACCESS)
public static Location of(Path path) {
    return new FilePathLocation(path.toUri());
}
 
开发者ID:TNG,项目名称:ArchUnit,代码行数:5,代码来源:Location.java

示例15: testCanCompileAgainstExplodedImage

import java.nio.file.Path; //导入方法依赖的package包/类
void testCanCompileAgainstExplodedImage(String loc) throws IOException {
    System.err.println("testCanCompileAgainstExplodedImage(" + loc + ")");
    Path javaHome = prepareJavaHome();
    Path targetPath = javaHome.resolve(loc.replace("*", "/java.base").replace("/", sep));
    try (StandardJavaFileManager fm = javaCompiler.getStandardFileManager(null, null, null)) {
        for (String pack : REQUIRED_PACKAGES) {
            Iterable<JavaFileObject> content = fm.list(StandardLocation.PLATFORM_CLASS_PATH,
                                                       pack,
                                                       EnumSet.allOf(JavaFileObject.Kind.class),
                                                       false);

            for (JavaFileObject jfo : content) {
                String name = jfo.getName();
                int lastSlash = name.lastIndexOf('/');
                name = lastSlash >= 0 ? name.substring(lastSlash + 1) : name;
                Path target = targetPath.resolve(pack.replace(".", sep) + sep + name);
                Files.createDirectories(target.getParent());
                try (InputStream in = jfo.openInputStream()) {
                    Files.copy(in, target);
                }
            }
        }
    }

    System.setProperty("java.home", javaHome.toString());

    try (StandardJavaFileManager fm = javaCompiler.getStandardFileManager(null, null, null)) {
        DiagnosticListener<JavaFileObject> noErrors = d -> {
            if (d.getKind() == Diagnostic.Kind.ERROR)
                throw new IllegalStateException("Unexpected error: " + d);
        };
        ToolBox.JavaSource inputFile =
                new ToolBox.JavaSource("import java.util.List; class Test { List l; }");
        List<JavaFileObject> inputFiles = Arrays.asList(inputFile);
        boolean result =
                javaCompiler.getTask(null, fm, noErrors, null, null, inputFiles).call();
        if (!result) {
            throw new IllegalStateException("Could not compile correctly!");
        }
        JavacTask task =
                (JavacTask) javaCompiler.getTask(null, fm, noErrors, null, null, inputFiles);
        task.parse();
        TypeElement juList = task.getElements().getTypeElement("java.util.List");
        if (juList == null)
            throw new IllegalStateException("Cannot resolve java.util.List!");
        URI listSource = ((ClassSymbol) juList).classfile.toUri();
        if (!listSource.toString().startsWith(javaHome.toUri().toString()))
            throw new IllegalStateException(  "Did not load java.util.List from correct place, " +
                                              "actual location: " + listSource.toString() +
                                            "; expected prefix: " + javaHome.toUri());
    }

    System.err.println("finished.");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:55,代码来源:ExplodedImage.java


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