1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-19 13:54:23 +01:00

Simplified overly complicated error handling in PApplet.createWriter

This commit is contained in:
Cristian Maglie 2018-08-10 20:09:01 +02:00 committed by Cristian Maglie
parent 9eeb79fed4
commit 2f6d2112cf

View File

@ -552,23 +552,20 @@ public class PApplet {
/**
* I want to print lines to a file. I have RSI from typing these
* eight lines of code so many times.
* @throws IOException
*/
static public PrintWriter createWriter(File file) {
static public PrintWriter createWriter(File file) throws IOException {
createPath(file); // make sure in-between folders exist
OutputStream output = new FileOutputStream(file);
try {
createPath(file); // make sure in-between folders exist
OutputStream output = new FileOutputStream(file);
if (file.getName().toLowerCase().endsWith(".gz")) {
output = new GZIPOutputStream(output);
}
return createWriter(output);
} catch (Exception e) {
if (file == null) {
throw new RuntimeException("File passed to createWriter() was null");
} else {
throw new RuntimeException("Couldn't create a writer for " + file.getAbsolutePath(), e);
}
} catch (IOException e) {
output.close();
throw e;
}
return createWriter(output);
}