@Test void saveToTempFile() throws UnsupportedEncodingException, IOException { String fileContent = "Hey dude"; when(part.getHeader("content-disposition")) .thenReturn("form-data; name=\"upload\"; filename=\"example.txt\""); when(part.getInputStream()).thenReturn(new ByteArrayInputStream(fileContent.getBytes("UTF-8"))); File tempFile = FileUploadUtils.saveToTempFile(part); try { assertNotNull(tempFile); assertTrue(tempFile.exists()); assertEquals(fileContent, copyToString(new FileReader(tempFile))); } finally { tempFile.delete(); } }
public static File saveToTempFile(Part part) throws IOException { String filename = getOriginalFileName(part); if (filename == null) { return null; } File file = File.createTempFile("molgenis-", "." + StringUtils.getFilenameExtension(filename)); FileCopyUtils.copy(part.getInputStream(), new FileOutputStream(file)); return file; }
FileUploadUtils { public static File saveToTempFile(Part part) throws IOException { String filename = getOriginalFileName(part); if (filename == null) { return null; } File file = File.createTempFile("molgenis-", "." + StringUtils.getFilenameExtension(filename)); FileCopyUtils.copy(part.getInputStream(), new FileOutputStream(file)); return file; } }
FileUploadUtils { public static File saveToTempFile(Part part) throws IOException { String filename = getOriginalFileName(part); if (filename == null) { return null; } File file = File.createTempFile("molgenis-", "." + StringUtils.getFilenameExtension(filename)); FileCopyUtils.copy(part.getInputStream(), new FileOutputStream(file)); return file; } private  FileUploadUtils(); }
FileUploadUtils { public static File saveToTempFile(Part part) throws IOException { String filename = getOriginalFileName(part); if (filename == null) { return null; } File file = File.createTempFile("molgenis-", "." + StringUtils.getFilenameExtension(filename)); FileCopyUtils.copy(part.getInputStream(), new FileOutputStream(file)); return file; } private  FileUploadUtils(); static File saveToTempFile(Part part); static File saveToTempFolder(Part part); static String getOriginalFileName(Part part); }
FileUploadUtils { public static File saveToTempFile(Part part) throws IOException { String filename = getOriginalFileName(part); if (filename == null) { return null; } File file = File.createTempFile("molgenis-", "." + StringUtils.getFilenameExtension(filename)); FileCopyUtils.copy(part.getInputStream(), new FileOutputStream(file)); return file; } private  FileUploadUtils(); static File saveToTempFile(Part part); static File saveToTempFolder(Part part); static String getOriginalFileName(Part part);  }