X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2FIOUtils.java;h=e9a378c0fd6e279c1568afb848808ab83f9cdf5e;hb=refs%2Ftags%2Fnikiroo-utils-4.4.5;hp=3e2f6e761481fbf7c0e741539c7f811dbf272daa;hpb=4110f63bcffb5112677fad45a6952314bde713df;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/IOUtils.java b/src/be/nikiroo/utils/IOUtils.java index 3e2f6e7..e9a378c 100644 --- a/src/be/nikiroo/utils/IOUtils.java +++ b/src/be/nikiroo/utils/IOUtils.java @@ -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(); + } + } }