Java Code Examples for org.apache.tomcat.util.http.fileupload.FileUtils#deleteDirectory()
The following examples show how to use
org.apache.tomcat.util.http.fileupload.FileUtils#deleteDirectory() .
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: PaySimProjectIntegrationTest.java From coderadar with MIT License | 5 votes |
@BeforeAll static void setUp() throws IOException { FileUtils.deleteDirectory(new File("coderadar-workdir/PaySim")); ZipFile zipFile = new ZipFile( PaySimProjectIntegrationTest.class .getClassLoader() .getResource("PaySim.zip") .getPath()); zipFile.extractAll("coderadar-workdir"); }
Example 2
Source File: PaySimProjectIntegrationTest.java From coderadar with MIT License | 4 votes |
@AfterAll static void cleanUp() throws IOException { FileUtils.deleteDirectory(new File("coderadar-workdir/PaySim")); }
Example 3
Source File: FrpController.java From frpMgr with MIT License | 4 votes |
@RequestMapping("/exportWin/{id}") @ResponseBody public void exportWin(@PathVariable String id, HttpServletResponse response) throws IOException { Frp frp = frpService.get(id); FrpServer frpServer = frpServerService.get(String.valueOf(frp.getServerId())); //创建临时文件夹 String zipName = UUID.randomUUID().toString(); String dir = System.getProperty("java.io.tmpdir") + File.separator + zipName + File.separator; String dir_client = System.getProperty("java.io.tmpdir") + File.separator + zipName + File.separator + "client"; File srcDir = new File(dir_client); log.info("临时文件夹准备"); //拷贝到临时文件夹 JarFileUtil.BatCopyFileFromJar("static/frp/frp-client", dir_client); log.info("拷贝到临时文件夹"); //读取frpc.ini File temp_file = new File(dir_client + File.separator +"frpc.ini"); StringBuffer res = new StringBuffer(); String line = null; BufferedReader reader = new BufferedReader(new FileReader(temp_file)); while ((line = reader.readLine()) != null) { res.append(line + "\n"); } reader.close(); log.info("读取文件"); BufferedWriter writer = new BufferedWriter(new FileWriter(temp_file)); String temp_string = res.toString(); //替换模板 String projectName = frp.getProjectName(); String subdomain = frp.getFrpDomainSecond(); String localport = frp.getFrpLocalPort(); temp_string = temp_string.replaceAll("project_name", projectName); temp_string = temp_string.replaceAll("frp_subdomain", subdomain); temp_string = temp_string.replaceAll("frp_local_port", localport); temp_string = temp_string.replaceAll("frp_server_addr", frpServer.getServerIp()); writer.write(temp_string); writer.flush(); writer.close(); log.info("替换模板"); String zipFilePath = System.getProperty("java.io.tmpdir") + File.separator + zipName + "zip"; ZipUtils.zip(dir, zipFilePath); File zipFile = new File(zipFilePath); // 以流的形式下载文件。 BufferedInputStream fis = new BufferedInputStream(new FileInputStream(zipFile.getPath())); byte[] buffer = new byte[fis.available()]; fis.read(buffer); fis.close(); response.reset(); OutputStream toClient = new BufferedOutputStream(response.getOutputStream()); response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment;filename=" + "client.zip"); toClient.write(buffer); toClient.flush(); toClient.close(); FileUtils.deleteDirectory(srcDir); zipFile.delete(); log.info("succeed"); }
Example 4
Source File: FrpController.java From frpMgr with MIT License | 4 votes |
@RequestMapping("/exportMac/{id}") public void exportMac(@PathVariable String id, HttpServletResponse response) throws IOException { Frp frp = frpService.get(id); FrpServer frpServer = frpServerService.get(String.valueOf(frp.getServerId())); // 源文件目录 String zipName = UUID.randomUUID().toString(); String dir = System.getProperty("java.io.tmpdir") + File.separator + zipName + File.separator; String dir_client = System.getProperty("java.io.tmpdir") + File.separator + zipName + File.separator + "client"; File srcDir = new File(dir_client); //拷贝到临时文件夹 JarFileUtil.BatCopyFileFromJar("static/frp/frp-client-mac", dir_client); //读取frpc.ini File temp_file = new File(dir_client + File.separator +"frpc.ini"); StringBuffer res = new StringBuffer(); String line = null; BufferedReader reader = new BufferedReader(new FileReader(temp_file)); while ((line = reader.readLine()) != null) { res.append(line + "\n"); } reader.close(); BufferedWriter writer = new BufferedWriter(new FileWriter(temp_file)); String temp_string = res.toString(); //替换模板 String projectName = frp.getProjectName(); String subdomain = frp.getFrpDomainSecond(); String localport = frp.getFrpLocalPort(); temp_string = temp_string.replaceAll("project_name", projectName); temp_string = temp_string.replaceAll("frp_subdomain", subdomain); temp_string = temp_string.replaceAll("frp_local_port", localport); temp_string = temp_string.replaceAll("frp_server_addr", frpServer.getServerIp()); writer.write(temp_string); writer.flush(); writer.close(); String zipFilePath = System.getProperty("java.io.tmpdir") + File.separator + zipName + "zip"; ZipUtils.zip(dir, zipFilePath); File zipFile = new File(zipFilePath); log.info("succeed"); // 以流的形式下载文件。 BufferedInputStream fis = new BufferedInputStream(new FileInputStream(zipFile.getPath())); byte[] buffer = new byte[fis.available()]; fis.read(buffer); fis.close(); response.reset(); OutputStream toClient = new BufferedOutputStream(response.getOutputStream()); response.setContentType("application/octet-stream"); response.setHeader("content-disposition", "attachment;filename=" + "client.zip"); toClient.write(buffer); toClient.flush(); toClient.close(); FileUtils.deleteDirectory(srcDir); zipFile.delete(); }
Example 5
Source File: FrpSSHController.java From frpMgr with MIT License | 4 votes |
@RequestMapping("/exportLinux/{id}") @ResponseBody public void exportWin(@PathVariable String id, HttpServletResponse response) throws IOException { Frp frp = frpService.get(id); FrpServer frpServer = frpServerService.get(String.valueOf(frp.getServerId())); //创建临时文件夹 String zipName = UUID.randomUUID().toString(); String dir = System.getProperty("java.io.tmpdir") + File.separator + zipName + File.separator; String dir_client = System.getProperty("java.io.tmpdir") + File.separator + zipName + File.separator + "client"; File srcDir = new File(dir_client); log.info("临时文件夹准备"); //拷贝到临时文件夹 JarFileUtil.BatCopyFileFromJar("static/frp/frp-client-linux", dir_client); log.info("拷贝到临时文件夹"); //读取frpc.ini File temp_file = new File(dir_client + File.separator +"frpc.ini"); StringBuffer res = new StringBuffer(); String line = null; BufferedReader reader = new BufferedReader(new FileReader(temp_file)); while ((line = reader.readLine()) != null) { res.append(line + "\n"); } reader.close(); log.info("读取文件"); BufferedWriter writer = new BufferedWriter(new FileWriter(temp_file)); String temp_string = res.toString(); //替换模板 String projectName = frp.getProjectName(); String remotePort = frp.getFrpRemotePort(); temp_string = temp_string.replaceAll("project_name", projectName); temp_string = temp_string.replaceAll("frp_remote_port", remotePort); temp_string = temp_string.replaceAll("frp_server_addr", frpServer.getServerIp()); writer.write(temp_string); writer.flush(); writer.close(); log.info("替换模板"); String zipFilePath = System.getProperty("java.io.tmpdir") + File.separator + zipName + "zip"; ZipUtils.zip(dir, zipFilePath); File zipFile = new File(zipFilePath); // 以流的形式下载文件。 BufferedInputStream fis = new BufferedInputStream(new FileInputStream(zipFile.getPath())); byte[] buffer = new byte[fis.available()]; fis.read(buffer); fis.close(); response.reset(); OutputStream toClient = new BufferedOutputStream(response.getOutputStream()); response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment;filename=" + "client.zip"); toClient.write(buffer); toClient.flush(); toClient.close(); FileUtils.deleteDirectory(srcDir); zipFile.delete(); log.info("succeed"); }
Example 6
Source File: FrpFileController.java From frpMgr with MIT License | 4 votes |
@RequestMapping("/exportFile/{id}") @ResponseBody public void exportFile(@PathVariable String id, HttpServletResponse response) throws IOException { Frp frp = frpService.get(id); FrpServer frpServer = frpServerService.get(String.valueOf(frp.getServerId())); //创建临时文件夹 String zipName = UUID.randomUUID().toString(); String dir = System.getProperty("java.io.tmpdir") + File.separator + zipName + File.separator; String dir_client = System.getProperty("java.io.tmpdir") + File.separator + zipName + File.separator + "client"; File srcDir = new File(dir_client); log.info("临时文件夹准备"); //拷贝到临时文件夹 JarFileUtil.BatCopyFileFromJar("static/frp/frp-client-file", dir_client); log.info("拷贝到临时文件夹"); // 创建文件夹 File folder = new File(dir_client + File.separator + "file"); folder.mkdir(); //读取frpc.ini File temp_file = new File(dir_client + File.separator +"frpc.ini"); StringBuffer res = new StringBuffer(); String line = null; BufferedReader reader = new BufferedReader(new FileReader(temp_file)); while ((line = reader.readLine()) != null) { res.append(line + "\n"); } reader.close(); log.info("读取文件"); BufferedWriter writer = new BufferedWriter(new FileWriter(temp_file)); String temp_string = res.toString(); //替换模板 String projectName = frp.getProjectName(); String remotePort = frp.getFrpRemotePort(); temp_string = temp_string.replaceAll("project_name", projectName); temp_string = temp_string.replaceAll("frp_remote_port", remotePort); temp_string = temp_string.replaceAll("frp_server_addr", frpServer.getServerIp()); // 设置访问密码 if (!StringUtils.isBlank(frp.getPassword())) { temp_string = temp_string.replaceAll("#plugin_http_user", "plugin_http_user=" + frp.getUser()); temp_string = temp_string.replaceAll("#plugin_http_passwd", "plugin_http_passwd=" + frp.getPassword()); } writer.write(temp_string); writer.flush(); writer.close(); log.info("替换模板"); String zipFilePath = System.getProperty("java.io.tmpdir") + File.separator + zipName + "zip"; ZipUtils.zip(dir, zipFilePath); File zipFile = new File(zipFilePath); // 以流的形式下载文件。 BufferedInputStream fis = new BufferedInputStream(new FileInputStream(zipFile.getPath())); byte[] buffer = new byte[fis.available()]; fis.read(buffer); fis.close(); response.reset(); OutputStream toClient = new BufferedOutputStream(response.getOutputStream()); response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment;filename=" + "client.zip"); toClient.write(buffer); toClient.flush(); toClient.close(); FileUtils.deleteDirectory(srcDir); zipFile.delete(); log.info("succeed"); }
Example 7
Source File: FrpRdpController.java From frpMgr with MIT License | 4 votes |
@RequestMapping("/exportRdp/{id}") @ResponseBody public void exportWin(@PathVariable String id, HttpServletResponse response) throws IOException { Frp frp = frpService.get(id); FrpServer frpServer = frpServerService.get(String.valueOf(frp.getServerId())); //创建临时文件夹 String zipName = UUID.randomUUID().toString(); String dir = System.getProperty("java.io.tmpdir") + File.separator + zipName + File.separator; String dir_client = System.getProperty("java.io.tmpdir") + File.separator + zipName + File.separator + "client"; File srcDir = new File(dir_client); log.info("临时文件夹准备"); //拷贝到临时文件夹 JarFileUtil.BatCopyFileFromJar("static/frp/frp-client-rdp", dir_client); log.info("拷贝到临时文件夹"); //读取frpc.ini File temp_file = new File(dir_client + File.separator +"frpc.ini"); StringBuffer res = new StringBuffer(); String line = null; BufferedReader reader = new BufferedReader(new FileReader(temp_file)); while ((line = reader.readLine()) != null) { res.append(line + "\n"); } reader.close(); log.info("读取文件"); BufferedWriter writer = new BufferedWriter(new FileWriter(temp_file)); String temp_string = res.toString(); //替换模板 String projectName = frp.getProjectName(); String remotePort = frp.getFrpRemotePort(); temp_string = temp_string.replaceAll("project_name", projectName); temp_string = temp_string.replaceAll("frp_remote_port", remotePort); temp_string = temp_string.replaceAll("frp_server_addr", frpServer.getServerIp()); writer.write(temp_string); writer.flush(); writer.close(); log.info("替换模板"); String zipFilePath = System.getProperty("java.io.tmpdir") + File.separator + zipName + "zip"; ZipUtils.zip(dir, zipFilePath); File zipFile = new File(zipFilePath); // 以流的形式下载文件。 BufferedInputStream fis = new BufferedInputStream(new FileInputStream(zipFile.getPath())); byte[] buffer = new byte[fis.available()]; fis.read(buffer); fis.close(); response.reset(); OutputStream toClient = new BufferedOutputStream(response.getOutputStream()); response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment;filename=" + "client.zip"); toClient.write(buffer); toClient.flush(); toClient.close(); FileUtils.deleteDirectory(srcDir); zipFile.delete(); log.info("succeed"); }
Example 8
Source File: TestVirtualContext.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
@Test public void testAdditionalWebInfClassesPaths() throws Exception { Tomcat tomcat = getTomcatInstance(); File appDir = new File("test/webapp-3.0-virtual-webapp/src/main/webapp"); // app dir is relative to server home StandardContext ctx = (StandardContext) tomcat.addWebapp(null, "/test", appDir.getAbsolutePath()); File tempFile = File.createTempFile("virtualWebInfClasses", null); File additionWebInfClasses = new File(tempFile.getAbsolutePath() + ".dir"); Assert.assertTrue(additionWebInfClasses.mkdirs()); File targetPackageForAnnotatedClass = new File(additionWebInfClasses, MyAnnotatedServlet.class.getPackage().getName().replace('.', '/')); Assert.assertTrue(targetPackageForAnnotatedClass.mkdirs()); InputStream annotatedServletClassInputStream = this.getClass().getResourceAsStream( MyAnnotatedServlet.class.getSimpleName() + ".class"); FileOutputStream annotatedServletClassOutputStream = new FileOutputStream(new File(targetPackageForAnnotatedClass, MyAnnotatedServlet.class.getSimpleName() + ".class")); IOUtils.copy(annotatedServletClassInputStream, annotatedServletClassOutputStream); annotatedServletClassInputStream.close(); annotatedServletClassOutputStream.close(); VirtualWebappLoader loader = new VirtualWebappLoader(ctx.getParentClassLoader()); loader.setVirtualClasspath("test/webapp-3.0-virtual-webapp/target/classes;" + // "test/webapp-3.0-virtual-library/target/classes;" + // additionWebInfClasses.getAbsolutePath()); ctx.setLoader(loader); tomcat.start(); // first test that without the setting on StandardContext the annotated // servlet is not detected assertPageContains("/test/annotatedServlet", MyAnnotatedServlet.MESSAGE, 404); tomcat.stop(); // then test that if we configure StandardContext with the additional // path, the servlet is detected // ctx.setAdditionalVirtualWebInfClasses(additionWebInfClasses.getAbsolutePath()); VirtualDirContext resources = new VirtualDirContext(); resources.setExtraResourcePaths("/WEB-INF/classes=" + additionWebInfClasses); ctx.setResources(resources); tomcat.start(); assertPageContains("/test/annotatedServlet", MyAnnotatedServlet.MESSAGE); tomcat.stop(); FileUtils.deleteDirectory(additionWebInfClasses); tempFile.delete(); }
Example 9
Source File: TestVirtualContext.java From Tomcat8-Source-Read with MIT License | 4 votes |
@Test public void testAdditionalWebInfClassesPaths() throws Exception { Tomcat tomcat = getTomcatInstance(); File appDir = new File("test/webapp-virtual-webapp/src/main/webapp"); // app dir is relative to server home StandardContext ctx = (StandardContext) tomcat.addWebapp(null, "/test", appDir.getAbsolutePath()); File tempFile = File.createTempFile("virtualWebInfClasses", null); File additionWebInfClasses = new File(tempFile.getAbsolutePath() + ".dir"); Assert.assertTrue(additionWebInfClasses.mkdirs()); File targetPackageForAnnotatedClass = new File(additionWebInfClasses, MyAnnotatedServlet.class.getPackage().getName().replace('.', '/')); Assert.assertTrue(targetPackageForAnnotatedClass.mkdirs()); try (InputStream annotatedServletClassInputStream = this.getClass().getResourceAsStream( MyAnnotatedServlet.class.getSimpleName() + ".class"); FileOutputStream annotatedServletClassOutputStream = new FileOutputStream(new File( targetPackageForAnnotatedClass, MyAnnotatedServlet.class.getSimpleName() + ".class"));) { IOUtils.copy(annotatedServletClassInputStream, annotatedServletClassOutputStream); } ctx.setResources(new StandardRoot(ctx)); File f1 = new File("test/webapp-virtual-webapp/target/classes"); File f2 = new File("test/webapp-virtual-library/target/WEB-INF/classes"); ctx.getResources().createWebResourceSet( WebResourceRoot.ResourceSetType.POST, "/WEB-INF/classes", f1.getAbsolutePath(), null, "/"); ctx.getResources().createWebResourceSet( WebResourceRoot.ResourceSetType.POST, "/WEB-INF/classes", f2.getAbsolutePath(), null, "/"); tomcat.start(); // first test that without the setting on StandardContext the annotated // servlet is not detected assertPageContains("/test/annotatedServlet", MyAnnotatedServlet.MESSAGE, 404); tomcat.stop(); // then test that if we configure StandardContext with the additional // path, the servlet is detected ctx.setResources(new StandardRoot(ctx)); ctx.getResources().createWebResourceSet( WebResourceRoot.ResourceSetType.POST, "/WEB-INF/classes", f1.getAbsolutePath(), null, "/"); ctx.getResources().createWebResourceSet( WebResourceRoot.ResourceSetType.POST, "/WEB-INF/classes", f2.getAbsolutePath(), null, "/"); ctx.getResources().createWebResourceSet( WebResourceRoot.ResourceSetType.POST, "/WEB-INF/classes", additionWebInfClasses.getAbsolutePath(), null, "/"); tomcat.start(); assertPageContains("/test/annotatedServlet", MyAnnotatedServlet.MESSAGE); tomcat.stop(); FileUtils.deleteDirectory(additionWebInfClasses); Assert.assertTrue("Failed to clean up [" + tempFile + "]", tempFile.delete()); }
Example 10
Source File: FileBrowserServiceTest.java From citrus-admin with Apache License 2.0 | 4 votes |
@AfterTest public void cleanup() throws Exception { FileUtils.deleteDirectory(tmpDir); tmpDir.delete(); }
Example 11
Source File: DeleteLocalRepositoryAdapter.java From coderadar with MIT License | 4 votes |
private void deleteDir(String path) throws IOException { FileUtils.deleteDirectory(new File(path)); }
Example 12
Source File: CloneRepositoryAdapterTest.java From coderadar with MIT License | 4 votes |
@AfterEach public void tearDown() throws IOException { FileUtils.deleteDirectory(folder); }
Example 13
Source File: ComputeContributorAdapterTest.java From coderadar with MIT License | 4 votes |
@AfterEach public void tearDown() throws IOException { FileUtils.deleteDirectory(folder); }
Example 14
Source File: ControllerTestTemplate.java From coderadar with MIT License | 4 votes |
@AfterAll static void cleanUp() throws IOException { FileUtils.deleteDirectory(new File("coderadar-workdir/projects")); }
Example 15
Source File: TestWebappClassLoaderWeaving.java From Tomcat7.0.67 with Apache License 2.0 | 2 votes |
@AfterClass public static void tearDownClass() throws Exception { FileUtils.deleteDirectory(new File(WEBAPP_DOC_BASE)); }
Example 16
Source File: TestWebappClassLoaderWeaving.java From tomcatsrc with Apache License 2.0 | 2 votes |
@AfterClass public static void tearDownClass() throws Exception { FileUtils.deleteDirectory(new File(WEBAPP_DOC_BASE)); }
Example 17
Source File: TestWebappClassLoaderWeaving.java From Tomcat8-Source-Read with MIT License | 2 votes |
@AfterClass public static void tearDownClass() throws Exception { FileUtils.deleteDirectory(new File(WEBAPP_DOC_BASE)); }