[ https://issues.apache.org/jira/browse/IO-609?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gary D. Gregory closed IO-609. ------------------------------ Resolution: Cannot Reproduce > FileUtils.copyToFile backward incompatibility bug > ------------------------------------------------- > > Key: IO-609 > URL: https://issues.apache.org/jira/browse/IO-609 > Project: Commons IO > Issue Type: Bug > Affects Versions: 2.6 > Reporter: xia0c > Priority: Major > > Hi, > The following code snippets throw an IOException: Stream closed. It works > well before commons-io 2.6. When I update commons-io to 2.6, it failed. There > is a backward incompatibility bug behind it. > The function code: > {code:java} > public class Demo { > private void backupFile(String srcPath, String entryPath, > ZipOutputStream stream) throws IOException { > ZipEntry zipEntry = new ZipEntry(entryPath); > stream.putNextEntry(zipEntry); > Files.copy(Paths.get(srcPath), stream); > } > private void backupDir(String srcDir, String dstDir, ZipOutputStream > stream) throws IOException { > File dir = new File(srcDir); > for (String path : dir.list()) { > System.out.println(path); > backupFile(dir.getAbsolutePath() + File.separator + path, > dstDir + File.separator + path, stream); > } > } > public void backup(String name) throws IOException { > > Files.createDirectories(Paths.get("/Users/chenlingchao/eclipse_projects/workspace/BBI.BugDetection")); > ZipOutputStream stream = new ZipOutputStream( > > Files.newOutputStream(Paths.get("/Users/chenlingchao/eclipse_projects/workspace/BBI.BugDetection/tmp" > + File.separator + name))); > try { > > backupDir("/Users/chenlingchao/eclipse_projects/workspace/BBI.BugDetection/tmp", > "meta" + File.separator + "tables", stream); > stream.closeEntry(); > } finally { > stream.close(); > } > } > > public void restore(String name) throws IOException { > ZipInputStream stream = new ZipInputStream( > > Files.newInputStream(Paths.get("/Users/chenlingchao/eclipse_projects/workspace/BBI.BugDetection/tmp" > + File.separator + name))); > try { > ZipEntry entry; > while ((entry = stream.getNextEntry()) != null) { > FileUtils.copyToFile(stream, new > File("/Users/chenlingchao/eclipse_projects/workspace/BBI.BugDetection/tmp" + > File.separator + entry.getName())); > } > } finally { > stream.close(); > } > } > } > {code} > The test code: > {code:java} > @Test > public void TestDemo() throws IOException{ > Demo test = new Demo(); > test.backup("test.zip"); > test.restore("test.zip"); > } > > {code} -- This message was sent by Atlassian Jira (v8.20.7#820007)