コード例 #1
0
ファイル: Files.java プロジェクト: prasaadk/renjin
 @Internal("file.access")
 public static IntVector fileAccess(@Current Context context, StringVector names, int mode)
     throws FileSystemException {
   IntArrayVector.Builder result = new IntArrayVector.Builder();
   for (String name : names) {
     FileObject file = context.resolveFile(pathExpand(name));
     result.add(checkAccess(file, mode));
   }
   result.setAttribute(Symbols.NAMES, new StringArrayVector(names.toArray()));
   return result.build();
 }
コード例 #2
0
ファイル: Files.java プロジェクト: prasaadk/renjin
  /**
   * Utility function to extract information about files on the user's file systems.
   *
   * @param context current call Context
   * @param paths the list of files for which to return information
   * @return list column-oriented table of file information
   * @throws FileSystemException
   */
  @Internal("file.info")
  public static ListVector fileInfo(@Current Context context, StringVector paths)
      throws FileSystemException {

    DoubleArrayVector.Builder size = new DoubleArrayVector.Builder();
    LogicalArrayVector.Builder isdir = new LogicalArrayVector.Builder();
    IntArrayVector.Builder mode =
        (IntArrayVector.Builder)
            new IntArrayVector.Builder()
                .setAttribute(Symbols.CLASS, StringVector.valueOf("octmode"));
    DoubleArrayVector.Builder mtime = new DoubleArrayVector.Builder();
    StringVector.Builder exe = new StringVector.Builder();

    for (String path : paths) {
      if (StringVector.isNA(path)) {
        throw new EvalException("invalid filename argument");
      }
      FileObject file = context.resolveFile(path);
      if (file.exists()) {
        if (file.getType() == FileType.FILE) {
          size.add((int) file.getContent().getSize());
        } else {
          size.add(0);
        }
        isdir.add(file.getType() == FileType.FOLDER);
        mode.add(mode(file));
        try {
          mtime.add(file.getContent().getLastModifiedTime());
        } catch (Exception e) {
          mtime.add(0);
        }
        exe.add(file.getName().getBaseName().endsWith(".exe") ? "yes" : "no");
      } else {
        size.addNA();
        isdir.addNA();
        mode.addNA();
        mtime.addNA();
        exe.addNA();
      }
    }

    return ListVector.newNamedBuilder()
        .add("size", size)
        .add("isdir", isdir)
        .add("mode", mode)
        .add("mtime", mtime)
        .add("ctime", mtime)
        .add("atime", mtime)
        .add("exe", exe)
        .build();
  }
コード例 #3
0
ファイル: Files.java プロジェクト: prasaadk/renjin
 /**
  * Unlink deletes the file(s) or directories specified by {@code paths}.
  *
  * @param context the current call Context
  * @param paths list of paths to delete
  * @param recursive Should directories be deleted recursively?
  * @return 0 for success, 1 for failure. Not deleting a non-existent file is not a failure, nor is
  *     being unable to delete a directory if recursive = FALSE. However, missing values in x are
  *     regarded as failures.
  * @throws FileSystemException
  */
 @Internal
 public static IntVector unlink(
     @Current Context context, StringVector paths, boolean recursive, boolean force)
     throws FileSystemException {
   IntArrayVector.Builder result = new IntArrayVector.Builder();
   for (String path : paths) {
     if (StringVector.isNA(path)) {
       result.add(0);
     } else {
       FileObject file = context.resolveFile(path);
       delete(file, recursive);
       result.add(1);
     }
   }
   return result.build();
 }