Package java.nio.file

Examples of java.nio.file.Path


  public void copyIfSrcExistsAndTargetDoesnt(URI srcFile, URI targetFile) throws IOException {
    this.copyIfSrcExistsAndTargetDoesnt(castToPath(srcFile), castToPath(targetFile));
  }

  private Path castToPath(Object locator) {
    final Path path;
    if (locator instanceof Path) {
      path = (Path) locator;
    } else if (locator instanceof String) {
      path = Paths.get((String) locator);
    } else if (locator instanceof File) {
View Full Code Here


   * Allows to get the language of the program.
   * @return The read language, or the default language.
   */
  public Lang readLang() {
    try {
      final Path xml = Paths.get(LPath.PATH_PREFERENCES_XML_FILE);

      if(Files.exists(xml)) {
              final Node node = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(Files.newInputStream(xml)).getFirstChild();
              final NodeList nl;

View Full Code Here

  private DirectoryContent getContent(Directory dir) {
    Set<File> foundFiles = new HashSet<>();
    Set<String> foundSubDirs = new HashSet<>();
    DirectoryContent content = new DirectoryContent(dir.getPath(), foundSubDirs, foundFiles);
   
    Path path = Paths.get(dir.getPath());
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) {
        for (Path file: stream) {
          BasicFileAttributeView view = getFileAttributeView(file,
              BasicFileAttributeView.class);
          BasicFileAttributes attr = view.readAttributes();
View Full Code Here

  /**
   * Recursively adds directories to a zip file.
   */
  private void addDirectoryToZip(File topDirectory, File directory, ZipOutputStream out) throws IOException {
    Path top = Paths.get(topDirectory.getAbsolutePath());

    File[] files = directory.listFiles();
    byte[] buffer = new byte[BUFFER_SIZE];

    for (int i = 0; i < files.length; i++) {
      Path entry = Paths.get(files[i].getAbsolutePath());
      Path relative = top.relativize(entry);
      String entryName = relative.toString();
      if (files[i].isDirectory()) {
        entryName += FILE_SEPARATOR;
      }

      out.putNextEntry(new ZipEntry(entryName.replace("\\", "/")));
View Full Code Here

  public MavenResolver(Path basePath) {
    this.basePath = basePath;
  }

  public Path resolve(MavenReference reference) throws IOException {
    Path artifactPath = toPath(reference.groupId, reference.artifactId);

    if (reference.versionId == null) {
      reference.versionId = resolveVersion(artifactPath, reference);
    }

    if (reference.classifier == null) {
      reference.classifier = "jar";
    }

    Path versionedPath = artifactPath.resolve(reference.versionId);
    Path artifactMavenMetadataPath = versionedPath.resolve("maven-metadata.xml");

    log.info("Reading file: " + artifactMavenMetadataPath);
    String mavenMetadataXml = IoUtils.readAll(Files.newInputStream(artifactMavenMetadataPath));

    Metadata mavenMetadata = MavenXml.readMetadata(mavenMetadataXml);
View Full Code Here

    return pickSnapshot(versionedPath, reference, mavenMetadata);
  }

  String resolveVersion(Path artifactPath, MavenReference reference) throws IOException {
    Path artifactMavenMetadataPath = artifactPath.resolve("maven-metadata.xml");

    log.info("Reading file: " + artifactMavenMetadataPath);
    String mavenMetadataXml = IoUtils.readAll(Files.newInputStream(artifactMavenMetadataPath));

    Metadata mavenMetadata = MavenXml.readMetadata(mavenMetadataXml);
View Full Code Here

    return version;
  }

  private Path toPath(String groupId, String artifactId) {
    String groupPathString = groupId.replace('.', '/');
    Path groupPath = basePath.resolve(groupPathString);

    Path artifactPath = groupPath.resolve(artifactId);
    return artifactPath;
  }
View Full Code Here

      name += "-" + found.getClassifier();
    }

    name += "." + found.getExtension();

    Path resolvedPath = versionedPath.resolve(name);
    return resolvedPath;
  }
View Full Code Here

public class MavenHashes {
  public static Md5Hash getMd5(Path artifactPath) throws IOException {
    String fileName = artifactPath.getFileName().toString();

    Path md5Path = artifactPath.resolveSibling(fileName + ".md5");

    InputStream is = null;

    try {
      is = Files.newInputStream(md5Path);
View Full Code Here

            out.close();
        }
    }

    private static void delete(File file) throws IOException {
        Path filePath = file.toPath();

        if (Files.exists(filePath, LinkOption.NOFOLLOW_LINKS)) {
            if (Files.isDirectory(filePath, LinkOption.NOFOLLOW_LINKS)) {
                File[] files = file.listFiles();
View Full Code Here

TOP

Related Classes of java.nio.file.Path

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.