IOUtils { public static File createTemporaryBuffer(TaskOutput taskOut) throws TaskIOException { TmpBufferLocationFinder bufferLocationFinder = new TmpBufferLocationFinder(); try { taskOut.accept(bufferLocationFinder); File buffer = tmpFile(bufferLocationFinder.bufferLocation).toFile(); buffer.deleteOnExit(); return buffer; } catch (TaskOutputVisitException | IOException e) { try { return createTemporaryBuffer(); } catch (TaskIOException ex) { throw new TaskIOException("Unable to create temporary buffer", ex); } } } private  IOUtils(); static File createTemporaryBuffer(TaskOutput taskOut); static File createTemporaryBuffer(); static File createTemporaryBuffer(String extension); static File createTemporaryBufferWithName(String filename); static File createTemporaryFolder(); static File findNewNameThatDoesNotExist(File output); static String shortenFilename(String name); static String toSafeFilename(String input); static String toStrictFilename(String input);  }
@Test public void testCreateBuffer() throws TaskIOException { File tmp = IOUtils.createTemporaryBuffer(); tmp.deleteOnExit(); assertTrue(tmp.exists()); assertTrue(tmp.isFile()); }
@Test public void testCreateBufferFileOut() throws TaskIOException, IOException { File file = folder.newFile("chuck.norris"); FileTaskOutput out = new FileTaskOutput(file); File tmp = IOUtils.createTemporaryBuffer(out); assertTrue(tmp.exists()); assertTrue(tmp.isFile()); assertEquals(file.getParent(), tmp.getParent()); }
@Test public void testCreateBufferFileOutNonExisting() throws TaskIOException { FileTaskOutput out = new FileTaskOutput(new File("I dont", "exist")); File tmp = IOUtils.createTemporaryBuffer(out); assertTrue(tmp.exists()); assertTrue(tmp.isFile()); assertEquals(SystemUtils.getJavaIoTmpDir().getAbsolutePath(), tmp.getParent()); }
@Test public void testCreateBufferFileOutNonExistingParentExists() throws TaskIOException, IOException { File dir = folder.newFolder("chuck.norris"); FileTaskOutput out = new FileTaskOutput(new File(dir.getAbsolutePath(), "I dont exist")); File tmp = IOUtils.createTemporaryBuffer(out); assertTrue(tmp.exists()); assertTrue(tmp.isFile()); assertEquals(dir.getAbsolutePath(), tmp.getParent()); }
@Test public void testCreateBufferDirectoryOut() throws TaskIOException, IOException { File dir = folder.newFolder("chuck.norris"); DirectoryTaskOutput out = new DirectoryTaskOutput(dir); File tmp = IOUtils.createTemporaryBuffer(out); assertTrue(tmp.exists()); assertTrue(tmp.isFile()); assertEquals(dir.getAbsolutePath(), tmp.getParent()); }
@Test public void testCreateBufferDirectoryOutNonExisting() throws TaskIOException { DirectoryTaskOutput out = new DirectoryTaskOutput(new File("I dont exist")); File tmp = IOUtils.createTemporaryBuffer(out); assertTrue(tmp.exists()); assertTrue(tmp.isFile()); assertEquals(SystemUtils.getJavaIoTmpDir().getAbsolutePath(), tmp.getParent()); }
@Test public void testCreateBufferFileOrDirectoryOutNonExisting() throws TaskIOException { FileOrDirectoryTaskOutput out = new FileOrDirectoryTaskOutput(new File("I dont exist")); File tmp = IOUtils.createTemporaryBuffer(out); assertTrue(tmp.exists()); assertTrue(tmp.isFile()); assertEquals(SystemUtils.getJavaIoTmpDir().getAbsolutePath(), tmp.getParent()); }
@Test public void testCreateBufferFileOrDirectoryOutFile() throws TaskIOException, IOException { File file = folder.newFile("chuck.norris"); FileOrDirectoryTaskOutput out = new FileOrDirectoryTaskOutput(file); File tmp = IOUtils.createTemporaryBuffer(out); assertTrue(tmp.exists()); assertTrue(tmp.isFile()); assertEquals(file.getParent(), tmp.getParent()); }
@Test public void testCreateBufferFileOrDirectoryOutDir() throws TaskIOException, IOException { File dir = folder.newFolder(); FileOrDirectoryTaskOutput out = new FileOrDirectoryTaskOutput(dir); File tmp = IOUtils.createTemporaryBuffer(out); assertTrue(tmp.exists()); assertTrue(tmp.isFile()); assertEquals(dir.getAbsolutePath(), tmp.getParent()); }
@Test public void noNPEIfParentIsMissing() throws TaskIOException { assertNotNull(IOUtils.createTemporaryBuffer(new FileTaskOutput(new File("test.pdf")))); }