src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/FileAccess.java
branchJEP-349-branch
changeset 57717 4ce66d271065
parent 57690 9316d02dd4a5
child 58112 e7754025004b
equal deleted inserted replaced
57702:c75c241c492a 57717:4ce66d271065
     1 package jdk.jfr.internal.consumer;
     1 package jdk.jfr.internal.consumer;
     2 
     2 
     3 import java.io.File;
     3 import java.io.File;
     4 import java.io.FileNotFoundException;
       
     5 import java.io.IOException;
     4 import java.io.IOException;
     6 import java.io.RandomAccessFile;
     5 import java.io.RandomAccessFile;
     7 import java.nio.file.DirectoryStream;
     6 import java.nio.file.DirectoryStream;
     8 import java.nio.file.Files;
     7 import java.nio.file.Files;
     9 import java.nio.file.Path;
     8 import java.nio.file.Path;
    10 
     9 
    11 // Protected by modular boundaries.
    10 // Protected by modular boundaries.
    12 public abstract class FileAccess {
    11 public abstract class FileAccess {
    13     public final static FileAccess PRIVILIGED = new UnPriviliged();
       
    14     // TODO: Should be changed Priviliged class
       
    15     public final static FileAccess UNPRIVILIGED = new UnPriviliged();
    12     public final static FileAccess UNPRIVILIGED = new UnPriviliged();
    16 
    13 
    17     abstract RandomAccessFile openRAF(File f, String mode) throws FileNotFoundException;
    14     public abstract RandomAccessFile openRAF(File f, String mode) throws IOException;
    18     abstract DirectoryStream<Path> newDirectoryStream(Path repository) throws IOException;
       
    19 
    15 
    20     static class Priviliged extends FileAccess {
    16     public abstract DirectoryStream<Path> newDirectoryStream(Path repository) throws IOException;
       
    17 
       
    18     public abstract String getAbsolutePath(File f) throws IOException;
       
    19 
       
    20     public abstract long length(File f) throws IOException;
       
    21 
       
    22     public abstract long fileSize(Path p) throws IOException;
       
    23 
       
    24     private static class UnPriviliged extends FileAccess {
    21         @Override
    25         @Override
    22         RandomAccessFile openRAF(File f, String mode) {
    26         public RandomAccessFile openRAF(File f, String mode) throws IOException {
    23             // TDOO: Implement
       
    24             return null;
       
    25         }
       
    26 
       
    27         @Override
       
    28         protected DirectoryStream<Path> newDirectoryStream(Path repository) {
       
    29             // TDOO: Implement
       
    30             return null;
       
    31         }
       
    32     }
       
    33 
       
    34     static class UnPriviliged extends FileAccess {
       
    35         @Override
       
    36         RandomAccessFile openRAF(File f, String mode) throws FileNotFoundException {
       
    37             return new RandomAccessFile(f, mode);
    27             return new RandomAccessFile(f, mode);
    38         }
    28         }
    39 
    29 
    40         @Override
    30         @Override
    41         DirectoryStream<Path> newDirectoryStream(Path dir) throws IOException {
    31         public DirectoryStream<Path> newDirectoryStream(Path dir) throws IOException {
    42             return Files.newDirectoryStream(dir);
    32             return Files.newDirectoryStream(dir);
    43         }
    33         }
    44 
    34 
       
    35         public String getAbsolutePath(File f) throws IOException {
       
    36             return f.getAbsolutePath();
       
    37         }
       
    38 
       
    39         public long length(File f) throws IOException {
       
    40             return f.length();
       
    41         }
       
    42 
       
    43         @Override
       
    44         public long fileSize(Path p) throws IOException {
       
    45             return Files.size(p);
       
    46         }
    45     }
    47     }
    46 }
    48 }