moved io classes

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6396 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 16 years ago
parent c0e0e1f422
commit bd876eb4b7

@ -1,62 +0,0 @@
// kelondroIOChunks.java
// -----------------------
// part of The Kelondro Database
// (C) by Michael Peter Christen; mc@yacy.net
// 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();
}

@ -1,77 +0,0 @@
// kelondroRAIOChunks.java
// -----------------------
// part of The Kelondro Database
// (C) by Michael Peter Christen; mc@yacy.net
// 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();
}
}

@ -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 file
protected int overhead; // OHBYTEC + 4 * OHHANDLEC = size of additional control bytes
protected int headchunksize;// overheadsize + key element column size
protected 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 space
USAGE.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 given
entryFile.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 data
this.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 head
synchronized (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;
}
}
}

@ -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;

@ -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 {

@ -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;

@ -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;

@ -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;

@ -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;

@ -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;

@ -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;

@ -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;

@ -1,10 +1,10 @@
// kelondroAbstractIOChunks.java
// RandomAccessIO.java
// -----------------------
// part of The Kelondro Database
// (C) by Michael Peter Christen; mc@yacy.net
// 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 support
protected 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();
}
}
public void deleteOnExit() {
this.ra.deleteOnExit();
}
}

@ -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;

@ -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;

@ -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;
Loading…
Cancel
Save