List of usage examples for java.nio.file Files createTempDirectory
public static Path createTempDirectory(String prefix, FileAttribute<?>... attrs) throws IOException
From source file:com.spectralogic.ds3client.integration.GetJobManagement_Test.java
@Test public void testReadRetrybugWhenChannelThrowsAccessException() throws IOException, URISyntaxException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { final String tempPathPrefix = null; final Path tempDirectoryPath = Files.createTempDirectory(Paths.get("."), tempPathPrefix); final AtomicBoolean caughtException = new AtomicBoolean(false); try {/*ww w . java2 s . co m*/ final String DIR_NAME = "largeFiles/"; final String FILE_NAME = "lesmis-copies.txt"; final Path objPath = ResourceUtils.loadFileResource(DIR_NAME + FILE_NAME); final long bookSize = Files.size(objPath); final Ds3Object obj = new Ds3Object(FILE_NAME, bookSize); final Ds3ClientShim ds3ClientShim = new Ds3ClientShim((Ds3ClientImpl) client); final int maxNumBlockAllocationRetries = 1; final int maxNumObjectTransferAttempts = 3; final Ds3ClientHelpers ds3ClientHelpers = Ds3ClientHelpers.wrap(ds3ClientShim, maxNumBlockAllocationRetries, maxNumObjectTransferAttempts); final Ds3ClientHelpers.Job readJob = ds3ClientHelpers.startReadJob(BUCKET_NAME, Arrays.asList(obj)); final GetJobSpectraS3Response jobSpectraS3Response = ds3ClientShim .getJobSpectraS3(new GetJobSpectraS3Request(readJob.getJobId())); assertThat(jobSpectraS3Response.getMasterObjectListResult(), is(notNullValue())); readJob.transfer(new Ds3ClientHelpers.ObjectChannelBuilder() { @Override public SeekableByteChannel buildChannel(final String key) throws IOException { throw new AccessControlException(key); } }); } catch (final IOException e) { caughtException.set(true); assertTrue(e.getCause() instanceof AccessControlException); } finally { FileUtils.deleteDirectory(tempDirectoryPath.toFile()); } assertTrue(caughtException.get()); }
From source file:org.corehunter.tests.data.simple.SimpleDefaultGenotypeDataTest.java
@Test public void diploidToCsvFileWithUnselectedIds() throws IOException { expectedHeaders = HEADERS_UNIQUE_NAMES; expectedMarkerNames = MARKER_NAMES_DEFAULT; expectedAlleleNames = ALLELE_NAMES_DIPLOID; SimpleDefaultGenotypeData genotypicData = new SimpleDefaultGenotypeData(NAME, HEADERS_UNIQUE_NAMES, MARKER_NAMES_DEFAULT, ALLELE_OBS_DIPLOID); Set<Integer> ids = genotypicData.getIDs(); Path dirPath = Paths.get(TEST_OUTPUT); Files.createDirectories(dirPath); dirPath = Files.createTempDirectory(dirPath, "GenoDiploid-UnselectedIds"); // create solution SubsetSolution solution = new SubsetSolution(ids); for (int sel : SELECTION) { solution.select(sel);/*from ww w. j a v a 2 s . c om*/ } Path path; // write with integer ids dataName = "with-ids.csv"; path = Paths.get(dirPath.toString(), dataName); System.out.println(" |- Write default genotypes file (diploid, with solution) " + dataName); genotypicData.writeData(path, FileType.CSV, solution, false, true, true); assertTrue("Output is not correct!", FileUtils.contentEquals( new File(SimpleDistanceMatrixDataTest.class .getResource("/diploid_genotypes/out/unsel-with-ids.csv").getPath()), path.toFile())); // write without integer ids dataName = "no-ids.csv"; path = Paths.get(dirPath.toString(), dataName); System.out.println(" |- Write default genotypes file (diploid, with solution) " + dataName); genotypicData.writeData(path, FileType.CSV, solution, false, true, false); assertTrue("Output is not correct!", FileUtils .contentEquals( new File(SimpleDistanceMatrixDataTest.class .getResource("/diploid_genotypes/out/unsel-no-ids.csv").getPath()), path.toFile())); }
From source file:com.spectralogic.ds3client.integration.GetJobManagement_Test.java
@Test public void testReadRetryBugWhenDiskIsFull() throws IOException, URISyntaxException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { final String tempPathPrefix = null; final Path tempDirectoryPath = Files.createTempDirectory(Paths.get("."), tempPathPrefix); try {/* w w w . j a v a 2s. com*/ final String DIR_NAME = "largeFiles/"; final String FILE_NAME = "lesmis-copies.txt"; final Path objPath = ResourceUtils.loadFileResource(DIR_NAME + FILE_NAME); final long bookSize = Files.size(objPath); final Ds3Object obj = new Ds3Object(FILE_NAME, bookSize); final Ds3ClientShim ds3ClientShim = new Ds3ClientShim((Ds3ClientImpl) client); final int maxNumBlockAllocationRetries = 1; final int maxNumObjectTransferAttempts = 3; final Ds3ClientHelpers ds3ClientHelpers = Ds3ClientHelpers.wrap(ds3ClientShim, maxNumBlockAllocationRetries, maxNumObjectTransferAttempts); final Ds3ClientHelpers.Job readJob = ds3ClientHelpers.startReadJob(BUCKET_NAME, Arrays.asList(obj)); final GetJobSpectraS3Response jobSpectraS3Response = ds3ClientShim .getJobSpectraS3(new GetJobSpectraS3Request(readJob.getJobId())); assertThat(jobSpectraS3Response.getMasterObjectListResult(), is(notNullValue())); try { readJob.transfer(new FailingChannelBuilder()); } catch (final UnrecoverableIOException e) { assertEquals(DISK_FULL_MESSAGE, e.getCause().getMessage()); } } finally { FileUtils.deleteDirectory(tempDirectoryPath.toFile()); } }
From source file:com.boundlessgeo.geoserver.AppIntegrationTest.java
@Test public void testWorkspaceExport() throws Exception { MockHttpServletResponse response = doWorkspaceExport("sf"); assertEquals("application/zip", response.getContentType()); assertEquals("attachment; filename=\"sf.zip\"", response.getHeader("Content-Disposition")); Path tmp = Files.createTempDirectory(Paths.get("target"), "export"); org.geoserver.data.util.IOUtils.decompress(new ByteArrayInputStream(response.getContentAsByteArray()), tmp.toFile());/* www. j a v a 2 s.c o m*/ assertTrue(tmp.resolve("bundle.json").toFile().exists()); }
From source file:com.spectralogic.ds3client.integration.GetJobManagement_Test.java
@Test public void testPartialRetriesWithInjectedFailures() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, IOException, URISyntaxException { final String tempPathPrefix = null; final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix); try {//from ww w . j a v a 2 s.c om final List<Ds3Object> filesToGet = new ArrayList<>(); final String DIR_NAME = "largeFiles/"; final String FILE_NAME = "GreatExpectations.txt"; final int offsetIntoFirstRange = 10; filesToGet.add(new PartialDs3Object(FILE_NAME, Range.byLength(200000, 100000))); filesToGet.add(new PartialDs3Object(FILE_NAME, Range.byLength(100000, 100000))); filesToGet.add(new PartialDs3Object(FILE_NAME, Range.byLength(offsetIntoFirstRange, 100000))); final Ds3ClientShim ds3ClientShim = new Ds3ClientShim((Ds3ClientImpl) client); final int maxNumBlockAllocationRetries = 1; final int maxNumObjectTransferAttempts = 4; final Ds3ClientHelpers ds3ClientHelpers = Ds3ClientHelpers.wrap(ds3ClientShim, maxNumBlockAllocationRetries, maxNumObjectTransferAttempts); final Ds3ClientHelpers.Job job = ds3ClientHelpers.startReadJob(BUCKET_NAME, filesToGet); final AtomicInteger intValue = new AtomicInteger(); job.attachObjectCompletedListener(new ObjectCompletedListener() { int numPartsCompleted = 0; @Override public void objectCompleted(final String name) { assertEquals(1, ++numPartsCompleted); intValue.incrementAndGet(); } }); job.attachDataTransferredListener(new DataTransferredListener() { @Override public void dataTransferred(final long size) { LOG.info("Data transferred size: {}", size); } }); job.transfer(new FileObjectGetter(tempDirectory)); assertEquals(1, intValue.get()); try (final InputStream originalFileStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream(DIR_NAME + FILE_NAME)) { final byte[] first300000Bytes = new byte[300000 - offsetIntoFirstRange]; originalFileStream.skip(offsetIntoFirstRange); int numBytesRead = originalFileStream.read(first300000Bytes, 0, 300000 - offsetIntoFirstRange); assertThat(numBytesRead, is(300000 - offsetIntoFirstRange)); try (final InputStream fileReadFromBP = Files .newInputStream(Paths.get(tempDirectory.toString(), FILE_NAME))) { final byte[] first300000BytesFromBP = new byte[300000 - offsetIntoFirstRange]; numBytesRead = fileReadFromBP.read(first300000BytesFromBP, 0, 300000 - offsetIntoFirstRange); assertThat(numBytesRead, is(300000 - offsetIntoFirstRange)); assertTrue(Arrays.equals(first300000Bytes, first300000BytesFromBP)); } } } finally { FileUtils.deleteDirectory(tempDirectory.toFile()); } }
From source file:com.spectralogic.ds3client.helpers.JobImpl_Test.java
@Test public void testReadObjectCompletionFiresInternalHandlersFirst() throws NoSuchMethodException, IOException, ClassNotFoundException, URISyntaxException, IllegalAccessException, InvocationTargetException, NoSuchFieldException { putBigFileIntoBlackPearl();/*from w ww . j a va 2s. c o m*/ final String tempPathPrefix = null; final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix); final IntValue intValue = new IntValue(); final ObjectCompletedListener objectCompletedListener = new ObjectCompletedListener() { private int numCompletedObjects = 0; @Override public void objectCompleted(final String name) { intValue.increment(); assertTrue(bookTitles.contains(name)); assertEquals(1, ++numCompletedObjects); } }; final DataTransferredListener dataTransferredListener = new DataTransferredListener() { @Override public void dataTransferred(final long size) { } }; try { final JobImplJobPartDecoratorPair jobImplJobPartDecoratorPair = createJobPartDecoratorAndEnsureObjectPartTrackersPopulated( objectCompletedListener, dataTransferredListener, AccessMode.ForReading); final JobPartDecoratorInterceptor jobPartDecoratorInterceptor = new JobPartDecoratorInterceptor( jobImplJobPartDecoratorPair); jobPartDecoratorInterceptor.transfer(new FileObjectGetter(tempDirectory)); assertTrue(jobPartDecoratorInterceptor.bothHandlersFired()); } finally { FileUtils.deleteDirectory(tempDirectory.toFile()); } }
From source file:com.spectralogic.ds3client.integration.GetJobManagement_Test.java
@Test public void testFiringFailureHandlerWhenGettingChunks() throws URISyntaxException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, IOException { final String tempPathPrefix = null; final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix); try {/*ww w . j a v a2s. c o m*/ final AtomicInteger numFailuresRecorded = new AtomicInteger(); final FailureEventListener failureEventListener = new FailureEventListener() { @Override public void onFailure(final FailureEvent failureEvent) { numFailuresRecorded.incrementAndGet(); assertEquals(FailureEvent.FailureActivity.GettingObject, failureEvent.doingWhat()); } }; final Ds3ClientHelpers.Job readJob = createReadJobWithObjectsReadyToTransfer( Ds3ClientShimFactory.ClientFailureType.ChunkAllocation); readJob.attachFailureEventListener(failureEventListener); try { readJob.transfer(new FileObjectGetter(tempDirectory)); } catch (final IOException e) { assertEquals(1, numFailuresRecorded.get()); } } finally { FileUtils.deleteDirectory(tempDirectory.toFile()); } }
From source file:com.spectralogic.ds3client.integration.GetJobManagement_Test.java
@Test public void testFiringFailureHandlerWhenGettingObject() throws URISyntaxException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, IOException { final String tempPathPrefix = null; final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix); try {/*from w w w. ja v a 2s . c o m*/ final AtomicInteger numFailuresRecorded = new AtomicInteger(); final FailureEventListener failureEventListener = new FailureEventListener() { @Override public void onFailure(final FailureEvent failureEvent) { numFailuresRecorded.incrementAndGet(); assertEquals(FailureEvent.FailureActivity.GettingObject, failureEvent.doingWhat()); } }; final Ds3ClientHelpers.Job readJob = createReadJobWithObjectsReadyToTransfer( Ds3ClientShimFactory.ClientFailureType.GetObject); readJob.attachFailureEventListener(failureEventListener); try { readJob.transfer(new FileObjectGetter(tempDirectory)); } catch (final IOException e) { assertEquals(1, numFailuresRecorded.get()); } } finally { FileUtils.deleteDirectory(tempDirectory.toFile()); } }
From source file:com.spectralogic.ds3client.integration.GetJobManagement_Test.java
private void doReadJobWithJobStarter(final ReadJobStarter readJobStarter) throws IOException, URISyntaxException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { final String tempPathPrefix = null; final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix); try {//from w w w . j a v a2 s. com final String DIR_NAME = "largeFiles/"; final String FILE_NAME = "lesmis.txt"; final Path objPath = ResourceUtils.loadFileResource(DIR_NAME + FILE_NAME); final long bookSize = Files.size(objPath); final Ds3Object obj = new Ds3Object(FILE_NAME, bookSize); final Ds3ClientShim ds3ClientShim = new Ds3ClientShim((Ds3ClientImpl) client); final int maxNumBlockAllocationRetries = 1; final int maxNumObjectTransferAttempts = 3; final Ds3ClientHelpers ds3ClientHelpers = Ds3ClientHelpers.wrap(ds3ClientShim, maxNumBlockAllocationRetries, maxNumObjectTransferAttempts); final Ds3ClientHelpers.Job readJob = readJobStarter.startReadJob(ds3ClientHelpers, BUCKET_NAME, Arrays.asList(obj)); final AtomicBoolean dataTransferredEventReceived = new AtomicBoolean(false); final AtomicBoolean objectCompletedEventReceived = new AtomicBoolean(false); final AtomicBoolean checksumEventReceived = new AtomicBoolean(false); final AtomicBoolean metadataEventReceived = new AtomicBoolean(false); final AtomicBoolean waitingForChunksEventReceived = new AtomicBoolean(false); final AtomicBoolean failureEventReceived = new AtomicBoolean(false); readJob.attachDataTransferredListener(new DataTransferredListener() { @Override public void dataTransferred(final long size) { dataTransferredEventReceived.set(true); assertEquals(bookSize, size); } }); readJob.attachObjectCompletedListener(new ObjectCompletedListener() { @Override public void objectCompleted(final String name) { objectCompletedEventReceived.set(true); } }); readJob.attachChecksumListener(new ChecksumListener() { @Override public void value(final BulkObject obj, final ChecksumType.Type type, final String checksum) { checksumEventReceived.set(true); assertEquals("69+JXWeZuzl2HFTM6Lbo8A==", checksum); } }); readJob.attachMetadataReceivedListener(new MetadataReceivedListener() { @Override public void metadataReceived(final String filename, final Metadata metadata) { metadataEventReceived.set(true); } }); readJob.attachWaitingForChunksListener(new WaitingForChunksListener() { @Override public void waiting(final int secondsToWait) { waitingForChunksEventReceived.set(true); } }); readJob.attachFailureEventListener(new FailureEventListener() { @Override public void onFailure(final FailureEvent failureEvent) { failureEventReceived.set(true); } }); readJob.transfer(new FileObjectGetter(tempDirectory)); final File originalFile = ResourceUtils.loadFileResource(DIR_NAME + FILE_NAME).toFile(); final File fileCopiedFromBP = Paths.get(tempDirectory.toString(), FILE_NAME).toFile(); assertTrue(FileUtils.contentEquals(originalFile, fileCopiedFromBP)); assertTrue(dataTransferredEventReceived.get()); assertTrue(objectCompletedEventReceived.get()); assertTrue(checksumEventReceived.get()); assertTrue(metadataEventReceived.get()); assertFalse(waitingForChunksEventReceived.get()); assertFalse(failureEventReceived.get()); } finally { FileUtils.deleteDirectory(tempDirectory.toFile()); } }