src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileAccess.java
author egahlin
Fri, 09 Aug 2019 01:18:18 +0200
branchJEP-349-branch
changeset 57690 9316d02dd4a5
child 57717 4ce66d271065
permissions -rw-r--r--
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository

package jdk.jfr.internal.consumer;

import java.io.File;
import java.io.FileNotFoundException;
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 PRIVILIGED = new UnPriviliged();
    // TODO: Should be changed Priviliged class
    public final static FileAccess UNPRIVILIGED = new UnPriviliged();

    abstract RandomAccessFile openRAF(File f, String mode) throws FileNotFoundException;
    abstract DirectoryStream<Path> newDirectoryStream(Path repository) throws IOException;

    static class Priviliged extends FileAccess {
        @Override
        RandomAccessFile openRAF(File f, String mode) {
            // TDOO: Implement
            return null;
        }

        @Override
        protected DirectoryStream<Path> newDirectoryStream(Path repository) {
            // TDOO: Implement
            return null;
        }
    }

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

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

    }
}