示例#1
0
  public static void main(String args[]) {
    try {
      aServer asr = new aServer();

      // file channel.
      FileInputStream is = new FileInputStream("");
      is.read();
      FileChannel cha = is.getChannel();
      ByteBuffer bf = ByteBuffer.allocate(1024);
      bf.flip();

      cha.read(bf);

      // Path Paths
      Path pth = Paths.get("", "");

      // Files some static operation.
      Files.newByteChannel(pth);
      Files.copy(pth, pth);
      // file attribute, other different class for dos and posix system.
      BasicFileAttributes bas = Files.readAttributes(pth, BasicFileAttributes.class);
      bas.size();

    } catch (Exception e) {
      System.err.println(e);
    }

    System.out.println("hello ");
  }
示例#2
0
 private static void extractAndLoadNativeLib(String nativeLibName, Path target) {
   //		System.err.println("loading "+nativeLibName);
   final Path path = Paths.get(target.toString(), nativeLibName);
   if (!path.toFile().exists()) {
     try (InputStream is =
         CudaEngine.class
             .getClassLoader()
             .getResourceAsStream("/lib/" + nativeLibName)) { // TODO TK property for lib dir
       Files.copy(is, path);
     } catch (IOException e) {
       e.printStackTrace();
     } catch (NullPointerException e) { // TODO find a way to do it instead of eclipse
       final Path eclipsePath = FileSystems.getDefault().getPath("lib", nativeLibName);
       try {
         Files.copy(eclipsePath, path);
       } catch (IOException e1) {
         // TODO Auto-generated catch block
         e1.printStackTrace();
       }
     }
   }
   System.load(path.toString());
   //		System.load(nativeLibName);
 }
示例#3
0
 // void compileKernelsPtx()
 static void compileKernelsPtx() throws IOException {
   if (!new File(ioTmpDir, PHEROMONES_CU + ".ptx").exists()) { // TODO externalize
     try (InputStream is =
         CudaEngine.class.getResourceAsStream(
             "/turtlekit/cuda/kernels/" + PHEROMONES_CU + ".cu")) {
       final Path path = Paths.get(ioTmpDir, PHEROMONES_CU + ".cu");
       try {
         Files.copy(is, path);
       } catch (FileAlreadyExistsException e) {
       }
       System.err.println("--------------- Compiling ptx ----------------------");
       KernelLauncher.create(
           path.toString(),
           Kernel.DIFFUSION_TO_TMP.name(),
           false,
           "--use_fast_math",
           "--prec-div=false"); // ,"--gpu-architecture=sm_20");
     } catch (IOException e) {
       throw e;
     }
   }
 }
  public void downloadFlat(String artifact, String copyToDir) {
    OutputBouble bouble = OutputBouble.push();
    try {
      Artifact theArtifact = new DefaultArtifact(artifact);

      HashSet<Artifact> downloadThese = new HashSet<Artifact>();
      downloadThese.add(theArtifact);
      Stack<Artifact> downloadDependenciesOfThese = new Stack<Artifact>();
      downloadDependenciesOfThese.add(theArtifact);

      while (!downloadDependenciesOfThese.isEmpty()) {
        Artifact getDependenciesOfThis = downloadDependenciesOfThese.pop();
        List<Artifact> dependencies =
            dependencyManager.getDirectDependencies(getDependenciesOfThis);
        for (Artifact a : dependencies) {
          if (!downloadThese.contains(a)) {
            downloadThese.add(a);
            downloadDependenciesOfThese.add(a);
          }
        }
      }

      File destination = new File(copyToDir);
      destination.mkdirs();

      for (Artifact a : downloadThese) {
        File theFile = getAsFile(a);
        Files.copy(theFile.toPath(), new File(destination, theFile.getName()).toPath());
      }
    } catch (Exception e) {
      OutputBouble.reportError(e);
    } finally {
      bouble.pop();
      if (bouble.isError) bouble.writeToParent();
    }
  }
 @Override
 public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
   Files.copy(file, toPath.resolve(fromPath.relativize(file)), copyOption);
   return FileVisitResult.CONTINUE;
 }
示例#6
0
    public void cnpStart(Path quellOrdner, Path zielOrdner) {
      try {
        DirectoryStream<Path> qstream = Files.newDirectoryStream(quellOrdner);
        for (Path qfile : qstream) {
          Path target = Paths.get(zielOrdner.toString() + "/" + qfile.getFileName());
          if (abbruch) break;
          if (Files.isDirectory(qfile) && !Files.exists(target)) {
            Files.createDirectory(target);
            textArea.append("Verzeichnis: " + qfile + " wurde erstellt" + System.lineSeparator());
            cnpStart(
                Paths.get(quellOrdner.toString() + "/" + qfile.getFileName()),
                Paths.get(zielOrdner.toString() + "/" + qfile.getFileName()));
          } else if (Files.isDirectory(qfile) && Files.exists(target)) {
            textArea.append("Wechsle in Verzeichnis: " + qfile + System.lineSeparator());
            cnpStart(
                Paths.get(quellOrdner.toString() + "/" + qfile.getFileName()),
                Paths.get(zielOrdner.toString() + "/" + qfile.getFileName()));
          }
          // Wenn die Datei noch nicht existiert
          else if (!Files.exists(target)) {
            textArea.append(
                "Datei " + target.toString() + " wurde erstellt" + System.lineSeparator());
            Files.copy(qfile, target, StandardCopyOption.REPLACE_EXISTING);

          }
          // Wenn Datei im Zielverzeichnis schon existiert
          else if (Files.exists(target)) {
            if (cAUeSchr) {
              textArea.append(
                  "Datei "
                      + target.toString()
                      + " wird absolut überschrieben"
                      + System.lineSeparator());
              Files.copy(qfile, target, StandardCopyOption.REPLACE_EXISTING);
            } else if (cUeSchr) {
              if (checkAlter(
                  Paths.get(quellOrdner.toString() + "/" + qfile.getFileName()),
                  Paths.get(zielOrdner.toString() + "/" + qfile.getFileName()))) {
                textArea.append(
                    target.toString()
                        + " wird mit neuer Datei überschrieben"
                        + System.lineSeparator());
                Files.copy(qfile, target, StandardCopyOption.REPLACE_EXISTING);
              } else {
                textArea.append(
                    target.toString() + " alte Datei bleibt bestehen" + System.lineSeparator());
              }
            } else
              textArea.append(
                  target.toString() + " alte Datei bleibt bestehen" + System.lineSeparator());
          }
          pbCounter++;
          progressBar.setValue(pbCounter);
        }

        qstream.close();
      } catch (IOException e) {

        e.printStackTrace();
      }
    }