Author: nextgens
Date: 2007-03-17 15:21:50 +0000 (Sat, 17 Mar 2007)
New Revision: 12187
Modified:
trunk/freenet/src/freenet/clients/http/HTTPRequestImpl.java
trunk/freenet/src/freenet/clients/http/Spider.java
trunk/freenet/src/freenet/crypt/Yarrow.java
trunk/freenet/src/freenet/pluginmanager/PluginManager.java
trunk/freenet/src/freenet/support/FileLoggerHook.java
trunk/freenet/src/freenet/support/io/BucketTools.java
Log:
add some InputStrem.close() calls
Modified: trunk/freenet/src/freenet/clients/http/HTTPRequestImpl.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/HTTPRequestImpl.java 2007-03-17
15:20:19 UTC (rev 12186)
+++ trunk/freenet/src/freenet/clients/http/HTTPRequestImpl.java 2007-03-17
15:21:50 UTC (rev 12187)
@@ -464,6 +464,8 @@
// Do nothing, irrelevant header
}
}
+ lis.close();
+ bis.close();
if (name == null) continue;
@@ -535,16 +537,25 @@
if (part.size() > maxlength) return "";
+ InputStream is = null;
+ DataInputStream dis = null;
try {
- InputStream is = part.getInputStream();
- DataInputStream dis = new DataInputStream(is);
+ is = part.getInputStream();
+ dis = new DataInputStream(is);
byte[] buf = new byte[is.available()];
dis.readFully(buf);
- is.close();
return new String(buf);
} catch (IOException ioe) {
-
+ Logger.error(this, "Caught IOE:" + ioe.getMessage());
+ } finally {
+ try {
+ if(dis != null)
+ dis.close();
+ if(is != null)
+ is.close();
+ } catch (IOException ioe) {}
}
+
return "";
}
Modified: trunk/freenet/src/freenet/clients/http/Spider.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/Spider.java 2007-03-17 15:20:19 UTC
(rev 12186)
+++ trunk/freenet/src/freenet/clients/http/Spider.java 2007-03-17 15:21:50 UTC
(rev 12187)
@@ -239,11 +239,12 @@
} catch (UnsupportedEncodingException e) {
throw new Error(e);
}
- BufferedWriter bw = new BufferedWriter(osw);
+
if (urisByWord.isEmpty() || urisWithWords.isEmpty()) {
System.out.println("No URIs with words");
return;
}
+ BufferedWriter bw = new BufferedWriter(osw);
String[] words = (String[]) urisByWord.keySet().toArray(new
String[urisByWord.size()]);
Arrays.sort(words);
FreenetURI[] uris = (FreenetURI[]) urisWithWords.toArray(new
FreenetURI[urisWithWords.size()]);
Modified: trunk/freenet/src/freenet/crypt/Yarrow.java
===================================================================
--- trunk/freenet/src/freenet/crypt/Yarrow.java 2007-03-17 15:20:19 UTC (rev
12186)
+++ trunk/freenet/src/freenet/crypt/Yarrow.java 2007-03-17 15:21:50 UTC (rev
12187)
@@ -98,12 +98,13 @@
public void seedFromExternalStuff(boolean canBlock) {
byte[] buf = new byte[32];
if(File.separatorChar == '/') {
+ DataInputStream dis = null;
FileInputStream fis = null;
File hwrng = new File("/dev/hwrng");
if(hwrng.exists() && hwrng.canRead()) {
try {
fis = new FileInputStream(hwrng);
- DataInputStream dis = new DataInputStream(fis);
+ dis = new DataInputStream(fis);
dis.readFully(buf);
consumeBytes(buf);
dis.readFully(buf);
@@ -111,17 +112,19 @@
} catch (Throwable t) {
Logger.normal(this, "Can't read /dev/hwrng even
though exists and is readable: "+t, t);
} finally {
- if(fis != null) try {
- fis.close();
- } catch (IOException e) {
- // Ignore
- }
+ try {
+ if(fis != null)
+ fis.close();
+ if(dis != null)
+ dis.close();
+ } catch (IOException e) {}
}
}
+
// Read some bits from /dev/urandom
try {
fis = new FileInputStream("/dev/urandom");
- DataInputStream dis = new DataInputStream(fis);
+ dis = new DataInputStream(fis);
dis.readFully(buf);
consumeBytes(buf);
dis.readFully(buf);
@@ -129,17 +132,18 @@
} catch (Throwable t) {
Logger.normal(this, "Can't read /dev/urandom: "+t, t);
} finally {
- if(fis != null) try {
- fis.close();
- } catch (IOException e) {
- // Ignore
- }
+ try {
+ if(fis != null)
+ fis.close();
+ if(dis != null)
+ dis.close();
+ } catch (IOException e) {}
}
if(canBlock) {
// Read some bits from /dev/random
try {
fis = new FileInputStream("/dev/random");
- DataInputStream dis = new DataInputStream(fis);
+ dis = new DataInputStream(fis);
dis.readFully(buf);
consumeBytes(buf);
dis.readFully(buf);
@@ -147,11 +151,12 @@
} catch (Throwable t) {
Logger.normal(this, "Can't read /dev/random: "+t, t);
} finally {
- if(fis != null) try {
- fis.close();
- } catch (IOException e) {
- // Ignore
- }
+ try {
+ if(fis != null)
+ fis.close();
+ if(dis != null)
+ dis.close();
+ } catch (IOException e) {}
}
}
fis = null;
Modified: trunk/freenet/src/freenet/pluginmanager/PluginManager.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/PluginManager.java 2007-03-17
15:20:19 UTC (rev 12186)
+++ trunk/freenet/src/freenet/pluginmanager/PluginManager.java 2007-03-17
15:21:50 UTC (rev 12187)
@@ -4,6 +4,7 @@
package freenet.pluginmanager;
import java.io.BufferedReader;
+import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.JarURLConnection;
@@ -320,6 +321,8 @@
if(logMINOR) Logger.minor(this, "Rewritten to "+filename);
}
+ BufferedReader in = null;
+ InputStream is = null;
if ((filename.indexOf("@") >= 0)) {
boolean assumeURLRedirect = true;
// Open from external file
@@ -340,7 +343,6 @@
if (filename.endsWith(".url")) {
if(!assumeURLRedirect) {
// Load the txt-file
- BufferedReader in;
URL url = new URL(parts[1]);
URLConnection uc =
url.openConnection();
in = new BufferedReader(
@@ -384,8 +386,8 @@
//URL url = new URL(parts[1]);
//URLConnection uc =
cl.getResource("/META-INF/MANIFEST.MF").openConnection();
- InputStream is =
jf.getInputStream(jf.getJarEntry("META-INF/MANIFEST.MF"));
- BufferedReader in = new
BufferedReader(new InputStreamReader(is));
+ is =
jf.getInputStream(jf.getJarEntry("META-INF/MANIFEST.MF"));
+ in = new BufferedReader(new
InputStreamReader(is));
String line;
while ((line = in.readLine())!=null) {
// System.err.println(line
+ "\t\t\t" + realClass);
@@ -407,6 +409,13 @@
try {
Thread.sleep(100);
} catch (Exception ee) {}
+ } finally {
+ try {
+ if(is != null)
+ is.close();
+ if(in != null)
+ in.close();
+ } catch (IOException ioe){}
}
} else {
// Load class
Modified: trunk/freenet/src/freenet/support/FileLoggerHook.java
===================================================================
--- trunk/freenet/src/freenet/support/FileLoggerHook.java 2007-03-17
15:20:19 UTC (rev 12186)
+++ trunk/freenet/src/freenet/support/FileLoggerHook.java 2007-03-17
15:21:50 UTC (rev 12187)
@@ -966,6 +966,8 @@
os.write(buf, 0, toRead);
written += toRead;
}
+ dis.close();
+ fis.close();
}
/** Set the maximum size of old (gzipped) log files to keep.
Modified: trunk/freenet/src/freenet/support/io/BucketTools.java
===================================================================
--- trunk/freenet/src/freenet/support/io/BucketTools.java 2007-03-17
15:20:19 UTC (rev 12186)
+++ trunk/freenet/src/freenet/support/io/BucketTools.java 2007-03-17
15:21:50 UTC (rev 12187)
@@ -194,11 +194,14 @@
if(size > Integer.MAX_VALUE) throw new OutOfMemoryError();
byte[] data = new byte[(int)size];
InputStream is = bucket.getInputStream();
+ DataInputStream dis = null;
try {
- DataInputStream dis = new DataInputStream(is);
+ dis = new DataInputStream(is);
dis.readFully(data);
} finally {
is.close();
+ if(dis != null)
+ dis.close();
}
return data;
}
@@ -334,8 +337,9 @@
if(length % splitSize > 0) bucketCount++;
Bucket[] buckets = new Bucket[bucketCount];
InputStream is = origData.getInputStream();
+ DataInputStream dis = null;
try {
- DataInputStream dis = new DataInputStream(is);
+ dis = new DataInputStream(is);
long remainingLength = length;
byte[] buf = new byte[splitSize];
for(int i=0;i<bucketCount;i++) {
@@ -353,6 +357,8 @@
}
} finally {
is.close();
+ if(dis != null)
+ dis.close();
}
return buckets;
}