Version 4.4.5
[nikiroo-utils.git] / src / be / nikiroo / utils / IOUtils.java
index 3e2f6e761481fbf7c0e741539c7f811dbf272daa..e9a378c0fd6e279c1568afb848808ab83f9cdf5e 100644 (file)
@@ -17,7 +17,7 @@ import java.util.zip.ZipInputStream;
 import java.util.zip.ZipOutputStream;
 
 /**
- * This class offer some utilities based around Streams.
+ * This class offer some utilities based around Streams and Files.
  * 
  * @author niki
  */
@@ -213,7 +213,23 @@ public class IOUtils {
                        dir.mkdirs();
                }
 
-               FileWriter writerVersion = new FileWriter(new File(dir, filename));
+               writeSmallFile(new File(dir, filename), content);
+       }
+
+       /**
+        * Write the {@link String} content to {@link File}.
+        * 
+        * @param file
+        *            the {@link File} to write
+        * @param content
+        *            the content
+        * 
+        * @throws IOException
+        *             in case of I/O error
+        */
+       public static void writeSmallFile(File file, String content)
+                       throws IOException {
+               FileWriter writerVersion = new FileWriter(file);
                try {
                        writerVersion.write(content);
                } finally {
@@ -432,4 +448,24 @@ public class IOUtils {
 
                return array;
        }
+
+       /**
+        * Convert the {@link File} into a byte array.
+        * 
+        * @param file
+        *            the input {@link File}
+        * 
+        * @return the array
+        * 
+        * @throws IOException
+        *             in case of I/O error
+        */
+       public static byte[] toByteArray(File file) throws IOException {
+               FileInputStream fis = new FileInputStream(file);
+               try {
+                       return toByteArray(fis);
+               } finally {
+                       fis.close();
+               }
+       }
 }