Search in sources :

Example 36 with PosixFilePermission

use of java.nio.file.attribute.PosixFilePermission in project gradle by gradle.

the class ChmodBenchmark method createFileJava7SetPermissionsWhenNeeded.

@Benchmark
public void createFileJava7SetPermissionsWhenNeeded(Blackhole blackhole) throws IOException {
    int incrementAndGet = counter.incrementAndGet();
    Path file = Files.createFile(tempDirPath.resolve("file-" + incrementAndGet));
    Set<PosixFilePermission> originalPermissions = Files.getPosixFilePermissions(file);
    Set<PosixFilePermission> permissionsToSet;
    if (incrementAndGet % 2 == 0) {
        permissionsToSet = DEFAULT_JAVA7_FILE_PERMISSIONS;
    } else {
        permissionsToSet = WEIRD_JAVA7_FILE_PERMISSIONS;
    }
    // This should pass 50% of the time
    if (!originalPermissions.equals(permissionsToSet)) {
        Files.setPosixFilePermissions(file, permissionsToSet);
    }
    blackhole.consume(file);
}
Also used : Path(java.nio.file.Path) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Aggregations

PosixFilePermission (java.nio.file.attribute.PosixFilePermission)36 Path (java.nio.file.Path)21 IOException (java.io.IOException)10 Test (org.junit.Test)7 File (java.io.File)6 PosixFileAttributes (java.nio.file.attribute.PosixFileAttributes)6 HashSet (java.util.HashSet)6 PosixFileAttributeView (java.nio.file.attribute.PosixFileAttributeView)4 Set (java.util.Set)4 GroupPrincipal (java.nio.file.attribute.GroupPrincipal)3 TransferSettings (org.syncany.plugins.transfer.TransferSettings)3 TestClient (org.syncany.tests.util.TestClient)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 FileOutputStream (java.io.FileOutputStream)2 InputStream (java.io.InputStream)2 RandomAccessFile (java.io.RandomAccessFile)2 UserPrincipal (java.nio.file.attribute.UserPrincipal)2 Date (java.util.Date)2 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)2 ZipArchiveEntry (org.apache.commons.compress.archivers.zip.ZipArchiveEntry)2