Skip to content
Snippets Groups Projects
Commit ed3d9ead authored by Nelson Tavares de Sousa's avatar Nelson Tavares de Sousa
Browse files

fixed bug #59 in ByteArrayFileWriter

parent 8e17fafe
No related branches found
No related tags found
No related merge requests found
...@@ -11,11 +11,13 @@ import com.google.common.io.Files; ...@@ -11,11 +11,13 @@ import com.google.common.io.Files;
public class ByteArrayFileWriter extends ConsumerStage<byte[]> { public class ByteArrayFileWriter extends ConsumerStage<byte[]> {
private final File file; private final File file;
private FileOutputStream fo;
public ByteArrayFileWriter(final File file) { public ByteArrayFileWriter(final File file) {
this.file = file; this.file = file;
try { try {
Files.touch(file); Files.touch(file);
fo = new FileOutputStream(this.file);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -23,13 +25,20 @@ public class ByteArrayFileWriter extends ConsumerStage<byte[]> { ...@@ -23,13 +25,20 @@ public class ByteArrayFileWriter extends ConsumerStage<byte[]> {
@Override @Override
protected void execute(final byte[] element) { protected void execute(final byte[] element) {
FileOutputStream fo;
try { try {
fo = new FileOutputStream(this.file);
fo.write(element); fo.write(element);
fo.close();
} catch (Exception e) { } catch (Exception e) {
throw new IllegalStateException(e); throw new IllegalStateException(e);
} }
} }
@Override
public void onTerminating() {
try {
fo.close();
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment