src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileAccess.java
author egahlin
Tue, 13 Aug 2019 03:58:29 +0200
branchJEP-349-branch
changeset 57717 4ce66d271065
parent 57690 9316d02dd4a5
child 58112 e7754025004b
permissions -rw-r--r--
Security handling, but two tests fails with driver

package jdk.jfr.internal.consumer;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;

// Protected by modular boundaries.
public abstract class FileAccess {
    public final static FileAccess UNPRIVILIGED = new UnPriviliged();

    public abstract RandomAccessFile openRAF(File f, String mode) throws IOException;

    public abstract DirectoryStream<Path> newDirectoryStream(Path repository) throws IOException;

    public abstract String getAbsolutePath(File f) throws IOException;

    public abstract long length(File f) throws IOException;

    public abstract long fileSize(Path p) throws IOException;

    private static class UnPriviliged extends FileAccess {
        @Override
        public RandomAccessFile openRAF(File f, String mode) throws IOException {
            return new RandomAccessFile(f, mode);
        }

        @Override
        public DirectoryStream<Path> newDirectoryStream(Path dir) throws IOException {
            return Files.newDirectoryStream(dir);
        }

        public String getAbsolutePath(File f) throws IOException {
            return f.getAbsolutePath();
        }

        public long length(File f) throws IOException {
            return f.length();
        }

        @Override
        public long fileSize(Path p) throws IOException {
            return Files.size(p);
        }
    }
}