mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-23 19:21:59 +03:00
Closing streams using IOUtils.closeQuietly
Fixed badly handled stream found in the meanwhile
This commit is contained in:
@ -39,6 +39,7 @@ import cc.arduino.view.Event;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Collections2;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import processing.app.debug.TargetBoard;
|
||||
import processing.app.debug.TargetPackage;
|
||||
@ -2517,9 +2518,7 @@ public class Base {
|
||||
}
|
||||
return buffer;
|
||||
} finally {
|
||||
if (input != null) {
|
||||
input.close();
|
||||
}
|
||||
IOUtils.closeQuietly(input);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2567,12 +2566,8 @@ public class Base {
|
||||
}
|
||||
to.flush();
|
||||
} finally {
|
||||
if (from != null) {
|
||||
from.close(); // ??
|
||||
}
|
||||
if (to != null) {
|
||||
to.close(); // ??
|
||||
}
|
||||
IOUtils.closeQuietly(from);
|
||||
IOUtils.closeQuietly(to);
|
||||
}
|
||||
|
||||
targetFile.setLastModified(sourceFile.lastModified());
|
||||
|
@ -28,6 +28,7 @@ import cc.arduino.view.StubMenuListener;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.jcraft.jsch.JSchException;
|
||||
import jssc.SerialPortException;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import processing.app.debug.*;
|
||||
import processing.app.forms.PasswordAuthorizationDialog;
|
||||
import processing.app.helpers.OSUtils;
|
||||
@ -965,11 +966,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
//System.err.println("Ignoring " + filename + " (" + e.getMessage() + ")");
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (zipFile != null)
|
||||
try {
|
||||
zipFile.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
IOUtils.closeQuietly(zipFile);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package processing.app;
|
||||
|
||||
import cc.arduino.files.DeleteFilesOnShutdown;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
@ -82,17 +83,13 @@ class EditorConsoleStream extends OutputStream {
|
||||
System.setErr(systemErr);
|
||||
|
||||
// close the PrintStream
|
||||
consoleOut.close();
|
||||
consoleErr.close();
|
||||
IOUtils.closeQuietly(consoleOut);
|
||||
IOUtils.closeQuietly(consoleErr);
|
||||
|
||||
// also have to close the original FileOutputStream
|
||||
// otherwise it won't be shut down completely
|
||||
try {
|
||||
stdoutFile.close();
|
||||
stderrFile.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
IOUtils.closeQuietly(stdoutFile);
|
||||
IOUtils.closeQuietly(stderrFile);
|
||||
|
||||
outFile.delete();
|
||||
errFile.delete();
|
||||
@ -149,4 +146,4 @@ class EditorConsoleStream extends OutputStream {
|
||||
currentConsole = console;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
package processing.app;
|
||||
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import processing.app.legacy.PApplet;
|
||||
|
||||
import javax.swing.*;
|
||||
@ -133,9 +134,7 @@ public class UpdateCheck implements Runnable {
|
||||
reader = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||
return Integer.parseInt(reader.readLine());
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
reader.close();
|
||||
}
|
||||
IOUtils.closeQuietly(reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
package processing.app.syntax;
|
||||
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.fife.ui.rsyntaxtextarea.TokenMap;
|
||||
import org.fife.ui.rsyntaxtextarea.TokenTypes;
|
||||
import processing.app.Base;
|
||||
@ -126,9 +127,7 @@ public class PdeKeywords {
|
||||
|
||||
fillMissingTokenType();
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
reader.close();
|
||||
}
|
||||
IOUtils.closeQuietly(reader);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
package processing.app.syntax;
|
||||
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.fife.ui.rsyntaxtextarea.*;
|
||||
import org.fife.ui.rsyntaxtextarea.Theme;
|
||||
import org.fife.ui.rsyntaxtextarea.Token;
|
||||
@ -102,9 +103,7 @@ public class SketchTextArea extends RSyntaxTextArea {
|
||||
Theme theme = Theme.load(defaultXmlInputStream);
|
||||
theme.apply(this);
|
||||
} finally {
|
||||
if (defaultXmlInputStream != null) {
|
||||
defaultXmlInputStream.close();
|
||||
}
|
||||
IOUtils.closeQuietly(defaultXmlInputStream);
|
||||
}
|
||||
|
||||
setForeground(processing.app.Theme.getColor("editor.fgcolor"));
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
package processing.app.tools;
|
||||
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import processing.app.Base;
|
||||
import processing.app.Editor;
|
||||
import processing.app.Sketch;
|
||||
@ -124,22 +125,21 @@ public class Archiver implements Tool {
|
||||
if (filename != null) {
|
||||
newbie = new File(directory, filename);
|
||||
|
||||
ZipOutputStream zos = null;
|
||||
try {
|
||||
//System.out.println(newbie);
|
||||
FileOutputStream zipOutputFile = new FileOutputStream(newbie);
|
||||
ZipOutputStream zos = new ZipOutputStream(zipOutputFile);
|
||||
zos = new ZipOutputStream(new FileOutputStream(newbie));
|
||||
|
||||
// recursively fill the zip file
|
||||
buildZip(location, name, zos);
|
||||
|
||||
// close up the jar file
|
||||
zos.flush();
|
||||
zos.close();
|
||||
|
||||
editor.statusNotice("Created archive " + newbie.getName() + ".");
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
IOUtils.closeQuietly(zos);
|
||||
}
|
||||
} else {
|
||||
editor.statusNotice(_("Archive sketch canceled."));
|
||||
|
@ -29,6 +29,7 @@ import java.io.IOException;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import processing.app.*;
|
||||
import static processing.app.I18n._;
|
||||
|
||||
@ -83,16 +84,19 @@ public class FixEncoding implements Tool {
|
||||
|
||||
protected String loadWithLocalEncoding(File file) throws IOException {
|
||||
// FileReader uses the default encoding, which is what we want.
|
||||
FileReader fr = new FileReader(file);
|
||||
BufferedReader reader = new BufferedReader(fr);
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(file));
|
||||
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
String line = null;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
buffer.append(line);
|
||||
buffer.append('\n');
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
buffer.append(line);
|
||||
buffer.append('\n');
|
||||
}
|
||||
return buffer.toString();
|
||||
} finally {
|
||||
IOUtils.closeQuietly(reader);
|
||||
}
|
||||
reader.close();
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipException;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import processing.app.helpers.FileUtils;
|
||||
|
||||
public class ZipDeflater {
|
||||
@ -54,12 +55,8 @@ public class ZipDeflater {
|
||||
fos.write(buffer, 0, len);
|
||||
}
|
||||
} finally {
|
||||
if (fos != null) {
|
||||
fos.close();
|
||||
}
|
||||
if (zipInputStream != null) {
|
||||
zipInputStream.close();
|
||||
}
|
||||
IOUtils.closeQuietly(fos);
|
||||
IOUtils.closeQuietly(zipInputStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user