58863
|
1 |
/*
|
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
package jdk.jfr.internal.consumer;
|
|
25 |
|
|
26 |
import java.io.File;
|
|
27 |
import java.io.IOException;
|
|
28 |
import java.io.RandomAccessFile;
|
|
29 |
import java.nio.file.DirectoryStream;
|
|
30 |
import java.nio.file.Files;
|
|
31 |
import java.nio.file.Path;
|
|
32 |
|
|
33 |
// Protected by modular boundaries.
|
|
34 |
public abstract class FileAccess {
|
|
35 |
public final static FileAccess UNPRIVILIGED = new UnPriviliged();
|
|
36 |
|
|
37 |
public abstract RandomAccessFile openRAF(File f, String mode) throws IOException;
|
|
38 |
|
|
39 |
public abstract DirectoryStream<Path> newDirectoryStream(Path repository) throws IOException;
|
|
40 |
|
|
41 |
public abstract String getAbsolutePath(File f) throws IOException;
|
|
42 |
|
|
43 |
public abstract long length(File f) throws IOException;
|
|
44 |
|
|
45 |
public abstract long fileSize(Path p) throws IOException;
|
|
46 |
|
|
47 |
private static class UnPriviliged extends FileAccess {
|
|
48 |
@Override
|
|
49 |
public RandomAccessFile openRAF(File f, String mode) throws IOException {
|
|
50 |
return new RandomAccessFile(f, mode);
|
|
51 |
}
|
|
52 |
|
|
53 |
@Override
|
|
54 |
public DirectoryStream<Path> newDirectoryStream(Path dir) throws IOException {
|
|
55 |
return Files.newDirectoryStream(dir);
|
|
56 |
}
|
|
57 |
|
|
58 |
@Override
|
|
59 |
public String getAbsolutePath(File f) throws IOException {
|
|
60 |
return f.getAbsolutePath();
|
|
61 |
}
|
|
62 |
|
|
63 |
@Override
|
|
64 |
public long length(File f) throws IOException {
|
|
65 |
return f.length();
|
|
66 |
}
|
|
67 |
|
|
68 |
@Override
|
|
69 |
public long fileSize(Path p) throws IOException {
|
|
70 |
return Files.size(p);
|
|
71 |
}
|
|
72 |
}
|
|
73 |
}
|