Java Code Examples for org.apache.commons.lang.SystemUtils#getJavaIoTmpDir()
The following examples show how to use
org.apache.commons.lang.SystemUtils#getJavaIoTmpDir() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JarManagerService.java From DBus with Apache License 2.0 | 6 votes |
public ResultEntity uploads(String category, String version, String type, MultipartFile jarFile) throws IOException { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); headers.setContentDispositionFormData("jarFile", jarFile.getOriginalFilename()); MultiValueMap<String, Object> data = new LinkedMultiValueMap<>(); File saveDir = new File(SystemUtils.getJavaIoTmpDir(), String.valueOf(System.currentTimeMillis())); if (!saveDir.exists()) saveDir.mkdirs(); File tempFile = new File(saveDir, jarFile.getOriginalFilename()); jarFile.transferTo(tempFile); FileSystemResource fsr = new FileSystemResource(tempFile); data.add("jarFile", fsr); HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(data, headers); URLBuilder urlBulider = new URLBuilder(ServiceNames.KEEPER_SERVICE, "/jars/uploads/{0}/{1}/{2}"); ResponseEntity<ResultEntity> result = rest.postForEntity(urlBulider.build(), entity, ResultEntity.class, version, type, category); if (tempFile.exists()) tempFile.delete(); if (saveDir.exists()) saveDir.delete(); return result.getBody(); }
Example 2
Source File: JarManagerService.java From DBus with Apache License 2.0 | 6 votes |
public ResultEntity uploadsEncodePlugin(String name, Integer projectId, MultipartFile jarFile) throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); headers.setContentDispositionFormData("jarFile", jarFile.getOriginalFilename()); MultiValueMap<String, Object> data = new LinkedMultiValueMap<>(); File saveDir = new File(SystemUtils.getJavaIoTmpDir(), String.valueOf(System.currentTimeMillis())); if (!saveDir.exists()) saveDir.mkdirs(); File tempFile = new File(saveDir, jarFile.getOriginalFilename()); jarFile.transferTo(tempFile); FileSystemResource fsr = new FileSystemResource(tempFile); data.add("jarFile", fsr); HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(data, headers); URLBuilder urlBulider = new URLBuilder(ServiceNames.KEEPER_SERVICE, "/jars/uploads-encode-plugin/{0}/{1}"); ResponseEntity<ResultEntity> result = rest.postForEntity(urlBulider.build(), entity, ResultEntity.class, name, projectId); if (tempFile.exists()) tempFile.delete(); if (saveDir.exists()) saveDir.delete(); return result.getBody(); }
Example 3
Source File: JarManagerService.java From DBus with Apache License 2.0 | 6 votes |
public ResultEntity uploadsKeytab(Integer projectId, String principal, MultipartFile jarFile) throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); headers.setContentDispositionFormData("jarFile", jarFile.getOriginalFilename()); MultiValueMap<String, Object> data = new LinkedMultiValueMap<>(); File saveDir = new File(SystemUtils.getJavaIoTmpDir(), String.valueOf(System.currentTimeMillis())); if (!saveDir.exists()) saveDir.mkdirs(); File tempFile = new File(saveDir, jarFile.getOriginalFilename()); jarFile.transferTo(tempFile); FileSystemResource fsr = new FileSystemResource(tempFile); data.add("jarFile", fsr); HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(data, headers); URLBuilder urlBulider = new URLBuilder(ServiceNames.KEEPER_SERVICE, "/jars/uploads-keytab?projectId={0}&principal={1}"); ResponseEntity<ResultEntity> result = rest.postForEntity(urlBulider.build(), entity, ResultEntity.class, projectId, principal); if (tempFile.exists()) tempFile.delete(); if (saveDir.exists()) saveDir.delete(); return result.getBody(); }
Example 4
Source File: TableService.java From DBus with Apache License 2.0 | 6 votes |
public ResultEntity importRulesByTableId(Integer tableId, MultipartFile uploadFile) throws Exception { File saveDir = new File(SystemUtils.getJavaIoTmpDir(), String.valueOf(System.currentTimeMillis())); if (!saveDir.exists()) saveDir.mkdirs(); File tempFile = new File(saveDir, uploadFile.getOriginalFilename()); uploadFile.transferTo(tempFile); StringBuilder sb = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new FileReader(tempFile)); String line = null; while ((line = br.readLine()) != null) { sb.append(line); } } finally { if (br != null) { br.close(); } if (tempFile != null && tempFile.exists()) { tempFile.delete(); } } return sender.post(ServiceNames.KEEPER_SERVICE, "/tables/importRulesByTableId/" + tableId, sb.toString()).getBody(); }
Example 5
Source File: SignToolTest.java From webstart with MIT License | 5 votes |
public void testGetKeyStoreFile() throws Exception { File tmpDir = SystemUtils.getJavaIoTmpDir(); File parentDir = new File( tmpDir, "tmp" ); File keyStoreFile; ClassLoader classLoader = getClassLoader(); // from classpath with / start keyStoreFile = signTool.getKeyStoreFile( "classpath:/test/myfile.txt", new File( tmpDir, "myfile2.txt" ), classLoader ); assertNotNull( keyStoreFile ); assertEquals( "myfile2.txt", keyStoreFile.getName() ); assertEquals( tmpDir, keyStoreFile.getParentFile() ); // from classpath keyStoreFile = signTool.getKeyStoreFile( "classpath:test/myfile.txt", new File( tmpDir, "myfile2.txt" ), classLoader ); assertNotNull( keyStoreFile ); assertEquals( "myfile2.txt", keyStoreFile.getName() ); assertEquals( tmpDir, keyStoreFile.getParentFile() ); // from a direct file (no change) keyStoreFile = signTool.getKeyStoreFile( keyStoreFile.getAbsolutePath(), new File( parentDir, "myfile3.txt" ), classLoader ); assertNotNull( keyStoreFile ); assertEquals( "myfile2.txt", keyStoreFile.getName() ); assertEquals( tmpDir, keyStoreFile.getParentFile() ); //from a url (from a file) keyStoreFile = signTool.getKeyStoreFile( keyStoreFile.toURI().toString(), new File( parentDir, "myfile3.txt" ), classLoader ); assertNotNull( keyStoreFile ); assertEquals( "myfile3.txt", keyStoreFile.getName() ); assertEquals( parentDir, keyStoreFile.getParentFile() ); }