public Client[] getPath(List<Path> paths) {
    List<Path> newPath = new LinkedList<Path>();
    for (Path path : paths) {
      newPath.add(path);
    }

    List<Client> clientsOnPath = new LinkedList<Client>();
    clientsOnPath.add(clients[0]);
    clientsOnPath.add(newPath.get(0).getStart());
    clientsOnPath.add(newPath.get(0).getEnd());
    newPath.remove(0);
    for (Path path : newPath) {
      Client start = path.getStart();
      Client end = path.getEnd();
      if (!clientsOnPath.contains(start)) {
        clientsOnPath.add(start);
      }
      if (!clientsOnPath.contains(end)) {
        clientsOnPath.add(end);
      }
    }
    clientsOnPath.add(clients[0]);
    Client[] result = new Client[clientsOnPath.size()];
    for (int i = 0; i < clientsOnPath.size(); i++) {
      result[i] = clientsOnPath.get(i);
    }
    return result;
  }
Пример #2
0
    public void initialize(InputSplit genericSplit, TaskAttemptContext context) throws IOException {
      FileSplit split = (FileSplit) genericSplit;
      Configuration job = context.getConfiguration();
      m_Sb.setLength(0);
      m_Start = split.getStart();
      m_End = m_Start + split.getLength();
      final Path file = split.getPath();
      compressionCodecs = new CompressionCodecFactory(job);
      final CompressionCodec codec = compressionCodecs.getCodec(file);

      // open the file and seek to the m_Start of the split
      FileSystem fs = file.getFileSystem(job);
      //  getFileStatus fileStatus = fs.getFileStatus(split.getPath());
      //noinspection deprecation
      @SuppressWarnings(value = "deprecated")
      long length = fs.getLength(file);
      FSDataInputStream fileIn = fs.open(split.getPath());
      if (m_Start > 0) fileIn.seek(m_Start);
      if (codec != null) {
        CompressionInputStream inputStream = codec.createInputStream(fileIn);
        m_Input = new BufferedReader(new InputStreamReader(inputStream));
        m_End = length;
      } else {
        m_Input = new BufferedReader(new InputStreamReader(fileIn));
      }
      m_Current = m_Start;
      m_Key = split.getPath().getName();
    }
Пример #3
0
  /** Check that a cancelled key will never be queued */
  static void testCancel(Path dir) throws IOException {
    System.out.println("-- Cancel --");

    try (WatchService watcher = FileSystems.getDefault().newWatchService()) {

      System.out.format("register %s for events\n", dir);
      WatchKey myKey = dir.register(watcher, new WatchEvent.Kind<?>[] {ENTRY_CREATE});
      checkKey(myKey, dir);

      System.out.println("cancel key");
      myKey.cancel();

      // create a file in the directory
      Path file = dir.resolve("mars");
      System.out.format("create: %s\n", file);
      Files.createFile(file);

      // poll for keys - there will be none
      System.out.println("poll...");
      try {
        WatchKey key = watcher.poll(3000, TimeUnit.MILLISECONDS);
        if (key != null) throw new RuntimeException("key should not be queued");
      } catch (InterruptedException x) {
        throw new RuntimeException(x);
      }

      // done
      Files.delete(file);

      System.out.println("OKAY");
    }
  }
  public int run(String[] args) throws Exception {
    Configuration conf = getConf();
    conf.setLong("mapreduce.task.timeout", 10000 * 60 * 60);

    Path train_file = new Path(args[0]);
    Path test_file = new Path(args[1]);
    conf.set("train_file", train_file.getParent().getName());

    Job job = new Job(conf, "MapTestID");
    job.setJarByClass(MapTestID.class);

    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(Text.class);

    job.setMapperClass(MapTestID.MapTestIDMap.class);
    job.setReducerClass(MapTestID.MapTestIDReduce.class);

    job.setNumReduceTasks(300);

    FileInputFormat.addInputPath(job, train_file);
    FileInputFormat.addInputPath(job, test_file);
    FileOutputFormat.setOutputPath(job, new Path(args[2]));

    return job.waitForCompletion(true) ? 0 : 1;
  }
Пример #5
0
  private void directory_to_directory(
      String source_base_name, String destination_base_name, String directory_name)
      throws IOException, InterruptedException {
    // E.g.
    // source_base_name:        /foo/bar
    // destination_base_name:   /x/y
    // directory_name:     abc
    //
    // - Create /x/y/abc
    // - Copy /foo/bar/abc/* to /x/y/abc/*

    // Get source directory.
    String source_directory_name = Path.concatenate(source_base_name, directory_name);
    File source_directory = File.create(source_directory_name);
    Assertion.check(source_directory.isDirectory());

    // Get destination directory, creating it if
    // necessary.
    String destination_directory_name = Path.concatenate(destination_base_name, directory_name);
    File destination_directory = File.create(destination_directory_name);
    destination_directory.mkdirs();

    // Get files in source directory
    String[] source_file_names = source_directory.list();
    Vector source_files = new Vector();
    for (int i = 0; i < source_file_names.length; i++)
      source_files.addElement(File.create(source_directory_name, source_file_names[i]));

    // Copy
    to_directory(source_files, destination_directory);
  }
Пример #6
0
 private void setPathIDForRoads(List<Path> paths) {
   for (Path path : paths) {
     for (Road road : path) {
       roadHelper.setPathId(road.getID(), path.getId());
     }
   }
 }
Пример #7
0
  @Override
  public final Expr optimize(final QueryContext qc, final VarScope scp) throws QueryException {
    final Value v = initial(qc);
    if (v != null && v.isEmpty() || emptyPath(v)) return optPre(qc);

    // merge descendant steps
    Expr e = mergeSteps(qc);
    if (e == this && v != null && v.type == NodeType.DOC) {
      // check index access
      e = index(qc, v);
      // rewrite descendant to child steps
      if (e == this) e = children(qc, v);
    }
    // recompile path if it has changed
    if (e != this) return e.compile(qc, scp);

    // set atomic type for single attribute steps to speed up predicate tests
    if (root == null && steps.length == 1 && steps[0] instanceof Step) {
      final Step curr = (Step) steps[0];
      if (curr.axis == ATTR && curr.test.kind == Kind.URI_NAME) curr.seqType(SeqType.NOD_ZO);
    }

    // choose best path implementation and set type information
    final Path path = get(info, root, steps);
    path.size = path.size(qc);
    path.seqType = SeqType.get(steps[steps.length - 1].seqType().type, size);
    return path;
  }
Пример #8
0
  /**
   * Initializes default class loader. It inherits from classloader, which was used to load this
   * task, therefore build-in classes and resources are loaded automatically.
   *
   * <p>Notice: task's classpath has priority over default classpath, therefore we are able to
   * easily override resources (templates)
   */
  protected void initClassloader() {
    // NOTICE: we should use the same classloader, which was used to load this task
    // otherwise we won't be able to cast instances
    // (that were loaded via different class loaders)

    // we are introducting workaround,
    // that tries to add classpath for current task to original class loader
    // and stores original classpath
    // after the task is executed, classpath is restored

    ClassLoader classLoader = getClass().getClassLoader();
    if (classLoader instanceof AntClassLoader) {
      // add defined classpath
      AntClassLoader antClassLoader = (AntClassLoader) classLoader;
      antClassLoader.setParentFirst(false);
      antClassLoader.setProject(getProject());
      savedClasspath = antClassLoader.getClasspath();

      Path cp = getClasspath();
      // add defined classpath to original path
      cp.add(new Path(getProject(), savedClasspath));
      antClassLoader.setClassPath(cp);
    } else {
      // create new class loader
      classLoader =
          new AntClassLoader(getClass().getClassLoader(), getProject(), getClasspath(), false);
    }

    // set this class loader as new class loader for whole thread
    // ContextClassLoader is used in StringTemplate's PathGroupLoader and other classes
    Thread.currentThread().setContextClassLoader(classLoader);
  }
Пример #9
0
  public static void main(String[] args) throws Exception {
    Path dir1 = TestUtil.createTemporaryDirectory();
    try {

      // Same directory
      testCopyFileToFile(dir1, dir1, TestUtil.supportsLinks(dir1));
      testMove(dir1, dir1, TestUtil.supportsLinks(dir1));

      // Different directories. Use test.dir if possible as it might be
      // a different volume/file system and so improve test coverage.
      String testDir = System.getProperty("test.dir", ".");
      Path dir2 = TestUtil.createTemporaryDirectory(testDir);
      try {
        boolean testSymbolicLinks = TestUtil.supportsLinks(dir1) && TestUtil.supportsLinks(dir2);
        testCopyFileToFile(dir1, dir2, testSymbolicLinks);
        testMove(dir1, dir2, testSymbolicLinks);
      } finally {
        TestUtil.removeAll(dir2);
      }

      // Target is location associated with custom provider
      Path dir3 = PassThroughFileSystem.create().getPath(dir1.toString());
      testCopyFileToFile(dir1, dir3, false);
      testMove(dir1, dir3, false);

      // Test copy(InputStream,Path) and copy(Path,OutputStream)
      testCopyInputStreamToFile();
      testCopyFileToOuputStream();

    } finally {
      TestUtil.removeAll(dir1);
    }
  }
Пример #10
0
  /**
   * Recursively rebuild the tree nodes.
   *
   * @param root The full abstract path to the root saved layout directory.
   * @param local The current directory relative to root (null if none).
   * @param tnode The current parent tree node.
   */
  private void rebuildTreeModel(Path root, Path local, DefaultMutableTreeNode tnode) {
    TreeSet<Path> subdirs = new TreeSet<Path>();
    TreeSet<String> layouts = new TreeSet<String>();
    {
      Path current = new Path(root, local);
      File files[] = current.toFile().listFiles();
      if (files != null) {
        int wk;
        for (wk = 0; wk < files.length; wk++) {
          String name = files[wk].getName();
          if (files[wk].isDirectory()) subdirs.add(new Path(local, name));
          else if (files[wk].isFile()) layouts.add(name);
        }
      }
    }

    for (Path subdir : subdirs) {
      TreeData data = new TreeData(subdir);
      DefaultMutableTreeNode child = new DefaultMutableTreeNode(data, true);
      tnode.add(child);

      rebuildTreeModel(root, subdir, child);
    }

    for (String lname : layouts) {
      TreeData data = new TreeData(new Path(local, lname), lname);
      DefaultMutableTreeNode child = new DefaultMutableTreeNode(data, false);
      tnode.add(child);
    }
  }
Пример #11
0
  private static List<LinkedHashMap<String, Object>> getFeaturesForClass(
      GraphDatabaseService db, Node classNode) {
    List<LinkedHashMap<String, Object>> patternIds = new ArrayList<>();

    for (Path p :
        db.traversalDescription()
            .depthFirst()
            .relationships(withName("HAS_CLASS"), Direction.INCOMING)
            .evaluator(Evaluators.fromDepth(1))
            .evaluator(Evaluators.toDepth(1))
            .traverse(classNode)) {

      LinkedHashMap<String, Object> featureMap = new LinkedHashMap<>();

      if (p.relationships().iterator().hasNext()) {
        featureMap.put("frequency", p.relationships().iterator().next().getProperty("matches"));
      } else {
        featureMap.put("frequency", 0);
      }

      featureMap.put("feature", ((Long) p.endNode().getId()).intValue());

      patternIds.add(featureMap);
    }
    return patternIds;
  }
Пример #12
0
  private static IntWritable deduceInputFile(JobConf job) {
    Path[] inputPaths = FileInputFormat.getInputPaths(job);
    Path inputFile = new Path(job.get("map.input.file"));

    // value == one for sort-input; value == two for sort-output
    return (inputFile.getParent().equals(inputPaths[0])) ? sortInput : sortOutput;
  }
Пример #13
0
  public static FileDesc loadFile(Path root, Path file, int blocSize)
      throws NoSuchAlgorithmException, FileNotFoundException, IOException {
    MessageDigest md = MessageDigest.getInstance("SHA-512");
    MessageDigest fileMd = MessageDigest.getInstance("SHA-512");

    FileDesc desc = new FileDesc(file.toString(), null, null);
    List<Bloc> list = new ArrayList<Bloc>();
    try (FileInputStream fis = new FileInputStream(root.resolve(file).toString())) {
      byte[] buf = new byte[blocSize];
      byte[] h;
      int s;
      while ((s = fis.read(buf)) != -1) {
        int c;
        while (s < buf.length && (c = fis.read()) != -1) buf[s++] = (byte) c;
        fileMd.update(buf, 0, s);

        // padding
        byte p = 0;
        while (s < buf.length) buf[s++] = ++p;
        h = md.digest(buf);
        Bloc bloc = new Bloc(RollingChecksum.compute(buf), new Hash(h));
        list.add(bloc);
      }
      h = fileMd.digest();
      desc.fileHash = new Hash(h);
      desc.blocs = list.toArray(new Bloc[0]);
    }
    return desc;
  }
Пример #14
0
  /** check a candidate plugin for jar hell before installing it */
  private void jarHellCheck(Path candidate, boolean isolated) throws IOException {
    // create list of current jars in classpath
    final List<URL> jars = new ArrayList<>(Arrays.asList(JarHell.parseClassPath()));

    // read existing bundles. this does some checks on the installation too.
    List<Bundle> bundles = PluginsService.getPluginBundles(environment.pluginsFile());

    // if we aren't isolated, we need to jarhellcheck against any other non-isolated plugins
    // thats always the first bundle
    if (isolated == false) {
      jars.addAll(bundles.get(0).urls);
    }

    // add plugin jars to the list
    Path pluginJars[] = FileSystemUtils.files(candidate, "*.jar");
    for (Path jar : pluginJars) {
      jars.add(jar.toUri().toURL());
    }

    // check combined (current classpath + new jars to-be-added)
    try {
      JarHell.checkJarHell(jars.toArray(new URL[jars.size()]));
    } catch (Exception ex) {
      throw new RuntimeException(ex);
    }
  }
 private static boolean exists(Path p) {
   Path base = p.getParent();
   String fileName = p.getFileName().toString();
   return Arrays.asList(extensions)
       .stream()
       .anyMatch(it -> Files.exists(base.resolve(fileName + it)));
 }
Пример #16
0
 private String copyFromLocal(FileSystem fs, Path basePath, String[] files) throws IOException {
   StringBuilder csv = new StringBuilder(files.length * (basePath.toString().length() + 16));
   for (String localFile : files) {
     Path src = new Path(localFile);
     String filename = src.getName();
     Path dst = new Path(basePath, filename);
     URI localFileURI = null;
     try {
       localFileURI = new URI(localFile);
     } catch (URISyntaxException e) {
       throw new IOException(e);
     }
     if (localFileURI.getScheme() == null || localFileURI.getScheme().startsWith("file")) {
       LOG.info("Copy {} from local filesystem to {}", localFile, dst);
       fs.copyFromLocalFile(false, true, src, dst);
     } else {
       LOG.info("Copy {} from DFS to {}", localFile, dst);
       FileUtil.copy(fs, src, fs, dst, false, true, conf);
     }
     if (csv.length() > 0) {
       csv.append(LIB_JARS_SEP);
     }
     csv.append(dst.toString());
   }
   return csv.toString();
 }
Пример #17
0
  private void uploadFile(String relPath, Path fullPath) throws DropboxException, IOException {
    if (!fullPath.toFile().exists()) return;

    /*if(api.metadata(relPath, 1, null, false, null).rev == MetaHandler.getRev(relPath)){
    	logger.debug("File "+relPath+" not changed");
    	return;
    }*/

    VOSync.debug("Uploading " + relPath);

    String rev = MetaHandler.getRev(relPath);

    InputStream inp = new FileInputStream(fullPath.toFile());
    Entry fileEntry = api.putFile(relPath, inp, fullPath.toFile().length(), rev, null);
    inp.close();

    Path destFilePath =
        FileSystems.getDefault()
            .getPath(fullPath.toFile().getParentFile().getPath(), fileEntry.fileName());

    MetaHandler.setFile(relPath, destFilePath.toFile(), fileEntry.rev);

    logger.debug(relPath + " put to db");

    // if the file was renamed, move the file on disk and download the current from server
    if (!fileEntry.fileName().equals(fullPath.toFile().getName())) {
      logger.error(fileEntry.fileName() + " != " + fullPath.toFile().getName());
      fullPath.toFile().renameTo(destFilePath.toFile());
    }
  }
  public void registerPath(String path) {
    boolean contentAlreadyRegistered = false;
    File hudsonFile = JenkinsFilesHelper.buildFileFromPathRelativeToHudsonRoot(path);
    Path pathToRegister = new Path(hudsonFile);

    if (pathToRegister.isDirectory()) {
      pathContents.put(pathToRegister, new byte[0]);
    } else {
      // Verifying if path content is already in pathContent and, if this is the case,
      // look at checksums
      if (pathContents.containsKey(pathToRegister)) {
        try {
          contentAlreadyRegistered =
              Checksums.fileAndByteArrayContentAreEqual(
                  pathToRegister.getHudsonFile(), pathContents.get(pathToRegister));
        } catch (IOException e) {
          throw new LoggableException(
              "Changeset path <" + path + "> registration failed",
              Checksums.class,
              "fileAndByteArrayContentAreEqual",
              e);
        }
      }

      if (!contentAlreadyRegistered) {
        try {
          pathContents.put(pathToRegister, Files.toByteArray(pathToRegister.getHudsonFile()));
        } catch (IOException e) {
          throw new LoggableException(
              "Changeset path <" + path + "> registration failed", Files.class, "toByteArray", e);
        }
      }
    }
  }
Пример #19
0
  private Path getNearestPath(Road road, List<Path> paths) {
    int range = 10000;
    int minDistance = Integer.MAX_VALUE;
    EntityID nearestPath = null;

    while (nearestPath == null) {
      Collection<StandardEntity> entities = world.getObjectsInRange(road, range);

      for (StandardEntity entity : entities) {
        if (entity instanceof Road) {
          EntityID pathId = roadHelper.getPathId(entity.getID());

          if (pathId != null) {
            int distance = Util.distance((Area) entity, road);
            if (distance < minDistance) {
              nearestPath = pathId;
              minDistance = distance;
            }
          }
        }
      }
      range += 10000;
    }

    for (Path path : paths) {
      if (path.getId().equals(nearestPath)) {
        return path;
      }
    }
    return null;
  }
Пример #20
0
  private static void finalize(
      Configuration conf, JobConf jobconf, final Path destPath, String presevedAttributes)
      throws IOException {
    if (presevedAttributes == null) {
      return;
    }
    EnumSet<FileAttribute> preseved = FileAttribute.parse(presevedAttributes);
    if (!preseved.contains(FileAttribute.USER)
        && !preseved.contains(FileAttribute.GROUP)
        && !preseved.contains(FileAttribute.PERMISSION)) {
      return;
    }

    FileSystem dstfs = destPath.getFileSystem(conf);
    Path dstdirlist = new Path(jobconf.get(DST_DIR_LIST_LABEL));
    SequenceFile.Reader in = null;
    try {
      in = new SequenceFile.Reader(dstdirlist.getFileSystem(jobconf), dstdirlist, jobconf);
      Text dsttext = new Text();
      FilePair pair = new FilePair();
      for (; in.next(dsttext, pair); ) {
        Path absdst = new Path(destPath, pair.output);
        updatePermissions(pair.input, dstfs.getFileStatus(absdst), preseved, dstfs);
      }
    } finally {
      checkAndClose(in);
    }
  }
Пример #21
0
    public void onDraw(Canvas canvas) {
      // 검정색 배경으로 지운다. 빈 화면이면 지우기만 하고 리턴
      canvas.drawColor(Color.BLACK);
      if (status == BLANK) {
        return;
      }

      // 도형 목록을 순회하면서 도형 정보대로 출력한다.
      int idx;
      for (idx = 0; idx < arShape.size(); idx++) {
        Paint Pnt = new Paint();
        Pnt.setAntiAlias(true);
        Pnt.setColor(arShape.get(idx).color);

        Rect rt = arShape.get(idx).rt;
        switch (arShape.get(idx).what) {
          case Shape.RECT:
            canvas.drawRect(rt, Pnt);
            break;
          case Shape.CIRCLE:
            canvas.drawCircle(
                rt.left + rt.width() / 2, rt.top + rt.height() / 2, rt.width() / 2, Pnt);
            break;
          case Shape.TRIANGLE:
            Path path = new Path();
            path.moveTo(rt.left + rt.width() / 2, rt.top);
            path.lineTo(rt.left, rt.bottom);
            path.lineTo(rt.right, rt.bottom);
            canvas.drawPath(path, Pnt);
            break;
        }
      }
    }
Пример #22
0
  /** {@inheritDoc} */
  protected void doRenderGraphic(DrawContext dc) {
    for (Path path : this.paths) {
      path.render(dc);
    }

    this.arrowHead1.render(dc);
    this.arrowHead2.render(dc);
  }
Пример #23
0
 private void addToPath(Road road, EntityID pathId, List<Path> paths) {
   for (Path path : paths) {
     if (path.getId().equals(pathId)) {
       adding(road, path);
       break;
     }
   }
 }
Пример #24
0
 protected Path createPath() {
   Path path = new Path();
   path.setFollowTerrain(true);
   path.setPathType(AVKey.GREAT_CIRCLE);
   path.setAltitudeMode(WorldWind.CLAMP_TO_GROUND);
   path.setDelegateOwner(this.getActiveDelegateOwner());
   return path;
 }
Пример #25
0
  // copy source to target with verification
  static void copyAndVerify(Path source, Path target, CopyOption... options) throws IOException {
    Path result = copy(source, target, options);
    assertTrue(result == target);

    // get attributes of source and target file to verify copy
    boolean followLinks = true;
    LinkOption[] linkOptions = new LinkOption[0];
    boolean copyAttributes = false;
    for (CopyOption opt : options) {
      if (opt == NOFOLLOW_LINKS) {
        followLinks = false;
        linkOptions = new LinkOption[] {NOFOLLOW_LINKS};
      }
      if (opt == COPY_ATTRIBUTES) copyAttributes = true;
    }
    BasicFileAttributes basicAttributes =
        readAttributes(source, BasicFileAttributes.class, linkOptions);

    // check hash if regular file
    if (basicAttributes.isRegularFile()) assertTrue(computeHash(source) == computeHash(target));

    // check link target if symbolic link
    if (basicAttributes.isSymbolicLink())
      assert (readSymbolicLink(source).equals(readSymbolicLink(target)));

    // check that attributes are copied
    if (copyAttributes && followLinks) {
      checkBasicAttributes(
          basicAttributes, readAttributes(source, BasicFileAttributes.class, linkOptions));

      // verify other attributes when same provider
      if (source.getFileSystem().provider() == target.getFileSystem().provider()) {

        // check POSIX attributes are copied
        String os = System.getProperty("os.name");
        if ((os.equals("SunOS") || os.equals("Linux")) && testPosixAttributes) {
          checkPosixAttributes(
              readAttributes(source, PosixFileAttributes.class, linkOptions),
              readAttributes(target, PosixFileAttributes.class, linkOptions));
        }

        // check DOS attributes are copied
        if (os.startsWith("Windows")) {
          checkDosAttributes(
              readAttributes(source, DosFileAttributes.class, linkOptions),
              readAttributes(target, DosFileAttributes.class, linkOptions));
        }

        // check named attributes are copied
        if (followLinks
            && getFileStore(source).supportsFileAttributeView("xattr")
            && getFileStore(target).supportsFileAttributeView("xattr")) {
          checkUserDefinedFileAttributes(
              readUserDefinedFileAttributes(source), readUserDefinedFileAttributes(target));
        }
      }
    }
  }
Пример #26
0
  /** Returns the {@code NodePath.path} for this shard. */
  public static Path shardStatePathToDataPath(Path shardPath) {
    int count = shardPath.getNameCount();

    // Sanity check:
    assert Integer.parseInt(shardPath.getName(count - 1).toString()) >= 0;
    assert "indices".equals(shardPath.getName(count - 3).toString());

    return shardPath.getParent().getParent().getParent();
  }
Пример #27
0
 private void adding(Road road, Path path) {
   roadHelper.setPathId(road.getID(), path.getId());
   if (!path.contains(road)) {
     path.add(road);
     if (entrances.contains(road)) {
       path.addEntrance(getEntrance(road));
     }
   }
 }
Пример #28
0
    private ArrayList<Path> holeLaufwerkeWindows() {
      ArrayList<Path> laufwerksRoot = new ArrayList<>();

      Iterable<Path> rootDirectories = FileSystems.getDefault().getRootDirectories();

      for (Path path : rootDirectories) {
        laufwerksRoot.add(path.getRoot());
      }
      return laufwerksRoot;
    }
 public static String absolutePath(Path p) {
   if (p == null) return "";
   StringBuilder sb = new StringBuilder();
   Path parentPath = p.getParent();
   if (parentPath == null) return "/";
   sb.append(absolutePath(parentPath));
   if (sb.length() > 1) sb.append("/");
   sb.append(p.getName());
   return sb.toString();
 }
 @Override
 public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
     throws IOException {
   Path targetPath = toPath.resolve(fromPath.relativize(dir));
   if (!Files.exists(targetPath)) {
     targetPath.toFile().mkdirs();
     // Files.createDirectory(targetPath);
   }
   return FileVisitResult.CONTINUE;
 }