You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Sebb (Jira)" <ji...@apache.org> on 2020/08/10 15:23:00 UTC
[jira] [Commented] (IO-609) FileUtils.copyToFile backward
incompatibility bug
[ https://issues.apache.org/jira/browse/IO-609?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17174388#comment-17174388 ]
Sebb commented on IO-609:
-------------------------
Sorry, but the sample test case requires far too much work to get it to run on anyone's system apart from your own.
It also includes lots of code which is not relevant to the bug report.
Also the line which throws the IOError is not identified.
Please provide the simplest possible test case that shows the issue, along with any test data that is needed (e.g. test.zip in this case)
> 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.3.4#803005)