コード例 #1
0
ファイル: ArchiveExtractTo.java プロジェクト: BaseXdb/basex
  @Override
  public Item item(final QueryContext qc, final InputInfo ii) throws QueryException {
    checkCreate(qc);

    final Path path = toPath(0, qc);
    final B64 archive = toB64(exprs[1], qc, false);
    final TokenSet hs = entries(2, qc);

    try (ArchiveIn in = ArchiveIn.get(archive.input(info), info)) {
      while (in.more()) {
        final ZipEntry ze = in.entry();
        final String name = ze.getName();
        if (hs == null || hs.delete(token(name)) != 0) {
          final Path file = path.resolve(name);
          if (ze.isDirectory()) {
            Files.createDirectories(file);
          } else {
            Files.createDirectories(file.getParent());
            Files.write(file, in.read());
          }
        }
      }
    } catch (final IOException ex) {
      throw ARCH_FAIL_X.get(info, ex);
    }
    return null;
  }
コード例 #2
0
 public void setClassPath(final Path classpath) {
   this.pathComponents.removeAllElements();
   if (classpath != null) {
     final Path actualClasspath = classpath.concatSystemClasspath("ignore");
     final String[] pathElements = actualClasspath.list();
     for (int i = 0; i < pathElements.length; ++i) {
       try {
         this.addPathElement(pathElements[i]);
       } catch (BuildException ex) {
       }
     }
   }
 }
コード例 #3
0
  public static long checksumRandomAccessFile(Path filename) throws IOException {
    try (RandomAccessFile file = new RandomAccessFile(filename.toFile(), "r")) {
      long length = file.length();
      CRC32 crc = new CRC32();

      for (long p = 0; p < length; p++) {
        file.seek(p);
        int c = file.readByte();
        crc.update(c);
      }
      return crc.getValue();
    }
  }
コード例 #4
0
ファイル: Backup.java プロジェクト: petermost/Snippets
  @Override
  public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
    if (_pathMatcher.matches(file.getFileName())) storeFile(file.toFile());

    return super.visitFile(file, attrs);
  }