package com.holmsted.file;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;

public class FileWriter {

    public static void writeFile(String filename, String contents) {
        File dataFile = new File(filename);
        FileOutputStream outputStream;
        try {
            outputStream = new FileOutputStream(dataFile);
            Writer writer = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
            writer.write(contents);
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void writeFile(String filename, InputStream inputStream) {
        File dataFile = new File(filename);
        FileOutputStream outputStream;
        try {
            outputStream = new FileOutputStream(dataFile);
            byte[] buffer = new byte[4096];
            int readBytes;
            while ((readBytes = inputStream.read(buffer)) > 0) {
                outputStream.write(buffer, 0, readBytes);
            }
            outputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

@@ -221,16 +221,50 @@
 riter;%0A%0A
+import javax.annotation.Nonnull;%0A%0A
 public c
@@ -387,32 +387,66 @@
 File(filename);%0A
+        mkdirsForFile(dataFile);%0A%0A
         FileOutp
@@ -897,32 +897,66 @@
 File(filename);%0A
+        mkdirsForFile(dataFile);%0A%0A
         FileOutp
@@ -1319,32 +1319,32 @@
 OException e) %7B%0A
-
             e.pr
@@ -1375,11 +1375,334 @@
  %7D%0A    %7D
+%0A%0A    private static void mkdirsForFile(@Nonnull File file) %7B%0A        File path = new File(file.getParent());%0A        if (!path.exists() && !path.mkdirs()) %7B%0A            throw new IllegalArgumentException(%0A                    %22Path did not exist and could not be created: '%22 + path.getAbsolutePath() + %22'%22);%0A        %7D%0A    %7D
 %0A%7D%0A

Create directories for output if they don't already exist