Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
moved io classes
orbiterbd876eb4b78f
diff --git a/source/de/anomic/kelondro/io/chunks/IOChunksInterface.java b/source/de/anomic/kelondro/io/chunks/IOChunksInterface.javadeleted file mode 100644index c0e3cf8ad..000000000--- a/source/de/anomic/kelondro/io/chunks/IOChunksInterface.java+++ /dev/null@@ -1,62 +0,0 @@-// kelondroIOChunks.java-// ------------------------// part of The Kelondro Database-// (C) by Michael Peter Christen; [email protected]-// first published on http://www.anomic.de-// Frankfurt, Germany, 2005-// created: 11.12.2005-//-// This program is free software; you can redistribute it and/or modify-// it under the terms of the GNU General Public License as published by-// the Free Software Foundation; either version 2 of the License, or-// (at your option) any later version.-//-// This program is distributed in the hope that it will be useful,-// but WITHOUT ANY WARRANTY; without even the implied warranty of-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-// GNU General Public License for more details.-//-// You should have received a copy of the GNU General Public License-// along with this program; if not, write to the Free Software-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA--package de.anomic.kelondro.io.chunks;--import java.io.IOException;--import de.anomic.kelondro.io.random.Writer;---public interface IOChunksInterface {-- // logging support- public String name();-- // reference handling- public Writer getRA();-- // pseudo-native methods:- public long length() throws IOException;- public void readFully(long pos, byte[] b, int off, int len) throws IOException;- public void write(long pos, byte[] b, int off, int len) throws IOException;- public void commit() throws IOException;- public void close() throws IOException;-- // derived methods:- public byte readByte(long pos) throws IOException;- public void writeByte(long pos, int v) throws IOException;-- public short readShort(long pos) throws IOException;- public void writeShort(long pos, int v) throws IOException;-- public int readInt(long pos) throws IOException;- public void writeInt(long pos, int v) throws IOException;-- public long readLong(long pos) throws IOException;- public void writeLong(long pos, long v) throws IOException;-- public void write(long pos, byte[] b) throws IOException;- public void writeSpace(long pos, int spacecount) throws IOException;-- public void deleteOnExit();-}diff --git a/source/de/anomic/kelondro/io/chunks/RandomAccessIOChunks.java b/source/de/anomic/kelondro/io/chunks/RandomAccessIOChunks.javadeleted file mode 100644index ff6e3bef8..000000000--- a/source/de/anomic/kelondro/io/chunks/RandomAccessIOChunks.java+++ /dev/null@@ -1,77 +0,0 @@-// kelondroRAIOChunks.java-// ------------------------// part of The Kelondro Database-// (C) by Michael Peter Christen; [email protected]-// first published on http://www.anomic.de-// Frankfurt, Germany, 2005-// created: 11.12.2004-//-// This program is free software; you can redistribute it and/or modify-// it under the terms of the GNU General Public License as published by-// the Free Software Foundation; either version 2 of the License, or-// (at your option) any later version.-//-// This program is distributed in the hope that it will be useful,-// but WITHOUT ANY WARRANTY; without even the implied warranty of-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-// GNU General Public License for more details.-//-// You should have received a copy of the GNU General Public License-// along with this program; if not, write to the Free Software-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA--package de.anomic.kelondro.io.chunks;--import java.io.IOException;--import de.anomic.kelondro.io.random.Writer;---public final class RandomAccessIOChunks extends AbstractIOChunks implements IOChunksInterface {-- protected Writer ra;-- public RandomAccessIOChunks(final Writer ra, final String name) {- this.name = name;- this.ra = ra;- }-- public Writer getRA() {- return this.ra;- }-- public synchronized long length() throws IOException {- return ra.length();- }-- public synchronized void readFully(long pos, final byte[] b, int off, int len) throws IOException {- if (len == 0) return;- this.ra.seek(pos);- this.ra.readFully(b, off, len);- }-- public synchronized void write(final long pos, final byte[] b, final int off, final int len) throws IOException {- if (len == 0) return;- this.ra.seek(pos);- this.ra.write(b, off, len);- }-- public void commit() throws IOException {- // do nothing here- // this method is used to flush write-buffers- }-- public synchronized void close() throws IOException {- if (this.ra != null) this.ra.close();- this.ra = null;- }-- protected void finalize() throws Throwable {- if (this.ra != null) this.close();- super.finalize();- }-- public void deleteOnExit() {- this.ra.deleteOnExit();- }-}diff --git a/source/de/anomic/kelondro/table/Records.java b/source/de/anomic/kelondro/table/Records.javaindex 69e64d4c6..fd53e5a1f 100644--- a/source/de/anomic/kelondro/table/Records.java+++ b/source/de/anomic/kelondro/table/Records.java@@ -41,14 +41,13 @@ import java.util.logging.Logger;import net.yacy.kelondro.index.Column;import net.yacy.kelondro.index.Row;import net.yacy.kelondro.index.Row.EntryIndex;+import net.yacy.kelondro.io.CachedFileWriter;+import net.yacy.kelondro.io.RandomAccessIO;+import net.yacy.kelondro.io.Writer;import net.yacy.kelondro.logging.Log;import net.yacy.kelondro.order.ByteOrder;import net.yacy.kelondro.order.NaturalOrder;-import de.anomic.kelondro.io.chunks.IOChunksInterface;-import de.anomic.kelondro.io.chunks.RandomAccessIOChunks;-import de.anomic.kelondro.io.random.CachedFileWriter;-import de.anomic.kelondro.io.random.Writer;import de.anomic.kelondro.util.FileUtils;import de.anomic.kelondro.util.kelondroException;@@ -79,8 +78,8 @@ public class Records {// POS_NODES : (USEDC + FREEC) * (overhead + sum(all: COLWIDTHS)) : Node Objects// values that are only present at run-time- public String filename; // the database's file name- protected IOChunksInterface entryFile; // the database file+ public String filename; // the database's file name+ protected RandomAccessIO entryFile; // the database fileprotected int overhead; // OHBYTEC + 4 * OHHANDLEC = size of additional control bytesprotected int headchunksize;// overheadsize + key element column sizeprotected int tailchunksize;// sum(all: COLWIDTHS) minus the size of the key element colum@@ -153,7 +152,6 @@ public class Records {if (finalwrite) synchronized (entryFile) {assert this.USEDC >= 0 : "this.USEDC = " + this.USEDC;entryFile.writeInt(POS_USEDC, this.USEDC);- entryFile.commit();}}@@ -161,7 +159,6 @@ public class Records {synchronized (entryFile) {entryFile.writeInt(POS_FREEC, FREEC);entryFile.writeInt(POS_FREEH, FREEH.index);- entryFile.commit();checkConsistency();}}@@ -177,7 +174,6 @@ public class Records {this.FREEC = 0;entryFile.writeInt(POS_FREEC, FREEC);entryFile.writeInt(POS_FREEH, FREEH.index);- entryFile.commit();} else {this.FREEH = new Handle(freeh);this.FREEC = entryFile.readInt(POS_FREEC);@@ -321,7 +317,6 @@ public class Records {USAGE.FREEH = h;assert ((USAGE.FREEH.index == Handle.NUL) && (USAGE.FREEC == 0)) || seekpos(USAGE.FREEH) < entryFile.length() : "allocateRecord: USAGE.FREEH.index = " + USAGE.FREEH.index;USAGE.writefree();- entryFile.commit();}assert (index <= USAGE.allCount());@@ -330,7 +325,6 @@ public class Records {entryFile.write(seekpos(index), bulkchunk, offset, recordsize); // write chunk and occupy spaceUSAGE.USEDC++;USAGE.writeused(false);- entryFile.commit();}}}@@ -353,7 +347,7 @@ public class Records {if (!(file.exists())) return 0;try {final Writer ra = new CachedFileWriter(new File(file.getCanonicalPath()));- final IOChunksInterface entryFile = new RandomAccessIOChunks(ra, ra.name());+ final RandomAccessIO entryFile = new RandomAccessIO(ra, ra.name());final int used = entryFile.readInt(POS_USEDC); // works only if consistency with file size is givenentryFile.close();@@ -425,7 +419,7 @@ public class Records {private void initNewFile(final Writer ra, final int FHandles, final int txtProps) throws IOException {// create new Chunked IO- this.entryFile = new RandomAccessIOChunks(ra, ra.name());+ this.entryFile = new RandomAccessIO(ra, ra.name());// store dynamic run-time datathis.overhead = this.OHBYTEC + 4 * this.OHHANDLEC;@@ -477,8 +471,6 @@ public class Records {for (int i = 0; i < this.TXTPROPS.length; i++) {entryFile.write(POS_TXTPROPS + TXTPROPW * i, ea);}-- this.entryFile.commit();}public void setDescription(final byte[] description) throws IOException {@@ -525,7 +517,7 @@ public class Records {/*if (useBuffer) {this.entryFile = new BufferedIOChunks(ra, ra.name(), 1024*1024, 30000 + random.nextLong() % 30000);} else {*/- this.entryFile = new RandomAccessIOChunks(ra, ra.name());+ this.entryFile = new RandomAccessIO(ra, ra.name());//}// read dynamic variables that are back-ups of stored values in file;@@ -1205,29 +1197,23 @@ public class Records {public synchronized void commit() throws IOException {// this must be called after all write operations to the node are finished-- // place the data to the file-- final boolean doCommit = this.ohChanged || this.bodyChanged;// save headsynchronized (entryFile) {- if (this.ohChanged) {- //System.out.println("WRITEH(" + filename + ", " + seekpos(this.handle) + ", " + this.headChunk.length + ")");- assert (ohChunk == null) || (ohChunk.length == overhead);- entryFile.write(seekpos(this.handle), (this.ohChunk == null) ? new byte[overhead] : this.ohChunk);- this.ohChanged = false;- }-- // save tail- if ((this.bodyChunk != null) && (this.bodyChanged)) {- //System.out.println("WRITET(" + filename + ", " + (seekpos(this.handle) + headchunksize) + ", " + this.tailChunk.length + ")");- assert (this.bodyChunk == null) || (this.bodyChunk.length == ROW.objectsize);- entryFile.write(seekpos(this.handle) + overhead, (this.bodyChunk == null) ? new byte[ROW.objectsize] : this.bodyChunk);- this.bodyChanged = false;- }-- if (doCommit) entryFile.commit();+ if (this.ohChanged) {+ //System.out.println("WRITEH(" + filename + ", " + seekpos(this.handle) + ", " + this.headChunk.length + ")");+ assert (ohChunk == null) || (ohChunk.length == overhead);+ entryFile.write(seekpos(this.handle), (this.ohChunk == null) ? new byte[overhead] : this.ohChunk);+ this.ohChanged = false;+ }++ // save tail+ if ((this.bodyChunk != null) && (this.bodyChanged)) {+ //System.out.println("WRITET(" + filename + ", " + (seekpos(this.handle) + headchunksize) + ", " + this.tailChunk.length + ")");+ assert (this.bodyChunk == null) || (this.bodyChunk.length == ROW.objectsize);+ entryFile.write(seekpos(this.handle) + overhead, (this.bodyChunk == null) ? new byte[ROW.objectsize] : this.bodyChunk);+ this.bodyChanged = false;+ }}}diff --git a/source/de/anomic/kelondro/table/Table.java b/source/de/anomic/kelondro/table/Table.javaindex f5802e854..e374ae5f3 100644--- a/source/de/anomic/kelondro/table/Table.java+++ b/source/de/anomic/kelondro/table/Table.java@@ -45,12 +45,12 @@ import net.yacy.kelondro.index.Row;import net.yacy.kelondro.index.RowCollection;import net.yacy.kelondro.index.RowSet;import net.yacy.kelondro.index.Row.Entry;+import net.yacy.kelondro.io.BufferedRecords;+import net.yacy.kelondro.io.Records;import net.yacy.kelondro.logging.Log;import net.yacy.kelondro.order.CloneableIterator;import net.yacy.kelondro.order.NaturalOrder;-import de.anomic.kelondro.io.records.BufferedRecords;-import de.anomic.kelondro.io.records.Records;import de.anomic.kelondro.util.FileUtils;import de.anomic.kelondro.util.MemoryControl;import de.anomic.kelondro.util.kelondroException;diff --git a/source/net/yacy/kelondro/blob/Heap.java b/source/net/yacy/kelondro/blob/Heap.javaindex aa8b0c2ad..1ae4e0532 100755--- a/source/net/yacy/kelondro/blob/Heap.java+++ b/source/net/yacy/kelondro/blob/Heap.java@@ -32,11 +32,11 @@ import java.util.HashMap;import java.util.Iterator;import java.util.Map;+import net.yacy.kelondro.io.AbstractWriter;import net.yacy.kelondro.order.ByteOrder;import net.yacy.kelondro.order.CloneableIterator;import net.yacy.kelondro.order.NaturalOrder;-import de.anomic.kelondro.io.random.AbstractWriter;public final class Heap extends HeapModifier implements BLOB {diff --git a/source/net/yacy/kelondro/blob/HeapModifier.java b/source/net/yacy/kelondro/blob/HeapModifier.javaindex e65e7ddbc..423712cda 100644--- a/source/net/yacy/kelondro/blob/HeapModifier.java+++ b/source/net/yacy/kelondro/blob/HeapModifier.java@@ -28,10 +28,10 @@ import java.io.File;import java.io.IOException;import java.util.SortedMap;+import net.yacy.kelondro.io.CachedFileWriter;import net.yacy.kelondro.logging.Log;import net.yacy.kelondro.order.ByteOrder;-import de.anomic.kelondro.io.random.CachedFileWriter;import de.anomic.kelondro.util.FileUtils;import de.anomic.kelondro.util.MemoryControl;diff --git a/source/net/yacy/kelondro/blob/HeapReader.java b/source/net/yacy/kelondro/blob/HeapReader.javaindex 05de6bfac..154e2da0b 100644--- a/source/net/yacy/kelondro/blob/HeapReader.java+++ b/source/net/yacy/kelondro/blob/HeapReader.java@@ -35,13 +35,13 @@ import java.util.Map.Entry;import java.util.concurrent.ExecutionException;import net.yacy.kelondro.index.HandleMap;+import net.yacy.kelondro.io.CachedFileWriter;+import net.yacy.kelondro.io.Writer;import net.yacy.kelondro.logging.Log;import net.yacy.kelondro.order.ByteOrder;import net.yacy.kelondro.order.CloneableIterator;import net.yacy.kelondro.order.RotateIterator;-import de.anomic.kelondro.io.random.CachedFileWriter;-import de.anomic.kelondro.io.random.Writer;import de.anomic.kelondro.util.FileUtils;import de.anomic.kelondro.util.MemoryControl;diff --git a/source/de/anomic/kelondro/io/random/AbstractReader.java b/source/net/yacy/kelondro/io/AbstractReader.javasimilarity index 98%rename from source/de/anomic/kelondro/io/random/AbstractReader.javarename to source/net/yacy/kelondro/io/AbstractReader.javaindex 5a27f656e..f2ad6537f 100644--- a/source/de/anomic/kelondro/io/random/AbstractReader.java+++ b/source/net/yacy/kelondro/io/AbstractReader.java@@ -22,7 +22,7 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.kelondro.io.random;+package net.yacy.kelondro.io;import java.io.File;import java.io.IOException;diff --git a/source/de/anomic/kelondro/io/random/AbstractWriter.java b/source/net/yacy/kelondro/io/AbstractWriter.javasimilarity index 96%rename from source/de/anomic/kelondro/io/random/AbstractWriter.javarename to source/net/yacy/kelondro/io/AbstractWriter.javaindex 26095c839..f40ec4aec 100644--- a/source/de/anomic/kelondro/io/random/AbstractWriter.java+++ b/source/net/yacy/kelondro/io/AbstractWriter.java@@ -22,7 +22,7 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.kelondro.io.random;+package net.yacy.kelondro.io;import java.io.BufferedReader;import java.io.ByteArrayInputStream;diff --git a/source/de/anomic/kelondro/io/records/BufferedRecords.java b/source/net/yacy/kelondro/io/BufferedRecords.javasimilarity index 99%rename from source/de/anomic/kelondro/io/records/BufferedRecords.javarename to source/net/yacy/kelondro/io/BufferedRecords.javaindex a5bf2d8a0..ecefd47ef 100644--- a/source/de/anomic/kelondro/io/records/BufferedRecords.java+++ b/source/net/yacy/kelondro/io/BufferedRecords.java@@ -22,7 +22,7 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.kelondro.io.records;+package net.yacy.kelondro.io;import java.io.File;import java.io.IOException;diff --git a/source/de/anomic/kelondro/io/random/CachedFileReader.java b/source/net/yacy/kelondro/io/CachedFileReader.javasimilarity index 98%rename from source/de/anomic/kelondro/io/random/CachedFileReader.javarename to source/net/yacy/kelondro/io/CachedFileReader.javaindex bf014a5ec..ca5b04807 100644--- a/source/de/anomic/kelondro/io/random/CachedFileReader.java+++ b/source/net/yacy/kelondro/io/CachedFileReader.java@@ -18,7 +18,7 @@// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.kelondro.io.random;+package net.yacy.kelondro.io;import java.io.File;import java.io.FileNotFoundException;diff --git a/source/de/anomic/kelondro/io/random/CachedFileWriter.java b/source/net/yacy/kelondro/io/CachedFileWriter.javasimilarity index 96%rename from source/de/anomic/kelondro/io/random/CachedFileWriter.javarename to source/net/yacy/kelondro/io/CachedFileWriter.javaindex daafaebbb..85f7cf491 100644--- a/source/de/anomic/kelondro/io/random/CachedFileWriter.java+++ b/source/net/yacy/kelondro/io/CachedFileWriter.java@@ -20,7 +20,7 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.kelondro.io.random;+package net.yacy.kelondro.io;import java.io.File;import java.io.FileNotFoundException;diff --git a/source/de/anomic/kelondro/io/chunks/AbstractIOChunks.java b/source/net/yacy/kelondro/io/RandomAccessIO.javasimilarity index 71%rename from source/de/anomic/kelondro/io/chunks/AbstractIOChunks.javarename to source/net/yacy/kelondro/io/RandomAccessIO.javaindex 134c53468..4b3ad0ef7 100644--- a/source/de/anomic/kelondro/io/chunks/AbstractIOChunks.java+++ b/source/net/yacy/kelondro/io/RandomAccessIO.java@@ -1,10 +1,10 @@-// kelondroAbstractIOChunks.java+// RandomAccessIO.java// -----------------------// part of The Kelondro Database// (C) by Michael Peter Christen; [email protected]// first published on http://www.anomic.de// Frankfurt, Germany, 2005-// created: 11.12.2005+// created: 11.12.2004//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by@@ -20,26 +20,47 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.kelondro.io.chunks;+package net.yacy.kelondro.io;import java.io.IOException;-public abstract class AbstractIOChunks implements IOChunksInterface {+public final class RandomAccessIO {- // logging support+ protected Writer ra;++ public RandomAccessIO(final Writer ra, final String name) {+ this.name = name;+ this.ra = ra;+ }++ public Writer getRA() {+ return this.ra;+ }++ public synchronized long length() throws IOException {+ return ra.length();+ }++ public synchronized void readFully(long pos, final byte[] b, int off, int len) throws IOException {+ if (len == 0) return;+ this.ra.seek(pos);+ this.ra.readFully(b, off, len);+ }++ public synchronized void write(final long pos, final byte[] b, final int off, final int len) throws IOException {+ if (len == 0) return;+ this.ra.seek(pos);+ this.ra.write(b, off, len);+ }++ // logging supportprotected String name = null;public String name() {return name;}- // pseudo-native methods:- abstract public long length() throws IOException;- abstract public void write(long pos, byte[] b, int off, int len) throws IOException;- abstract public void close() throws IOException;- abstract public void readFully(long pos, final byte[] b, int off, int len) throws IOException;-public synchronized byte readByte(final long pos) throws IOException {final byte[] b = new byte[1];this.readFully(pos, b, 0, 1);@@ -100,24 +121,37 @@ public abstract class AbstractIOChunks implements IOChunksInterface {public synchronized void writeSpace(long pos, int spaceCount) throws IOException {if (spaceCount < 512) {- write(pos, space(spaceCount));- return;+ write(pos, space(spaceCount));+ return;}byte[] b = space(512);while (spaceCount > b.length) {- write(pos, b);- pos += b.length;- spaceCount -= b.length;+ write(pos, b);+ pos += b.length;+ spaceCount -= b.length;}if (spaceCount > 0) {- write(pos, space(spaceCount));+ write(pos, space(spaceCount));}}private byte[] space(int count) {- byte[] s = new byte[count];- while (count-- > 0) s[count] = 0;- return s;+ byte[] s = new byte[count];+ while (count-- > 0) s[count] = 0;+ return s;+ }++ public synchronized void close() throws IOException {+ if (this.ra != null) this.ra.close();+ this.ra = null;+ }++ protected void finalize() throws Throwable {+ if (this.ra != null) this.close();+ super.finalize();}-}\ No newline at end of file+ public void deleteOnExit() {+ this.ra.deleteOnExit();+ }+}diff --git a/source/de/anomic/kelondro/io/random/Reader.java b/source/net/yacy/kelondro/io/Reader.javasimilarity index 97%rename from source/de/anomic/kelondro/io/random/Reader.javarename to source/net/yacy/kelondro/io/Reader.javaindex 520cf4d1c..6b71937f3 100644--- a/source/de/anomic/kelondro/io/random/Reader.java+++ b/source/net/yacy/kelondro/io/Reader.java@@ -18,7 +18,7 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.kelondro.io.random;+package net.yacy.kelondro.io;import java.io.File;import java.io.IOException;diff --git a/source/de/anomic/kelondro/io/records/Records.java b/source/net/yacy/kelondro/io/Records.javasimilarity index 99%rename from source/de/anomic/kelondro/io/records/Records.javarename to source/net/yacy/kelondro/io/Records.javaindex b5b4a4431..97f472eff 100644--- a/source/de/anomic/kelondro/io/records/Records.java+++ b/source/net/yacy/kelondro/io/Records.java@@ -22,7 +22,7 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.kelondro.io.records;+package net.yacy.kelondro.io;import java.io.File;import java.io.FileNotFoundException;diff --git a/source/de/anomic/kelondro/io/random/Writer.java b/source/net/yacy/kelondro/io/Writer.javasimilarity index 95%rename from source/de/anomic/kelondro/io/random/Writer.javarename to source/net/yacy/kelondro/io/Writer.javaindex edf177bbb..2c66e7f77 100644--- a/source/de/anomic/kelondro/io/random/Writer.java+++ b/source/net/yacy/kelondro/io/Writer.java@@ -18,7 +18,7 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-package de.anomic.kelondro.io.random;+package net.yacy.kelondro.io;import java.io.IOException;import java.util.HashMap;