org.apache.tomcat.util.http.fileupload.FileUtils Java Examples
The following examples show how to use
org.apache.tomcat.util.http.fileupload.FileUtils.
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: UpdateLocalRepositoryAdapter.java From coderadar with MIT License | 5 votes |
private void deleteAndCloneRepository(UpdateRepositoryCommand command) throws UnableToCloneRepositoryException, IOException { File localDir = new File(command.getLocalDir()); if (localDir.exists()) { FileUtils.forceDelete(localDir); } cloneRepositoryAdapter.cloneRepository( new CloneRepositoryCommand( command.getRemoteUrl(), command.getLocalDir(), command.getUsername(), command.getPassword())); }
Example #3
Source File: CleanerRunner.java From ogham with Apache License 2.0 | 5 votes |
@Override public void run(ApplicationArguments args) throws Exception { boolean override = args.getOptionValues("override")!=null; if(!override) { return; } Path parentFolder = Paths.get(args.getNonOptionArgs().get(0)); log.info("Cleaning {}", parentFolder); Files.createDirectories(parentFolder); FileUtils.cleanDirectory(parentFolder.toFile()); }
Example #4
Source File: TestConfigFileLoader.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Test public void testAbsolutePath() throws IOException { File test = new File(System.getProperty("java.io.tmpdir"), "testAbsolutePath"); if (test.exists()) { FileUtils.forceDelete(test); } test.createNewFile(); doTest(test.getAbsolutePath()); }
Example #5
Source File: TestConfigFileLoader.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Test public void testAbsolutePath() throws IOException { File test = new File(System.getProperty("java.io.tmpdir"), "testAbsolutePath"); if (test.exists()) { FileUtils.forceDelete(test); } test.createNewFile(); doTest(test.getAbsolutePath()); }
Example #6
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 #7
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 #8
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 #9
Source File: ComputeContributorAdapterTest.java From coderadar with MIT License | 4 votes |
@AfterEach public void tearDown() throws IOException { FileUtils.deleteDirectory(folder); }
Example #10
Source File: CloneRepositoryAdapterTest.java From coderadar with MIT License | 4 votes |
@AfterEach public void tearDown() throws IOException { FileUtils.deleteDirectory(folder); }
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: FileBrowserServiceTest.java From citrus-admin with Apache License 2.0 | 4 votes |
@AfterTest public void cleanup() throws Exception { FileUtils.deleteDirectory(tmpDir); tmpDir.delete(); }
Example #13
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 #14
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 #15
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 #16
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 #17
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 #18
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 #19
Source File: AccessLogConfigTest.java From micro-server with Apache License 2.0 | 3 votes |
@Before public void startServer() throws InterruptedException, IOException { logFile = new File(System.getProperty("user.home") + "/access-log-app-access.log"); FileUtils.forceDelete(logFile); assertThat(logFile.exists(), is(false)); server = new MicroserverApp(() -> "access-log-app"); Thread.sleep(1000); server.start(); }
Example #20
Source File: AccessLogConfigTest.java From micro-server with Apache License 2.0 | 3 votes |
@Before public void startServer() throws IOException { logFile = new File(System.getProperty("user.home") + "/access-log-app-access.log"); FileUtils.forceDelete(logFile); System.out.println(logFile.exists()); assertThat(logFile.exists(), is(false)); server = new MicroserverApp(() -> "access-log-app"); server.start(); }
Example #21
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 #22
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 #23
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)); }