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