From 6b450d09ca8e4a2dbb3dcec94ae110d1845a42b2 Mon Sep 17 00:00:00 2001 From: orbiter Date: Mon, 16 Feb 2009 23:31:54 +0000 Subject: [PATCH] some fixes recommended by findbugs git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5618 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/http/httpdFileHandler.java | 6 ++---- source/de/anomic/kelondro/index/BytesLongMap.java | 1 + source/de/anomic/kelondro/index/RAMIndex.java | 4 ++-- source/de/anomic/kelondro/util/FileUtils.java | 8 +++++++- source/de/anomic/kelondro/util/ScoreCluster.java | 2 +- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/source/de/anomic/http/httpdFileHandler.java b/source/de/anomic/http/httpdFileHandler.java index 6f53a7aa2..c9e4b23f9 100644 --- a/source/de/anomic/http/httpdFileHandler.java +++ b/source/de/anomic/http/httpdFileHandler.java @@ -77,7 +77,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Properties; -import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.zip.GZIPOutputStream; @@ -608,9 +607,8 @@ public final class httpdFileHandler { } // add values from request header to environment (see: http://hoohoo.ncsa.uiuc.edu/cgi/env.html#headers) - Set requestHeaderKeys = requestHeader.keySet(); - for (String requestHeaderKey : requestHeaderKeys) { - env.put("HTTP_" + requestHeaderKey.toUpperCase().replace("-", "_"), requestHeader.get(requestHeaderKey)); + for (Map.Entry requestHeaderEntry : requestHeader.entrySet()) { + env.put("HTTP_" + requestHeaderEntry.getKey().toUpperCase().replace("-", "_"), requestHeaderEntry.getValue()); } int exitValue = 0; diff --git a/source/de/anomic/kelondro/index/BytesLongMap.java b/source/de/anomic/kelondro/index/BytesLongMap.java index 9722c6347..cb2a804c0 100644 --- a/source/de/anomic/kelondro/index/BytesLongMap.java +++ b/source/de/anomic/kelondro/index/BytesLongMap.java @@ -81,6 +81,7 @@ public class BytesLongMap { if (c <= 0) break; this.index.addUnique(this.rowdef.newEntry(a)); } + is.close(); assert this.index.size() == file.length() / (keylength + 8); } diff --git a/source/de/anomic/kelondro/index/RAMIndex.java b/source/de/anomic/kelondro/index/RAMIndex.java index aa3b8d5cf..9c5a71e1c 100644 --- a/source/de/anomic/kelondro/index/RAMIndex.java +++ b/source/de/anomic/kelondro/index/RAMIndex.java @@ -49,7 +49,7 @@ public class RAMIndex implements ObjectIndex { reset(0); } - public void reset(final int initialspace) { + public synchronized void reset(final int initialspace) { this.index0 = null; // first flush RAM to make room this.index0 = new RowSet(rowdef, initialspace); this.index1 = null; // to show that this is the initialization phase @@ -77,7 +77,7 @@ public class RAMIndex implements ObjectIndex { return index1.get(key); } - public boolean has(final byte[] key) { + public synchronized boolean has(final byte[] key) { assert (key != null); finishInitialization(); assert index0.isSorted(); diff --git a/source/de/anomic/kelondro/util/FileUtils.java b/source/de/anomic/kelondro/util/FileUtils.java index 56b9c5dc9..aca6c093e 100644 --- a/source/de/anomic/kelondro/util/FileUtils.java +++ b/source/de/anomic/kelondro/util/FileUtils.java @@ -255,7 +255,13 @@ public final class FileUtils { public static byte[] read(final InputStream source, final int count) throws IOException { if (count > 0) { byte[] b = new byte[count]; - source.read(b, 0, count); + int c = source.read(b, 0, count); + assert c == count: "count = " + count + ", c = " + c; + if (c != count) { + byte[] bb = new byte[c]; + System.arraycopy(b, 0, bb, 0, c); + return bb; + } return b; } else { final ByteArrayOutputStream baos = new ByteArrayOutputStream(512); diff --git a/source/de/anomic/kelondro/util/ScoreCluster.java b/source/de/anomic/kelondro/util/ScoreCluster.java index a036d7e7d..ed71556aa 100644 --- a/source/de/anomic/kelondro/util/ScoreCluster.java +++ b/source/de/anomic/kelondro/util/ScoreCluster.java @@ -44,7 +44,7 @@ public final class ScoreCluster { encnt = 0; } - public void clear() { + public synchronized void clear() { refkeyDB.clear(); keyrefDB.clear(); gcount = 0;