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:
@ -8,6 +8,7 @@ import cc.arduino.files.DeleteFilesOnShutdown;
|
||||
import cc.arduino.packages.DiscoveryManager;
|
||||
import cc.arduino.packages.Uploader;
|
||||
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.NoOpLog;
|
||||
import processing.app.debug.Compiler;
|
||||
@ -315,14 +316,15 @@ public class BaseNoGui {
|
||||
static public File getSketchbookLibrariesFolder() {
|
||||
File libdir = new File(getSketchbookFolder(), "libraries");
|
||||
if (!libdir.exists()) {
|
||||
FileWriter freadme = null;
|
||||
try {
|
||||
libdir.mkdirs();
|
||||
File readme = new File(libdir, "readme.txt");
|
||||
FileWriter freadme = new FileWriter(readme);
|
||||
freadme = new FileWriter(new File(libdir, "readme.txt"));
|
||||
freadme.write(_("For information on installing libraries, see: " +
|
||||
"http://www.arduino.cc/en/Guide/Libraries\n"));
|
||||
freadme.close();
|
||||
} catch (Exception e) {
|
||||
} finally {
|
||||
IOUtils.closeQuietly(freadme);
|
||||
}
|
||||
}
|
||||
return libdir;
|
||||
@ -595,11 +597,8 @@ public class BaseNoGui {
|
||||
try {
|
||||
out = new FileOutputStream(indexFile);
|
||||
out.write("{ \"packages\" : [ ] }".getBytes());
|
||||
out.close();
|
||||
} finally {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
IOUtils.closeQuietly(out);
|
||||
}
|
||||
}
|
||||
|
||||
@ -643,9 +642,7 @@ public class BaseNoGui {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
IOUtils.closeQuietly(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import processing.app.helpers.PreferencesHelper;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.legacy.PApplet;
|
||||
@ -124,9 +125,7 @@ public class PreferencesData {
|
||||
|
||||
writer.flush();
|
||||
} finally {
|
||||
if (writer != null) {
|
||||
writer.close();
|
||||
}
|
||||
IOUtils.closeQuietly(writer);
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -39,6 +39,7 @@ import cc.arduino.packages.BoardPort;
|
||||
import cc.arduino.packages.Uploader;
|
||||
import cc.arduino.packages.UploaderFactory;
|
||||
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.apache.commons.exec.CommandLine;
|
||||
import org.apache.commons.exec.DefaultExecutor;
|
||||
import org.apache.commons.exec.ExecuteStreamHandler;
|
||||
@ -100,12 +101,14 @@ public class Compiler implements MessageConsumer {
|
||||
compiler.cleanup(prefsChanged, tempBuildFolder);
|
||||
|
||||
if (prefsChanged) {
|
||||
PrintWriter out = null;
|
||||
try {
|
||||
PrintWriter out = new PrintWriter(buildPrefsFile);
|
||||
out = new PrintWriter(buildPrefsFile);
|
||||
out.print(newBuildPrefs);
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
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) {
|
||||
boolean ret=true;
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
//System.out.println("\n isAlreadyCompiled: begin checks: " + obj.getPath());
|
||||
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();
|
||||
if (src_modified >= obj_modified) return false; // source modified since object 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;
|
||||
boolean need_obj_parse = true;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
@ -664,9 +668,10 @@ public class Compiler implements MessageConsumer {
|
||||
//System.out.println(" isAlreadyCompiled: prerequisite ok");
|
||||
}
|
||||
}
|
||||
reader.close();
|
||||
} catch (Exception e) {
|
||||
return false; // any error reading dep file = recompile it
|
||||
} finally {
|
||||
IOUtils.closeQuietly(reader);
|
||||
}
|
||||
if (ret && verbose) {
|
||||
System.out.println(I18n.format(_("Using previously compiled file: {0}"), obj.getPath()));
|
||||
@ -1267,13 +1272,7 @@ public class Compiler implements MessageConsumer {
|
||||
ex.printStackTrace();
|
||||
throw new RunnerException(ex.toString());
|
||||
} finally {
|
||||
if (outputStream != null) {
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
//noop
|
||||
}
|
||||
}
|
||||
IOUtils.closeQuietly(outputStream);
|
||||
}
|
||||
|
||||
// grab the imports from the code just preproc'd
|
||||
|
@ -1,5 +1,7 @@
|
||||
package processing.app.helpers;
|
||||
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -49,12 +51,8 @@ public class FileUtils {
|
||||
fos.write(buf, 0, readBytes);
|
||||
}
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
fis.close();
|
||||
}
|
||||
if (fos != null) {
|
||||
fos.close();
|
||||
}
|
||||
IOUtils.closeQuietly(fis);
|
||||
IOUtils.closeQuietly(fos);
|
||||
}
|
||||
}
|
||||
|
||||
@ -185,13 +183,7 @@ public class FileUtils {
|
||||
}
|
||||
return sb.toString();
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
// noop
|
||||
}
|
||||
}
|
||||
IOUtils.closeQuietly(reader);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package processing.app.helpers;
|
||||
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
@ -43,13 +45,7 @@ public abstract class NetUtils {
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
} finally {
|
||||
if (socket != null) {
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException e) {
|
||||
// noop
|
||||
}
|
||||
}
|
||||
IOUtils.closeQuietly(socket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
*/
|
||||
package processing.app.helpers;
|
||||
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import processing.app.legacy.PApplet;
|
||||
|
||||
import java.io.*;
|
||||
@ -72,9 +73,7 @@ public class PreferencesMap extends LinkedHashMap<String, String> {
|
||||
fileInputStream = new FileInputStream(file);
|
||||
load(fileInputStream);
|
||||
} finally {
|
||||
if (fileInputStream != null) {
|
||||
fileInputStream.close();
|
||||
}
|
||||
IOUtils.closeQuietly(fileInputStream);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user