Permalink
Browse files

Issue #21

Write to a ByteArrayOutputStream instead of a FileOutputStream, which lets us store the results of the tool in memory until we've succeeded (the finally block) before writing to disk using a FileOutputStream.
  • Loading branch information...
1 parent 7909b49 commit 6e6e48d409e602127a710a0be970355cfb9cbabf @tivac tivac committed Apr 18, 2011
Showing with 4 additions and 1 deletion.
  1. +4 −1 src/net/nczonline/web/cssembed/CSSEmbed.java
@@ -29,6 +29,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
+import java.io.ByteArrayOutputStream;
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.Charset;
@@ -46,6 +47,7 @@ public static void main(String[] args) {
boolean verbose = false;
String charset = null;
String outputFilename = null;
+ ByteArrayOutputStream bytes = new ByteArrayOutputStream();
Writer out = null;
Reader in = null;
String root;
@@ -154,7 +156,7 @@ public static void main(String[] args) {
System.err.println("[INFO] Output file is '" + outputFile.getAbsolutePath() + "'");
}
embedder.setFilename(outputFile.getName());
- out = new OutputStreamWriter(new FileOutputStream(outputFilename), charset);
+ out = new OutputStreamWriter(bytes, charset);
}
//set verbose option
@@ -173,6 +175,7 @@ public static void main(String[] args) {
if (out != null) {
try {
out.close();
+ bytes.writeTo(new FileOutputStream(outputFilename));
} catch (IOException e) {
System.err.println("[ERROR] " + e.getMessage());
if (verbose){

0 comments on commit 6e6e48d

Please sign in to comment.