code cleanup, fix for ReplaceInputStream
[nikiroo-utils.git] / src / be / nikiroo / utils / IOUtils.java
index 9cdaba840af79727fba495b2095af03cf5918c2f..fa18d0de5c868f411d2d7da88e2cf39fd0e47f23 100644 (file)
@@ -13,6 +13,8 @@ import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 import java.util.zip.ZipOutputStream;
 
+import be.nikiroo.utils.streams.MarkableFileInputStream;
+
 /**
  * This class offer some utilities based around Streams and Files.
  * 
@@ -54,7 +56,7 @@ public class IOUtils {
                        throws IOException {
                byte buffer[] = new byte[4096];
                int len = in.read(buffer);
-               while (len > 0) {
+               while (len > -1) {
                        out.write(buffer, 0, len);
                        len = in.read(buffer);
                }
@@ -408,19 +410,11 @@ public class IOUtils {
                        write(in, tmp);
                        in.close();
 
-                       final FileInputStream fis = new FileInputStream(tmp);
-                       return new MarkableFileInputStream(fis) {
+                       return new MarkableFileInputStream(tmp) {
                                @Override
                                public void close() throws IOException {
                                        try {
-                                               try {
-                                                       super.close();
-                                               } finally {
-                                                       try {
-                                                               fis.close();
-                                                       } catch (IOException e) {
-                                                       }
-                                               }
+                                               super.close();
                                        } finally {
                                                tmp.delete();
                                        }