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

@ -39,6 +39,7 @@ import cc.arduino.view.Event;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.collect.Collections2; import com.google.common.collect.Collections2;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import processing.app.debug.TargetBoard; import processing.app.debug.TargetBoard;
import processing.app.debug.TargetPackage; import processing.app.debug.TargetPackage;
@ -2517,9 +2518,7 @@ public class Base {
} }
return buffer; return buffer;
} finally { } finally {
if (input != null) { IOUtils.closeQuietly(input);
input.close();
}
} }
} }
@ -2567,12 +2566,8 @@ public class Base {
} }
to.flush(); to.flush();
} finally { } finally {
if (from != null) { IOUtils.closeQuietly(from);
from.close(); // ?? IOUtils.closeQuietly(to);
}
if (to != null) {
to.close(); // ??
}
} }
targetFile.setLastModified(sourceFile.lastModified()); targetFile.setLastModified(sourceFile.lastModified());

View File

@ -28,6 +28,7 @@ import cc.arduino.view.StubMenuListener;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.jcraft.jsch.JSchException; import com.jcraft.jsch.JSchException;
import jssc.SerialPortException; import jssc.SerialPortException;
import org.apache.commons.compress.utils.IOUtils;
import processing.app.debug.*; import processing.app.debug.*;
import processing.app.forms.PasswordAuthorizationDialog; import processing.app.forms.PasswordAuthorizationDialog;
import processing.app.helpers.OSUtils; import processing.app.helpers.OSUtils;
@ -965,11 +966,7 @@ public class Editor extends JFrame implements RunnerListener {
//System.err.println("Ignoring " + filename + " (" + e.getMessage() + ")"); //System.err.println("Ignoring " + filename + " (" + e.getMessage() + ")");
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if (zipFile != null) IOUtils.closeQuietly(zipFile);
try {
zipFile.close();
} catch (IOException e) {
}
} }
return null; return null;
} }

View File

@ -1,6 +1,7 @@
package processing.app; package processing.app;
import cc.arduino.files.DeleteFilesOnShutdown; import cc.arduino.files.DeleteFilesOnShutdown;
import org.apache.commons.compress.utils.IOUtils;
import static processing.app.I18n._; import static processing.app.I18n._;
@ -82,17 +83,13 @@ class EditorConsoleStream extends OutputStream {
System.setErr(systemErr); System.setErr(systemErr);
// close the PrintStream // close the PrintStream
consoleOut.close(); IOUtils.closeQuietly(consoleOut);
consoleErr.close(); IOUtils.closeQuietly(consoleErr);
// also have to close the original FileOutputStream // also have to close the original FileOutputStream
// otherwise it won't be shut down completely // otherwise it won't be shut down completely
try { IOUtils.closeQuietly(stdoutFile);
stdoutFile.close(); IOUtils.closeQuietly(stderrFile);
stderrFile.close();
} catch (IOException e) {
e.printStackTrace();
}
outFile.delete(); outFile.delete();
errFile.delete(); errFile.delete();

View File

@ -22,6 +22,7 @@
package processing.app; package processing.app;
import org.apache.commons.compress.utils.IOUtils;
import processing.app.legacy.PApplet; import processing.app.legacy.PApplet;
import javax.swing.*; import javax.swing.*;
@ -133,9 +134,7 @@ public class UpdateCheck implements Runnable {
reader = new BufferedReader(new InputStreamReader(url.openStream())); reader = new BufferedReader(new InputStreamReader(url.openStream()));
return Integer.parseInt(reader.readLine()); return Integer.parseInt(reader.readLine());
} finally { } finally {
if (reader != null) { IOUtils.closeQuietly(reader);
reader.close();
}
} }
} }
} }

View File

@ -25,6 +25,7 @@
package processing.app.syntax; package processing.app.syntax;
import cc.arduino.contributions.libraries.ContributedLibrary; import cc.arduino.contributions.libraries.ContributedLibrary;
import org.apache.commons.compress.utils.IOUtils;
import org.fife.ui.rsyntaxtextarea.TokenMap; import org.fife.ui.rsyntaxtextarea.TokenMap;
import org.fife.ui.rsyntaxtextarea.TokenTypes; import org.fife.ui.rsyntaxtextarea.TokenTypes;
import processing.app.Base; import processing.app.Base;
@ -126,9 +127,7 @@ public class PdeKeywords {
fillMissingTokenType(); fillMissingTokenType();
} finally { } finally {
if (reader != null) { IOUtils.closeQuietly(reader);
reader.close();
}
} }
} }

View File

@ -30,6 +30,7 @@
package processing.app.syntax; package processing.app.syntax;
import org.apache.commons.compress.utils.IOUtils;
import org.fife.ui.rsyntaxtextarea.*; import org.fife.ui.rsyntaxtextarea.*;
import org.fife.ui.rsyntaxtextarea.Theme; import org.fife.ui.rsyntaxtextarea.Theme;
import org.fife.ui.rsyntaxtextarea.Token; import org.fife.ui.rsyntaxtextarea.Token;
@ -102,9 +103,7 @@ public class SketchTextArea extends RSyntaxTextArea {
Theme theme = Theme.load(defaultXmlInputStream); Theme theme = Theme.load(defaultXmlInputStream);
theme.apply(this); theme.apply(this);
} finally { } finally {
if (defaultXmlInputStream != null) { IOUtils.closeQuietly(defaultXmlInputStream);
defaultXmlInputStream.close();
}
} }
setForeground(processing.app.Theme.getColor("editor.fgcolor")); setForeground(processing.app.Theme.getColor("editor.fgcolor"));

View File

@ -23,6 +23,7 @@
package processing.app.tools; package processing.app.tools;
import org.apache.commons.compress.utils.IOUtils;
import processing.app.Base; import processing.app.Base;
import processing.app.Editor; import processing.app.Editor;
import processing.app.Sketch; import processing.app.Sketch;
@ -124,22 +125,21 @@ public class Archiver implements Tool {
if (filename != null) { if (filename != null) {
newbie = new File(directory, filename); newbie = new File(directory, filename);
ZipOutputStream zos = null;
try { try {
//System.out.println(newbie); //System.out.println(newbie);
FileOutputStream zipOutputFile = new FileOutputStream(newbie); zos = new ZipOutputStream(new FileOutputStream(newbie));
ZipOutputStream zos = new ZipOutputStream(zipOutputFile);
// recursively fill the zip file // recursively fill the zip file
buildZip(location, name, zos); buildZip(location, name, zos);
// close up the jar file // close up the jar file
zos.flush(); zos.flush();
zos.close();
editor.statusNotice("Created archive " + newbie.getName() + "."); editor.statusNotice("Created archive " + newbie.getName() + ".");
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally {
IOUtils.closeQuietly(zos);
} }
} else { } else {
editor.statusNotice(_("Archive sketch canceled.")); editor.statusNotice(_("Archive sketch canceled."));

View File

@ -29,6 +29,7 @@ import java.io.IOException;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import org.apache.commons.compress.utils.IOUtils;
import processing.app.*; import processing.app.*;
import static processing.app.I18n._; import static processing.app.I18n._;
@ -83,16 +84,19 @@ public class FixEncoding implements Tool {
protected String loadWithLocalEncoding(File file) throws IOException { protected String loadWithLocalEncoding(File file) throws IOException {
// FileReader uses the default encoding, which is what we want. // FileReader uses the default encoding, which is what we want.
FileReader fr = new FileReader(file); BufferedReader reader = null;
BufferedReader reader = new BufferedReader(fr); try {
reader = new BufferedReader(new FileReader(file));
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
String line = null; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
buffer.append(line); buffer.append(line);
buffer.append('\n'); buffer.append('\n');
} }
reader.close();
return buffer.toString(); return buffer.toString();
} finally {
IOUtils.closeQuietly(reader);
}
} }
} }

View File

@ -10,6 +10,7 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipException; import java.util.zip.ZipException;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import org.apache.commons.compress.utils.IOUtils;
import processing.app.helpers.FileUtils; import processing.app.helpers.FileUtils;
public class ZipDeflater { public class ZipDeflater {
@ -54,12 +55,8 @@ public class ZipDeflater {
fos.write(buffer, 0, len); fos.write(buffer, 0, len);
} }
} finally { } finally {
if (fos != null) { IOUtils.closeQuietly(fos);
fos.close(); IOUtils.closeQuietly(zipInputStream);
}
if (zipInputStream != null) {
zipInputStream.close();
}
} }
} }
} }

View File

@ -29,6 +29,7 @@
package processing.app; package processing.app;
import org.apache.commons.compress.utils.IOUtils;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
@ -63,9 +64,7 @@ public class I18NTest {
is = new FileInputStream(file); is = new FileInputStream(file);
properties.load(is); properties.load(is);
} finally { } finally {
if (is != null) { IOUtils.closeQuietly(is);
is.close();
}
} }
return properties; return properties;
} }

View File

@ -77,12 +77,8 @@ public class GPGDetachedSignatureVerifier {
return pgpSignature.verify(); return pgpSignature.verify();
} finally { } finally {
if (signatureInputStream != null) { IOUtils.closeQuietly(signatureInputStream);
signatureInputStream.close(); IOUtils.closeQuietly(signedFileInputStream);
}
if (signedFileInputStream != null) {
signedFileInputStream.close();
}
} }
} }
@ -92,9 +88,7 @@ public class GPGDetachedSignatureVerifier {
keyIn = new BufferedInputStream(new FileInputStream(file)); keyIn = new BufferedInputStream(new FileInputStream(file));
return readPublicKey(keyIn, keyId); return readPublicKey(keyIn, keyId);
} finally { } finally {
if (keyIn != null) { IOUtils.closeQuietly(keyIn);
keyIn.close();
}
} }
} }

View File

@ -37,6 +37,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.mrbean.MrBeanModule; import com.fasterxml.jackson.module.mrbean.MrBeanModule;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.FluentIterable; import com.google.common.collect.FluentIterable;
import org.apache.commons.compress.utils.IOUtils;
import processing.app.BaseNoGui; import processing.app.BaseNoGui;
import processing.app.I18n; import processing.app.I18n;
import processing.app.helpers.FileUtils; import processing.app.helpers.FileUtils;
@ -96,9 +97,7 @@ public class LibrariesIndexer {
} }
} }
} finally { } finally {
if (indexIn != null) { IOUtils.closeQuietly(indexIn);
indexIn.close();
}
} }
} }

View File

@ -44,6 +44,7 @@ import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Multimaps; import com.google.common.collect.Multimaps;
import org.apache.commons.compress.utils.IOUtils;
import processing.app.BaseNoGui; import processing.app.BaseNoGui;
import processing.app.debug.TargetPackage; import processing.app.debug.TargetPackage;
import processing.app.debug.TargetPlatform; import processing.app.debug.TargetPlatform;
@ -172,9 +173,7 @@ public class ContributionsIndexer {
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return mapper.readValue(inputStream, ContributionsIndex.class); return mapper.readValue(inputStream, ContributionsIndex.class);
} finally { } finally {
if (inputStream != null) { IOUtils.closeQuietly(inputStream);
inputStream.close();
}
} }
} }

View File

@ -33,6 +33,7 @@ import cc.arduino.packages.BoardPort;
import cc.arduino.packages.Discovery; import cc.arduino.packages.Discovery;
import cc.arduino.packages.discoverers.network.BoardReachabilityFilter; import cc.arduino.packages.discoverers.network.BoardReachabilityFilter;
import cc.arduino.packages.discoverers.network.NetworkChecker; import cc.arduino.packages.discoverers.network.NetworkChecker;
import org.apache.commons.compress.utils.IOUtils;
import processing.app.BaseNoGui; import processing.app.BaseNoGui;
import processing.app.helpers.PreferencesMap; import processing.app.helpers.PreferencesMap;
import processing.app.zeroconf.jmdns.ArduinoDNSTaskStarter; import processing.app.zeroconf.jmdns.ArduinoDNSTaskStarter;
@ -199,12 +200,6 @@ public class NetworkDiscovery implements Discovery, ServiceListener, cc.arduino.
@Override @Override
public void inetAddressRemoved(InetAddress address) { public void inetAddressRemoved(InetAddress address) {
JmDNS jmDNS = mappedJmDNSs.remove(address); JmDNS jmDNS = mappedJmDNSs.remove(address);
if (jmDNS != null) { IOUtils.closeQuietly(jmDNS);
try {
jmDNS.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} }
} }

View File

@ -32,6 +32,7 @@ package cc.arduino.packages.ssh;
import com.jcraft.jsch.Channel; import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelExec; import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.Session; import com.jcraft.jsch.Session;
import org.apache.commons.compress.utils.IOUtils;
import java.io.*; import java.io.*;
@ -61,12 +62,8 @@ public class SCP extends SSH {
} }
public void close() throws IOException { public void close() throws IOException {
if (out != null) { IOUtils.closeQuietly(out);
out.close(); IOUtils.closeQuietly(in);
}
if (in != null) {
in.close();
}
if (channel != null) { if (channel != null) {
channel.disconnect(); channel.disconnect();
} }
@ -118,9 +115,7 @@ public class SCP extends SSH {
buf[0] = 0; buf[0] = 0;
out.write(buf, 0, 1); out.write(buf, 0, 1);
} finally { } finally {
if (fis != null) { IOUtils.closeQuietly(fis);
fis.close();
}
} }
ensureAcknowledged(); ensureAcknowledged();

View File

@ -33,6 +33,7 @@ import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelExec; import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSchException; import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session; import com.jcraft.jsch.Session;
import org.apache.commons.compress.utils.IOUtils;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -70,12 +71,8 @@ public class SSH {
return exitCode == 0; return exitCode == 0;
} finally { } finally {
if (stdout != null) { IOUtils.closeQuietly(stdout);
stdout.close(); IOUtils.closeQuietly(stderr);
}
if (stderr != null) {
stderr.close();
}
if (channel != null) { if (channel != null) {
channel.disconnect(); channel.disconnect();
} }

View File

@ -35,6 +35,7 @@ import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
import org.apache.commons.compress.utils.IOUtils;
import processing.app.I18n; import processing.app.I18n;
import processing.app.Platform; import processing.app.Platform;
@ -258,9 +259,7 @@ public class ArchiveExtractor {
} }
} finally { } finally {
if (in != null) { IOUtils.closeQuietly(in);
in.close();
}
} }
// Set folders timestamps // Set folders timestamps
@ -294,9 +293,7 @@ public class ArchiveExtractor {
size -= length; size -= length;
} }
} finally { } finally {
if (fos != null) { IOUtils.closeQuietly(fos);
fos.close();
}
} }
} }

View File

@ -28,6 +28,8 @@
*/ */
package cc.arduino.utils; package cc.arduino.utils;
import org.apache.commons.compress.utils.IOUtils;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
@ -68,9 +70,7 @@ public class FileHash {
} }
return algorithm + ":" + res; return algorithm + ":" + res;
} finally { } finally {
if (in != null) { IOUtils.closeQuietly(in);
in.close();
}
} }
} }
} }

View File

@ -29,6 +29,7 @@
package cc.arduino.utils.network; package cc.arduino.utils.network;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.commons.compress.utils.IOUtils;
import processing.app.PreferencesData; import processing.app.PreferencesData;
import java.io.File; import java.io.File;
@ -221,22 +222,10 @@ public class FileDownloader extends Observable {
setError(e); setError(e);
} finally { } finally {
if (file != null) { IOUtils.closeQuietly(file);
try {
file.close();
} catch (Exception e) {
//ignore
}
}
synchronized (this) { synchronized (this) {
if (stream != null) { IOUtils.closeQuietly(stream);
try {
stream.close();
} catch (Exception e) {
//ignore
}
}
} }
} }
} }

View File

@ -8,6 +8,7 @@ import cc.arduino.files.DeleteFilesOnShutdown;
import cc.arduino.packages.DiscoveryManager; import cc.arduino.packages.DiscoveryManager;
import cc.arduino.packages.Uploader; import cc.arduino.packages.Uploader;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.logging.impl.LogFactoryImpl; import org.apache.commons.logging.impl.LogFactoryImpl;
import org.apache.commons.logging.impl.NoOpLog; import org.apache.commons.logging.impl.NoOpLog;
import processing.app.debug.Compiler; import processing.app.debug.Compiler;
@ -315,14 +316,15 @@ public class BaseNoGui {
static public File getSketchbookLibrariesFolder() { static public File getSketchbookLibrariesFolder() {
File libdir = new File(getSketchbookFolder(), "libraries"); File libdir = new File(getSketchbookFolder(), "libraries");
if (!libdir.exists()) { if (!libdir.exists()) {
FileWriter freadme = null;
try { try {
libdir.mkdirs(); libdir.mkdirs();
File readme = new File(libdir, "readme.txt"); freadme = new FileWriter(new File(libdir, "readme.txt"));
FileWriter freadme = new FileWriter(readme);
freadme.write(_("For information on installing libraries, see: " + freadme.write(_("For information on installing libraries, see: " +
"http://www.arduino.cc/en/Guide/Libraries\n")); "http://www.arduino.cc/en/Guide/Libraries\n"));
freadme.close();
} catch (Exception e) { } catch (Exception e) {
} finally {
IOUtils.closeQuietly(freadme);
} }
} }
return libdir; return libdir;
@ -595,11 +597,8 @@ public class BaseNoGui {
try { try {
out = new FileOutputStream(indexFile); out = new FileOutputStream(indexFile);
out.write("{ \"packages\" : [ ] }".getBytes()); out.write("{ \"packages\" : [ ] }".getBytes());
out.close();
} finally { } finally {
if (out != null) { IOUtils.closeQuietly(out);
out.close();
}
} }
} }
@ -643,9 +642,7 @@ public class BaseNoGui {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if (out != null) { IOUtils.closeQuietly(out);
out.close();
}
} }
} }
} }

View File

@ -13,6 +13,7 @@ import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.MissingResourceException; import java.util.MissingResourceException;
import org.apache.commons.compress.utils.IOUtils;
import processing.app.helpers.PreferencesHelper; import processing.app.helpers.PreferencesHelper;
import processing.app.helpers.PreferencesMap; import processing.app.helpers.PreferencesMap;
import processing.app.legacy.PApplet; import processing.app.legacy.PApplet;
@ -124,9 +125,7 @@ public class PreferencesData {
writer.flush(); writer.flush();
} finally { } finally {
if (writer != null) { IOUtils.closeQuietly(writer);
writer.close();
}
} }
try { try {

View File

@ -39,6 +39,7 @@ import cc.arduino.packages.BoardPort;
import cc.arduino.packages.Uploader; import cc.arduino.packages.Uploader;
import cc.arduino.packages.UploaderFactory; import cc.arduino.packages.UploaderFactory;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor; import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.ExecuteStreamHandler; import org.apache.commons.exec.ExecuteStreamHandler;
@ -100,12 +101,14 @@ public class Compiler implements MessageConsumer {
compiler.cleanup(prefsChanged, tempBuildFolder); compiler.cleanup(prefsChanged, tempBuildFolder);
if (prefsChanged) { if (prefsChanged) {
PrintWriter out = null;
try { try {
PrintWriter out = new PrintWriter(buildPrefsFile); out = new PrintWriter(buildPrefsFile);
out.print(newBuildPrefs); out.print(newBuildPrefs);
out.close();
} catch (IOException e) { } catch (IOException e) {
System.err.println(_("Could not write build preferences file")); System.err.println(_("Could not write build preferences file"));
} finally {
IOUtils.closeQuietly(out);
} }
} }
@ -612,6 +615,7 @@ public class Compiler implements MessageConsumer {
private boolean isAlreadyCompiled(File src, File obj, File dep, Map<String, String> prefs) { private boolean isAlreadyCompiled(File src, File obj, File dep, Map<String, String> prefs) {
boolean ret=true; boolean ret=true;
BufferedReader reader = null;
try { try {
//System.out.println("\n isAlreadyCompiled: begin checks: " + obj.getPath()); //System.out.println("\n isAlreadyCompiled: begin checks: " + obj.getPath());
if (!obj.exists()) return false; // object file (.o) does not exist if (!obj.exists()) return false; // object file (.o) does not exist
@ -620,7 +624,7 @@ public class Compiler implements MessageConsumer {
long obj_modified = obj.lastModified(); long obj_modified = obj.lastModified();
if (src_modified >= obj_modified) return false; // source modified since object compiled if (src_modified >= obj_modified) return false; // source modified since object compiled
if (src_modified >= dep.lastModified()) return false; // src modified since dep compiled if (src_modified >= dep.lastModified()) return false; // src modified since dep compiled
BufferedReader reader = new BufferedReader(new FileReader(dep.getPath())); reader = new BufferedReader(new FileReader(dep.getPath()));
String line; String line;
boolean need_obj_parse = true; boolean need_obj_parse = true;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
@ -664,9 +668,10 @@ public class Compiler implements MessageConsumer {
//System.out.println(" isAlreadyCompiled: prerequisite ok"); //System.out.println(" isAlreadyCompiled: prerequisite ok");
} }
} }
reader.close();
} catch (Exception e) { } catch (Exception e) {
return false; // any error reading dep file = recompile it return false; // any error reading dep file = recompile it
} finally {
IOUtils.closeQuietly(reader);
} }
if (ret && verbose) { if (ret && verbose) {
System.out.println(I18n.format(_("Using previously compiled file: {0}"), obj.getPath())); System.out.println(I18n.format(_("Using previously compiled file: {0}"), obj.getPath()));
@ -1267,13 +1272,7 @@ public class Compiler implements MessageConsumer {
ex.printStackTrace(); ex.printStackTrace();
throw new RunnerException(ex.toString()); throw new RunnerException(ex.toString());
} finally { } finally {
if (outputStream != null) { IOUtils.closeQuietly(outputStream);
try {
outputStream.close();
} catch (IOException e) {
//noop
}
}
} }
// grab the imports from the code just preproc'd // grab the imports from the code just preproc'd

View File

@ -1,5 +1,7 @@
package processing.app.helpers; package processing.app.helpers;
import org.apache.commons.compress.utils.IOUtils;
import java.io.*; import java.io.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -49,12 +51,8 @@ public class FileUtils {
fos.write(buf, 0, readBytes); fos.write(buf, 0, readBytes);
} }
} finally { } finally {
if (fis != null) { IOUtils.closeQuietly(fis);
fis.close(); IOUtils.closeQuietly(fos);
}
if (fos != null) {
fos.close();
}
} }
} }
@ -185,13 +183,7 @@ public class FileUtils {
} }
return sb.toString(); return sb.toString();
} finally { } finally {
if (reader != null) { IOUtils.closeQuietly(reader);
try {
reader.close();
} catch (IOException e) {
// noop
}
}
} }
} }

View File

@ -1,5 +1,7 @@
package processing.app.helpers; package processing.app.helpers;
import org.apache.commons.compress.utils.IOUtils;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -43,13 +45,7 @@ public abstract class NetUtils {
} catch (IOException e) { } catch (IOException e) {
return false; return false;
} finally { } finally {
if (socket != null) { IOUtils.closeQuietly(socket);
try {
socket.close();
} catch (IOException e) {
// noop
}
}
} }
} }
} }

View File

@ -21,6 +21,7 @@
*/ */
package processing.app.helpers; package processing.app.helpers;
import org.apache.commons.compress.utils.IOUtils;
import processing.app.legacy.PApplet; import processing.app.legacy.PApplet;
import java.io.*; import java.io.*;
@ -72,9 +73,7 @@ public class PreferencesMap extends LinkedHashMap<String, String> {
fileInputStream = new FileInputStream(file); fileInputStream = new FileInputStream(file);
load(fileInputStream); load(fileInputStream);
} finally { } finally {
if (fileInputStream != null) { IOUtils.closeQuietly(fileInputStream);
fileInputStream.close();
}
} }
} }

View File

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