Example usage for java.nio.file StandardOpenOption DELETE_ON_CLOSE

List of usage examples for java.nio.file StandardOpenOption DELETE_ON_CLOSE

Introduction

In this page you can find the example usage for java.nio.file StandardOpenOption DELETE_ON_CLOSE.

Prototype

StandardOpenOption DELETE_ON_CLOSE

To view the source code for java.nio.file StandardOpenOption DELETE_ON_CLOSE.

Click Source Link

Document

Delete on close.

Usage

From source file:com.google.cloud.dataflow.sdk.io.TextIOTest.java

License:asdf

private GcsUtil buildMockGcsUtil() throws IOException {
    GcsUtil mockGcsUtil = Mockito.mock(GcsUtil.class);

    // Any request to open gets a new bogus channel
    Mockito.when(mockGcsUtil.open(Mockito.any(GcsPath.class))).then(new Answer<SeekableByteChannel>() {
        @Override/*from  w w w. ja  va  2  s. c om*/
        public SeekableByteChannel answer(InvocationOnMock invocation) throws Throwable {
            return FileChannel.open(Files.createTempFile("channel-", ".tmp"), StandardOpenOption.CREATE,
                    StandardOpenOption.DELETE_ON_CLOSE);
        }
    });

    // Any request for expansion returns a list containing the original GcsPath
    // This is required to pass validation that occurs in TextIO during apply()
    Mockito.when(mockGcsUtil.expand(Mockito.any(GcsPath.class))).then(new Answer<List<GcsPath>>() {
        @Override
        public List<GcsPath> answer(InvocationOnMock invocation) throws Throwable {
            return ImmutableList.of((GcsPath) invocation.getArguments()[0]);
        }
    });

    return mockGcsUtil;
}

From source file:com.spectralogic.ds3client.integration.Smoke_Test.java

@Test
public void getContents() throws IOException, URISyntaxException, XmlProcessingException, InterruptedException {
    final String bucketName = "test_get_contents";

    try {/*from w  w w  . j ava 2 s  .co m*/
        HELPERS.ensureBucketExists(bucketName, envDataPolicyId);
        loadBookTestData(client, bucketName);

        final Ds3ClientHelpers.Job job = HELPERS.startReadAllJob(bucketName);

        final UUID jobId = job.getJobId();

        job.transfer(new Ds3ClientHelpers.ObjectChannelBuilder() {
            @Override
            public SeekableByteChannel buildChannel(final String key) throws IOException {
                final Path filePath = Files.createTempFile("ds3", key);
                return Files.newByteChannel(filePath, StandardOpenOption.DELETE_ON_CLOSE,
                        StandardOpenOption.WRITE);
            }
        });

        assertThat(JobStatusHelper.getJobStatusWithRetries(client, jobId, JobStatus.COMPLETED),
                is(JobStatus.COMPLETED));

    } finally {
        deleteAllContents(client, bucketName);
    }
}

From source file:org.neo4j.io.pagecache.PageCacheTest.java

@Test(expected = NoSuchFileException.class)
public void fileMappedWithDeleteOnCloseMustNotExistAfterUnmap() throws Exception {
    getPageCache(fs, maxPages, pageCachePageSize, PageCacheTracer.NULL);
    pageCache.map(file("a"), filePageSize, StandardOpenOption.DELETE_ON_CLOSE).close();
    pageCache.map(file("a"), filePageSize);
}

From source file:org.neo4j.io.pagecache.PageCacheTest.java

@Test(expected = NoSuchFileException.class)
public void fileMappedWithDeleteOnCloseMustNotExistAfterLastUnmap() throws Exception {
    getPageCache(fs, maxPages, pageCachePageSize, PageCacheTracer.NULL);
    File file = file("a");
    try (PagedFile ignore = pageCache.map(file, filePageSize)) {
        pageCache.map(file, filePageSize, StandardOpenOption.DELETE_ON_CLOSE).close();
    }//  w  w w  . j  a  v  a  2s .  com
    pageCache.map(file, filePageSize);
}