Example usage for java.nio.file Files createTempDirectory

List of usage examples for java.nio.file Files createTempDirectory

Introduction

In this page you can find the example usage for java.nio.file Files createTempDirectory.

Prototype

public static Path createTempDirectory(String prefix, FileAttribute<?>... attrs) throws IOException 

Source Link

Document

Creates a new directory in the default temporary-file directory, using the given prefix to generate its name.

Usage

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

@Test
public void testStartReadAllJobUsingStreamedBehavior() throws IOException {
    final String tempPathPrefix = null;
    final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix);

    try {//from   w  ww  .  j  ava  2 s. c o  m
        final AtomicInteger numFailuresRecorded = new AtomicInteger(0);

        final FailureEventListener failureEventListener = new FailureEventListener() {
            @Override
            public void onFailure(final FailureEvent failureEvent) {
                numFailuresRecorded.incrementAndGet();
                assertEquals(FailureEvent.FailureActivity.GettingObject, failureEvent.doingWhat());
            }
        };

        final Ds3ClientHelpers.Job readJob = HELPERS.startReadAllJobUsingStreamedBehavior(BUCKET_NAME);
        readJob.attachFailureEventListener(failureEventListener);
        readJob.transfer(new FileObjectGetter(tempDirectory));

        final Collection<File> filesInTempDirectory = FileUtils.listFiles(tempDirectory.toFile(), null, false);

        final List<String> filesWeExpectToBeInTempDirectory = Arrays.asList("beowulf.txt", "lesmis.txt",
                "lesmis-copies.txt", "GreatExpectations.txt");

        for (final File fileInTempDirectory : filesInTempDirectory) {
            assertTrue(filesWeExpectToBeInTempDirectory.contains(fileInTempDirectory.getName()));
        }

        assertEquals(0, numFailuresRecorded.get());
    } finally {
        FileUtils.deleteDirectory(tempDirectory.toFile());
    }
}

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

@Test
public void testStartReadAllJobUsingRandomAccessBehavior() throws IOException {
    final String tempPathPrefix = null;
    final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix);

    try {/*from   w w  w .  j a v a2s .  c om*/
        final AtomicInteger numFailuresRecorded = new AtomicInteger(0);

        final FailureEventListener failureEventListener = new FailureEventListener() {
            @Override
            public void onFailure(final FailureEvent failureEvent) {
                numFailuresRecorded.incrementAndGet();
                assertEquals(FailureEvent.FailureActivity.GettingObject, failureEvent.doingWhat());
            }
        };

        final Ds3ClientHelpers.Job readJob = HELPERS.startReadAllJobUsingRandomAccessBehavior(BUCKET_NAME);
        readJob.attachFailureEventListener(failureEventListener);
        readJob.transfer(new FileObjectGetter(tempDirectory));

        final Collection<File> filesInTempDirectory = FileUtils.listFiles(tempDirectory.toFile(), null, false);

        final List<String> filesWeExpectToBeInTempDirectory = Arrays.asList("beowulf.txt", "lesmis.txt",
                "lesmis-copies.txt", "GreatExpectations.txt");

        for (final File fileInTempDirectory : filesInTempDirectory) {
            assertTrue(filesWeExpectToBeInTempDirectory.contains(fileInTempDirectory.getName()));
        }

        assertEquals(0, numFailuresRecorded.get());
    } finally {
        FileUtils.deleteDirectory(tempDirectory.toFile());
    }
}

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

@Test
public void testGetJobUsingTransferStrategy() throws IOException, InterruptedException {
    final String tempPathPrefix = null;
    final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix);
    final String fileName = "beowulf.txt";

    try {/*from  ww  w  .  ja  v a 2 s  .c  o  m*/
        final List<Ds3Object> objects = Lists.newArrayList(new Ds3Object(fileName));

        final GetBulkJobSpectraS3Request getBulkJobSpectraS3Request = new GetBulkJobSpectraS3Request(
                BUCKET_NAME, objects);

        final GetBulkJobSpectraS3Response getBulkJobSpectraS3Response = client
                .getBulkJobSpectraS3(getBulkJobSpectraS3Request);

        final MasterObjectList masterObjectList = getBulkJobSpectraS3Response.getMasterObjectList();

        final TransferStrategyBuilder transferStrategyBuilder = new TransferStrategyBuilder()
                .withDs3Client(client).withMasterObjectList(masterObjectList)
                .withChannelBuilder(new FileObjectGetter(tempDirectory))
                .withRangesForBlobs(PartialObjectHelpers.mapRangesToBlob(masterObjectList.getObjects(),
                        PartialObjectHelpers.getPartialObjectsRanges(objects)));

        final TransferStrategy transferStrategy = transferStrategyBuilder.makeGetTransferStrategy();

        transferStrategy.transfer();

        final Collection<File> filesInTempDirectory = FileUtils.listFiles(tempDirectory.toFile(), null, false);

        for (final File file : filesInTempDirectory) {
            assertEquals(fileName, file.getName());
        }
    } finally {
        FileUtils.deleteDirectory(tempDirectory.toFile());
    }
}

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

@Test
public void testReadJobUsingTransferStrategy() throws IOException, InterruptedException {
    final String tempPathPrefix = null;
    final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix);
    final String fileName = "beowulf.txt";

    try {/*from   www . ja va2  s  .c  o  m*/
        final List<Ds3Object> objects = Lists.newArrayList(new Ds3Object(fileName));

        final GetBulkJobSpectraS3Request getBulkJobSpectraS3Request = new GetBulkJobSpectraS3Request(
                BUCKET_NAME, objects);

        final GetBulkJobSpectraS3Response getBulkJobSpectraS3Response = client
                .getBulkJobSpectraS3(getBulkJobSpectraS3Request);

        final MasterObjectList masterObjectList = getBulkJobSpectraS3Response.getMasterObjectList();

        final TransferStrategyBuilder transferStrategyBuilder = new TransferStrategyBuilder()
                .withDs3Client(client).withMasterObjectList(masterObjectList)
                .withChannelBuilder(new FileObjectGetter(tempDirectory))
                .withRangesForBlobs(PartialObjectHelpers.mapRangesToBlob(masterObjectList.getObjects(),
                        PartialObjectHelpers.getPartialObjectsRanges(objects)));

        final TransferStrategy transferStrategy = transferStrategyBuilder.makeGetTransferStrategy();

        Ds3ClientHelpers.wrap(client).startReadJob(transferStrategy).transfer();

        final Collection<File> filesInTempDirectory = FileUtils.listFiles(tempDirectory.toFile(), null, false);

        for (final File file : filesInTempDirectory) {
            assertEquals(fileName, file.getName());
        }
    } finally {
        FileUtils.deleteDirectory(tempDirectory.toFile());
    }
}

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

@Test
public void testGetJobWithUserSuppliedBlobStrategy() throws IOException, InterruptedException {
    final String tempPathPrefix = null;
    final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix);
    final String fileName = "beowulf.txt";

    try {/*w  w  w.j  a  v  a  2  s .c o  m*/
        final List<Ds3Object> objects = Lists.newArrayList(new Ds3Object(fileName));

        final GetBulkJobSpectraS3Request getBulkJobSpectraS3Request = new GetBulkJobSpectraS3Request(
                BUCKET_NAME, objects);

        final GetBulkJobSpectraS3Response getBulkJobSpectraS3Response = client
                .getBulkJobSpectraS3(getBulkJobSpectraS3Request);

        final MasterObjectList masterObjectList = getBulkJobSpectraS3Response.getMasterObjectList();

        final EventDispatcher eventDispatcher = new EventDispatcherImpl(new SameThreadEventRunner());

        final AtomicInteger numChunkAllocationAttempts = new AtomicInteger(0);

        final TransferStrategyBuilder transferStrategyBuilder = new TransferStrategyBuilder()
                .withDs3Client(client).withMasterObjectList(masterObjectList)
                .withChannelBuilder(new FileObjectGetter(tempDirectory))
                .withRangesForBlobs(PartialObjectHelpers.mapRangesToBlob(masterObjectList.getObjects(),
                        PartialObjectHelpers.getPartialObjectsRanges(objects)))
                .withBlobStrategy(new UserSuppliedPutBlobStrategy(client, masterObjectList, eventDispatcher,
                        new MaxChunkAttemptsRetryBehavior(5),
                        new ClientDefinedChunkAttemptRetryDelayBehavior(1, eventDispatcher), new Monitorable() {
                            @Override
                            public void monitor() {
                                numChunkAllocationAttempts.getAndIncrement();
                            }
                        }));

        final TransferStrategy transferStrategy = transferStrategyBuilder.makeGetTransferStrategy();

        transferStrategy.transfer();

        final Collection<File> filesInTempDirectory = FileUtils.listFiles(tempDirectory.toFile(), null, false);

        for (final File file : filesInTempDirectory) {
            assertEquals(fileName, file.getName());
        }

        assertEquals(1, numChunkAllocationAttempts.get());
    } finally {
        FileUtils.deleteDirectory(tempDirectory.toFile());
    }
}

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

private void testGetJobWithUserSuppliedChannelStrategy(
        final TransferStrategyBuilderModifiable transferStrategyBuilderModifiable)
        throws IOException, InterruptedException {
    final String tempPathPrefix = null;
    final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix);
    final String fileName = "beowulf.txt";

    try {/*from  www. ja va2  s.  com*/
        final List<Ds3Object> objects = Lists.newArrayList(new Ds3Object(fileName));

        final GetBulkJobSpectraS3Request getBulkJobSpectraS3Request = new GetBulkJobSpectraS3Request(
                BUCKET_NAME, objects);

        final GetBulkJobSpectraS3Response getBulkJobSpectraS3Response = client
                .getBulkJobSpectraS3(getBulkJobSpectraS3Request);

        final MasterObjectList masterObjectList = getBulkJobSpectraS3Response.getMasterObjectList();

        final AtomicInteger numTimesChannelOpened = new AtomicInteger(0);
        final AtomicInteger numTimesChannelClosed = new AtomicInteger(0);

        TransferStrategyBuilder transferStrategyBuilder = new TransferStrategyBuilder().withDs3Client(client)
                .withMasterObjectList(masterObjectList).withChannelBuilder(new FileObjectGetter(tempDirectory))
                .withRangesForBlobs(PartialObjectHelpers.mapRangesToBlob(masterObjectList.getObjects(),
                        PartialObjectHelpers.getPartialObjectsRanges(objects)))
                .withChannelStrategy(new UserSuppliedPutChannelStrategy(new FileObjectGetter(tempDirectory),
                        new ChannelMonitorable() {
                            @Override
                            public void acquired() {
                                numTimesChannelOpened.getAndIncrement();
                            }

                            @Override
                            public void released() {
                                numTimesChannelClosed.getAndIncrement();
                            }
                        }));

        transferStrategyBuilder = transferStrategyBuilderModifiable.modify(transferStrategyBuilder);

        final TransferStrategy transferStrategy = transferStrategyBuilder.makeGetTransferStrategy();

        transferStrategy.transfer();

        final Collection<File> filesInTempDirectory = FileUtils.listFiles(tempDirectory.toFile(), null, false);

        for (final File file : filesInTempDirectory) {
            assertEquals(fileName, file.getName());
        }

        assertEquals(1, numTimesChannelOpened.get());
        assertEquals(1, numTimesChannelClosed.get());
    } finally {
        FileUtils.deleteDirectory(tempDirectory.toFile());
    }
}

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

@Test
public void testGetJobUserSuppliedTransferRetryDecorator() throws IOException, InterruptedException {
    final String tempPathPrefix = null;
    final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix);
    final String fileName = "beowulf.txt";

    try {//from   w ww . ja  va 2 s  .co  m
        final List<Ds3Object> objects = Lists.newArrayList(new Ds3Object(fileName));

        final GetBulkJobSpectraS3Request getBulkJobSpectraS3Request = new GetBulkJobSpectraS3Request(
                BUCKET_NAME, objects);

        final GetBulkJobSpectraS3Response getBulkJobSpectraS3Response = client
                .getBulkJobSpectraS3(getBulkJobSpectraS3Request);

        final MasterObjectList masterObjectList = getBulkJobSpectraS3Response.getMasterObjectList();

        final AtomicInteger numTimesTransferCalled = new AtomicInteger(0);

        final TransferStrategyBuilder transferStrategyBuilder = new TransferStrategyBuilder()
                .withDs3Client(client).withMasterObjectList(masterObjectList)
                .withChannelBuilder(new FileObjectGetter(tempDirectory))
                .withRangesForBlobs(PartialObjectHelpers.mapRangesToBlob(masterObjectList.getObjects(),
                        PartialObjectHelpers.getPartialObjectsRanges(objects)))
                .withTransferRetryDecorator(new UserSuppliedTransferRetryDecorator(new Monitorable() {
                    @Override
                    public void monitor() {
                        numTimesTransferCalled.getAndIncrement();
                    }
                }));

        final TransferStrategy transferStrategy = transferStrategyBuilder.makeGetTransferStrategy();

        transferStrategy.transfer();

        final Collection<File> filesInTempDirectory = FileUtils.listFiles(tempDirectory.toFile(), null, false);

        for (final File file : filesInTempDirectory) {
            assertEquals(fileName, file.getName());
        }

        assertEquals(1, numTimesTransferCalled.get());
    } finally {
        FileUtils.deleteDirectory(tempDirectory.toFile());
    }
}

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

@Test
public void testGetJobUserSuppliedChunkAttemptRetryBehavior() throws IOException, InterruptedException {
    final String tempPathPrefix = null;
    final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix);
    final String fileName = "beowulf.txt";

    try {//from   w  ww. j  a  v  a2s  .  c o  m
        final List<Ds3Object> objects = Lists.newArrayList(new Ds3Object(fileName));

        final GetBulkJobSpectraS3Request getBulkJobSpectraS3Request = new GetBulkJobSpectraS3Request(
                BUCKET_NAME, objects);

        final GetBulkJobSpectraS3Response getBulkJobSpectraS3Response = client
                .getBulkJobSpectraS3(getBulkJobSpectraS3Request);

        final MasterObjectList masterObjectList = getBulkJobSpectraS3Response.getMasterObjectList();

        final AtomicInteger numTimesInvokeCalled = new AtomicInteger(0);
        final AtomicInteger numTimesResetCalled = new AtomicInteger(0);

        final TransferStrategyBuilder transferStrategyBuilder = new TransferStrategyBuilder()
                .withDs3Client(client).withMasterObjectList(masterObjectList)
                .withChannelBuilder(new FileObjectGetter(tempDirectory))
                .withRangesForBlobs(PartialObjectHelpers.mapRangesToBlob(masterObjectList.getObjects(),
                        PartialObjectHelpers.getPartialObjectsRanges(objects)))
                .withChunkAttemptRetryBehavior(
                        new UserSuppliedChunkAttemptRetryBehavior(new ChunkAttemptRetryBehaviorMonitorable() {
                            @Override
                            public void invoke() {
                                numTimesInvokeCalled.getAndIncrement();
                            }

                            @Override
                            public void reset() {
                                numTimesResetCalled.getAndIncrement();
                            }
                        }));

        final TransferStrategy transferStrategy = transferStrategyBuilder.makeGetTransferStrategy();

        transferStrategy.transfer();

        final Collection<File> filesInTempDirectory = FileUtils.listFiles(tempDirectory.toFile(), null, false);

        for (final File file : filesInTempDirectory) {
            assertEquals(fileName, file.getName());
        }

        assertEquals(0, numTimesInvokeCalled.get());
        assertEquals(1, numTimesResetCalled.get());
    } finally {
        FileUtils.deleteDirectory(tempDirectory.toFile());
    }
}

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

@Test
public void testThatFifoIsNotProcessed() throws IOException, InterruptedException {
    Assume.assumeFalse(Platform.isWindows());

    final String tempPathPrefix = null;
    final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix);

    final String BEOWULF_FILE_NAME = "beowulf.txt";

    final AtomicBoolean caughtException = new AtomicBoolean(false);

    try {/*from w  ww.  j  a va  2  s .co m*/
        Runtime.getRuntime().exec("mkfifo " + Paths.get(tempDirectory.toString(), BEOWULF_FILE_NAME)).waitFor();

        final List<Ds3Object> ds3Objects = Arrays.asList(new Ds3Object(BEOWULF_FILE_NAME));

        final Ds3ClientHelpers.Job readJob = HELPERS.startReadJob(BUCKET_NAME, ds3Objects);
        readJob.transfer(new FileObjectPutter(tempDirectory));
    } catch (final UnrecoverableIOException e) {
        assertTrue(e.getMessage().contains(BEOWULF_FILE_NAME));
        caughtException.set(true);
    } finally {
        FileUtils.deleteDirectory(tempDirectory.toFile());
    }

    assertTrue(caughtException.get());
}