Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
Replaced improper ByteBuffer.equals() implementation by Arrays.equals()
luccioman929e0d6eae88
diff --git a/htroot/IndexControlRWIs_p.java b/htroot/IndexControlRWIs_p.javaindex ed2cbbd0a..d39558029 100644--- a/htroot/IndexControlRWIs_p.java+++ b/htroot/IndexControlRWIs_p.java@@ -27,6 +27,7 @@import java.io.IOException;import java.util.ArrayList;+import java.util.Arrays;import java.util.Collection;import java.util.Date;import java.util.Iterator;@@ -42,7 +43,6 @@ import net.yacy.cora.federate.yacy.CacheStrategy;import net.yacy.cora.protocol.ClientIdentification;import net.yacy.cora.protocol.RequestHeader;import net.yacy.cora.storage.HandleSet;-import net.yacy.cora.util.ByteBuffer;import net.yacy.cora.util.ConcurrentLog;import net.yacy.cora.util.SpaceExceededException;import net.yacy.data.ListManager;@@ -146,7 +146,7 @@ public class IndexControlRWIs_p {}if ( post.containsKey("keyhashsearch") ) {- if ( keystring.isEmpty() || !ByteBuffer.equals(Word.word2hash(keystring), keyhash) ) {+ if ( keystring.isEmpty() || !Arrays.equals(Word.word2hash(keystring), keyhash) ) {prop.put("keystring", "<" + errmsg + ">");}final SearchEvent theSearch = genSearchresult(prop, sb, keyhash, null);@@ -246,7 +246,7 @@ public class IndexControlRWIs_p {}if ( post.containsKey("urllist") ) {- if ( keystring.isEmpty() || !ByteBuffer.equals(Word.word2hash(keystring), keyhash) ) {+ if ( keystring.isEmpty() || !Arrays.equals(Word.word2hash(keystring), keyhash) ) {prop.put("keystring", "<" + errmsg + ">");}final Bitfield flags = compileFlags(post);@@ -261,7 +261,7 @@ public class IndexControlRWIs_p {TransactionManager.checkPostTransaction(header, post);try {- if ( keystring.isEmpty() || !ByteBuffer.equals(Word.word2hash(keystring), keyhash) ) {+ if ( keystring.isEmpty() || !Arrays.equals(Word.word2hash(keystring), keyhash) ) {prop.put("keystring", "<" + errmsg + ">");}diff --git a/htroot/Wiki.java b/htroot/Wiki.javaindex 55255caee..3468440fc 100644--- a/htroot/Wiki.java+++ b/htroot/Wiki.java@@ -31,6 +31,7 @@// if the shell's current path is HTROOTimport java.io.IOException;+import java.util.Arrays;import java.util.Date;import java.util.HashMap;import java.util.Iterator;@@ -41,7 +42,6 @@ import net.yacy.cora.document.encoding.UTF8;import net.yacy.cora.protocol.Domains;import net.yacy.cora.protocol.HeaderFramework;import net.yacy.cora.protocol.RequestHeader;-import net.yacy.cora.util.ByteBuffer;import net.yacy.data.Diff;import net.yacy.data.wiki.WikiBoard;import net.yacy.peers.NewsPool;@@ -118,7 +118,7 @@ public class Wiki {final Map<String, String> map = new HashMap<String, String>();map.put("page", pagename);map.put("author", author.replace(',', ' '));- if (!sb.isRobinsonMode() && post.get("content", "").trim().length() > 0 && !ByteBuffer.equals(page.page(), content)) {+ if (!sb.isRobinsonMode() && post.get("content", "").trim().length() > 0 && !Arrays.equals(page.page(), content)) {sb.peers.newsPool.publishMyNews(sb.peers.mySeed(), NewsPool.CATEGORY_WIKI_UPDATE, map);}page = newEntry;diff --git a/htroot/yacy/search.java b/htroot/yacy/search.javaindex ed810d475..de10b8849 100644--- a/htroot/yacy/search.java+++ b/htroot/yacy/search.java@@ -30,6 +30,7 @@import java.io.IOException;import java.util.ArrayList;+import java.util.Arrays;import java.util.HashSet;import java.util.Iterator;import java.util.Map;@@ -48,7 +49,6 @@ import net.yacy.cora.protocol.RequestHeader;import net.yacy.cora.sorting.ScoreMap;import net.yacy.cora.sorting.WeakPriorityBlockingQueue;import net.yacy.cora.storage.HandleSet;-import net.yacy.cora.util.ByteBuffer;import net.yacy.cora.util.SpaceExceededException;import net.yacy.gui.Audio;import net.yacy.kelondro.data.meta.URIMetadataNode;@@ -368,7 +368,7 @@ public final class search {// automatically attach the index abstract for the index that has the most references. This should be our target dht positionindexabstractContainercount += theSearch.abstractsCount(theSearch.getAbstractsMaxCountHash());indexabstract.append("indexabstract.").append(ASCII.String(theSearch.getAbstractsMaxCountHash())).append("=").append(theSearch.abstractsString(theSearch.getAbstractsMaxCountHash())).append(serverCore.CRLF_STRING);- if ((theSearch.getAbstractsNearDHTHash() != null) && (!(ByteBuffer.equals(theSearch.getAbstractsNearDHTHash(), theSearch.getAbstractsMaxCountHash())))) {+ if ((theSearch.getAbstractsNearDHTHash() != null) && (!(Arrays.equals(theSearch.getAbstractsNearDHTHash(), theSearch.getAbstractsMaxCountHash())))) {// in case that the neardhthash is different from the maxcounthash attach also the neardhthash-containerindexabstractContainercount += theSearch.abstractsCount(theSearch.getAbstractsNearDHTHash());indexabstract.append("indexabstract.").append(ASCII.String(theSearch.getAbstractsNearDHTHash())).append("=").append(theSearch.abstractsString(theSearch.getAbstractsNearDHTHash())).append(serverCore.CRLF_STRING);diff --git a/source/net/yacy/cora/util/ByteBuffer.java b/source/net/yacy/cora/util/ByteBuffer.javaindex 208d18103..4c6477a1b 100644--- a/source/net/yacy/cora/util/ByteBuffer.java+++ b/source/net/yacy/cora/util/ByteBuffer.java@@ -23,6 +23,7 @@ package net.yacy.cora.util;import java.io.IOException;import java.io.OutputStream;import java.util.ArrayList;+import java.util.Arrays;import java.util.Collection;import java.util.Iterator;import java.util.List;@@ -221,10 +222,20 @@ public final class ByteBuffer extends OutputStream {return sb;}- public static boolean equals(final byte[] buffer, final byte[] pattern) {- // compares two byte arrays: true, if pattern appears completely at offset position- if (buffer.length < pattern.length) return false;- for (int i = 0; i < pattern.length; i++) if (buffer[i] != pattern[i]) return false;+ /**+ * @param buffer the buffer to test. Must not be null.+ * @param pattern a pattern to check for presence at the beginning of the buffer. Must not be null.+ * @return true when the buffer starts with the given pattern+ */+ public static boolean startsWith(final byte[] buffer, final byte[] pattern) {+ if (buffer.length < pattern.length) {+ return false;+ }+ for (int i = 0; i < pattern.length; i++) {+ if (buffer[i] != pattern[i]) {+ return false;+ }+ }return true;}@@ -241,7 +252,7 @@ public final class ByteBuffer extends OutputStream {public static boolean contains(final Collection<byte[]> collection, final byte[] key) {for (final byte[] v: collection) {- if (equals(v, key)) return true;+ if (Arrays.equals(v, key)) return true;}return false;}@@ -252,7 +263,7 @@ public final class ByteBuffer extends OutputStream {int c = 0;while (i.hasNext()) {v = i.next();- if (equals(v, key)) {+ if (Arrays.equals(v, key)) {i.remove();c++;}diff --git a/source/net/yacy/dbtest.java b/source/net/yacy/dbtest.javaindex 1059ba31c..4e2fd0519 100644--- a/source/net/yacy/dbtest.java+++ b/source/net/yacy/dbtest.java@@ -5,6 +5,7 @@ package net.yacy;import java.io.File;import java.io.IOException;+import java.util.Arrays;import java.util.Date;import java.util.Iterator;import java.util.Random;@@ -15,7 +16,6 @@ import net.yacy.cora.document.encoding.UTF8;import net.yacy.cora.order.Base64Order;import net.yacy.cora.order.CloneableIterator;import net.yacy.cora.order.NaturalOrder;-import net.yacy.cora.util.ByteBuffer;import net.yacy.cora.util.ConcurrentLog;import net.yacy.cora.util.SpaceExceededException;import net.yacy.kelondro.index.Index;@@ -73,7 +73,7 @@ public class dbtest {final String s = UTF8.String(this.value).trim();if (s.isEmpty()) return false;final long source = Long.parseLong(s);- return ByteBuffer.equals(this.key, randomHash(source, source));+ return Arrays.equals(this.key, randomHash(source, source));}public byte[] getKey() {@@ -340,13 +340,13 @@ public class dbtest {if (entry == null)System.out.println("missing value for entry " + UTF8.String(key) + " in test table");else- if (!ByteBuffer.equals(entry.getColBytes(1, false), key)) System.out.println("wrong value for entry " + UTF8.String(key) + ": " + UTF8.String(entry.getColBytes(1, false)) + " in test table");+ if (!Arrays.equals(entry.getColBytes(1, false), key)) System.out.println("wrong value for entry " + UTF8.String(key) + ": " + UTF8.String(entry.getColBytes(1, false)) + " in test table");if (table_reference != null) {entry = table_reference.get(key, false);if (entry == null)System.out.println("missing value for entry " + UTF8.String(key) + " in reference table");else- if (!ByteBuffer.equals(entry.getColBytes(1, false), key)) System.out.println("wrong value for entry " + UTF8.String(key) + ": " + UTF8.String(entry.getColBytes(1, false)) + " in reference table");+ if (!Arrays.equals(entry.getColBytes(1, false), key)) System.out.println("wrong value for entry " + UTF8.String(key) + ": " + UTF8.String(entry.getColBytes(1, false)) + " in reference table");}if (i % 1000 == 0) {diff --git a/source/net/yacy/search/index/Segment.java b/source/net/yacy/search/index/Segment.javaindex 4d43f6dc6..1fa22ff32 100644--- a/source/net/yacy/search/index/Segment.java+++ b/source/net/yacy/search/index/Segment.java@@ -29,6 +29,7 @@ package net.yacy.search.index;import java.io.File;import java.io.IOException;import java.net.MalformedURLException;+import java.util.Arrays;import java.util.Collection;import java.util.Date;import java.util.Iterator;@@ -303,7 +304,7 @@ public class Segment {byte[] hh = new byte[6]; // host hashSystem.arraycopy(refidh, 6, hh, 0, 6);if (ByteBuffer.equals(hh, 0, id, 6, 6)) {- if (acceptSelfReference || !ByteBuffer.equals(refidh, id)) {+ if (acceptSelfReference || !Arrays.equals(refidh, id)) {internalIDs.put(refidh);internal++;}diff --git a/source/net/yacy/search/ranking/ReferenceOrder.java b/source/net/yacy/search/ranking/ReferenceOrder.javaindex 3fc812b5b..8be0c9b7d 100644--- a/source/net/yacy/search/ranking/ReferenceOrder.java+++ b/source/net/yacy/search/ranking/ReferenceOrder.java@@ -26,6 +26,7 @@package net.yacy.search.ranking;+import java.util.Arrays;import java.util.HashMap;import java.util.Iterator;import java.util.Map;@@ -36,7 +37,6 @@ import java.util.concurrent.Semaphore;import net.yacy.cora.document.encoding.ASCII;import net.yacy.cora.document.id.DigestURL;import net.yacy.cora.sorting.ConcurrentScoreMap;-import net.yacy.cora.util.ByteBuffer;import net.yacy.cora.util.ConcurrentLog;import net.yacy.document.LargeNumberCache;import net.yacy.document.Tokenizer;@@ -257,7 +257,7 @@ public class ReferenceOrder {+ ((flags.get(Tokenizer.flag_cat_hasaudio)) ? 255 << this.ranking.coeff_cathasaudio : 0)+ ((flags.get(Tokenizer.flag_cat_hasvideo)) ? 255 << this.ranking.coeff_cathasvideo : 0)+ ((flags.get(Tokenizer.flag_cat_hasapp)) ? 255 << this.ranking.coeff_cathasapp : 0)- + ((ByteBuffer.equals(t.getLanguage(), ASCII.getBytes(this.language))) ? 255 << this.ranking.coeff_language : 0);+ + ((Arrays.equals(t.getLanguage(), ASCII.getBytes(this.language))) ? 255 << this.ranking.coeff_language : 0);//if (searchWords != null) r += (yacyURL.probablyWordURL(t.urlHash(), searchWords) != null) ? 256 << ranking.coeff_appurl : 0;