/** Permission checks to access file */
 private void checkAccess(UnixPath file, boolean checkRead, boolean checkWrite) {
   SecurityManager sm = System.getSecurityManager();
   if (sm != null) {
     if (checkRead) file.checkRead();
     if (checkWrite) file.checkWrite();
     sm.checkPermission(new RuntimePermission("accessUserInformation"));
   }
 }
コード例 #2
0
 @Override
 public BasicFileAttributes readAttributes() throws IOException {
   file.checkRead();
   try {
     UnixFileAttributes attrs = UnixFileAttributes.get(file, followLinks);
     return attrs.asBasicFileAttributes();
   } catch (UnixException x) {
     x.rethrowAsIOException(file);
     return null; // keep compiler happy
   }
 }
  @Override
  public String implProbeContentType(Path obj) throws IOException {
    if (!gioAvailable) return null;
    if (!(obj instanceof UnixPath)) return null;

    UnixPath path = (UnixPath) obj;
    NativeBuffer buffer = NativeBuffers.asNativeBuffer(path.getByteArrayForSysCalls());
    try {
      // GIO may access file so need permission check
      path.checkRead();
      byte[] type = probeGio(buffer.address());
      return (type == null) ? null : Util.toString(type);
    } finally {
      buffer.release();
    }
  }