1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-17 22:23:10 +03:00

Closing streams using IOUtils.closeQuietly

Fixed badly handled stream found in the meanwhile
This commit is contained in:
Federico Fissore
2015-05-21 16:47:50 +02:00
parent a5ad02f818
commit 365b0bdc94
26 changed files with 112 additions and 192 deletions

View File

@ -1,5 +1,7 @@
package processing.app.legacy;
import org.apache.commons.compress.utils.IOUtils;
import java.io.*;
import java.text.NumberFormat;
import java.util.ArrayList;
@ -272,13 +274,7 @@ public class PApplet {
if (is != null) return loadStrings(is);
return null;
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
// noop
}
}
IOUtils.closeQuietly(is);
}
}
@ -312,14 +308,7 @@ public class PApplet {
e.printStackTrace();
//throw new RuntimeException("Error inside loadStrings()");
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
//ignore
}
}
IOUtils.closeQuietly(reader);
}
return null;
}
@ -335,27 +324,25 @@ public class PApplet {
outputStream = createOutput(file);
saveStrings(outputStream, strings);
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
//noop
}
}
IOUtils.closeQuietly(outputStream);
}
}
static public void saveStrings(OutputStream output, String strings[]) {
PrintWriter writer = createWriter(output);
if (writer == null) {
return;
PrintWriter writer = null;
try {
writer = createWriter(output);
if (writer == null) {
return;
}
for (String string : strings) {
writer.println(string);
}
writer.flush();
} finally {
IOUtils.closeQuietly(writer);
}
for (String string : strings) {
writer.println(string);
}
writer.flush();
writer.close();
}