return (int) (newpos - pos);
}
- public final int readByte(){
+ public final byte readByte(){
byte[] data = new byte[1];
read(data);
- int result = (byte)(data[0]);
+ byte result = (byte)(data[0]);
return result;
}
- public final int readChar(){
+ public final boolean readBoolean(){
+ byte[] data = new byte[1];
+ read(data);
+ if (data[0] == 0 )
+ return false;
+ return true;
+ //return ((boolean)data[0]);// != 0);
+ }
+
+ public final char readChar(){
byte[] data = new byte[2];
read(data);
- int result = (char)((data[0] << 8) | data[0]);
+ char result = (char)((data[0] << 8) | data[0]);
return result;
}
- public final int readShort(){
+ public final short readShort(){
byte[] data = new byte[2];
read(data);
- int result = (short)((data[0] << 8) | data[1]);
- System.out.println("res " + result);
+ short result = (short)((data[0] << 8) | data[1]);
+ // System.out.println("res " + result);
return result;
}
+ public final int readUnsignedShort() throws IOException {
+ byte[] data = new byte[2];
+ read(data);
+ return (data[0] << 8) + (data[1] << 0);
+ }
+
+ public final String readUTF() throws UTFDataFormatException{
+ int utflen = -1;
+ byte[] bytearr = null;
+ char[] chararr = null;
+ try {
+ utflen = readUnsignedShort();
+ } catch (IOException ex) {
+ Logger.getLogger(TransactionalFile.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ bytearr = new byte[utflen];
+ chararr = new char[utflen];
+
+
+ int c, char2, char3;
+ int count = 0;
+ int chararr_count = 0;
+
+ read(bytearr);
+
+ while (count < utflen) {
+ c = (int) bytearr[count] & 0xff;
+ if (c > 127)
+ break;
+ count++;
+ chararr[chararr_count++] = (char) c;
+ }
+
+ while (count < utflen) {
+ c = (int) bytearr[count] & 0xff;
+ switch (c >> 4) {
+ case 0:
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ /* 0xxxxxxx*/
+ count++;
+ chararr[chararr_count++] = (char) c;
+ break;
+ case 12:
+ case 13:
+ /* 110x xxxx 10xx xxxx*/
+ count += 2;
+ if (count > utflen)
+ throw new UTFDataFormatException(
+ "malformed input: partial character at end");
+ char2 = (int) bytearr[count - 1];
+ if ((char2 & 0xC0) != 0x80)
+ throw new UTFDataFormatException(
+ "malformed input around byte " + count);
+ chararr[chararr_count++] = (char) (((c & 0x1F) << 6) | (char2 & 0x3F));
+ break;
+ case 14:
+ /* 1110 xxxx 10xx xxxx 10xx xxxx */
+ count += 3;
+ if (count > utflen)
+ throw new UTFDataFormatException(
+ "malformed input: partial character at end");
+ char2 = (int) bytearr[count - 2];
+ char3 = (int) bytearr[count - 1];
+ if (((char2 & 0xC0) != 0x80)
+ || ((char3 & 0xC0) != 0x80))
+ throw new UTFDataFormatException(
+ "malformed input around byte "
+ + (count - 1));
+ chararr[chararr_count++] = (char) (((c & 0x0F) << 12)
+ | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0));
+ break;
+ default:
+ /* 10xx xxxx, 1111 xxxx */
+ throw new UTFDataFormatException(
+ "malformed input around byte " + count);
+ }
+ }
+ // The number of chars produced may be less than utflen
+ return new String(chararr, 0, chararr_count);
+
+ }
+
+ public final float readFloat(){
+ // byte[] data = new byte[4];
+ // int k = read(data);
+ return Float.intBitsToFloat(readInt());
+ // float result = Conversions.bytes2float(data);
+ //int result = (data[0] << 24) | (data[1] << 16) + (data[2] << 8) + (data[3]<<0);
+ // System.out.println("int res " + result);
+ // return result;
+ }
+
+ public final double readDouble(){
+ return Double.longBitsToDouble(readLong());
+ }
+
public final int readInt(){
byte[] data = new byte[4];
int result = Conversions.bytes2int(data);
//int result = (data[0] << 24) | (data[1] << 16) + (data[2] << 8) + (data[3]<<0);
- System.out.println("int res " + result);
+ // System.out.println("int res " + result);
return result;
}
read(data);
//long result = ((long)data[0] << 56) + ((long)data[1] << 48) + ((long)data[2] << 40) + ((long)data[3] << 32) + ((long)data[4] << 24) + ((long)data[5] << 16)+ ((long)data[6] << 8) + data[7];
long result = Conversions.bytes2long(data);
- System.out.println("long res " + result);
+ // System.out.println("long res " + result);
return result;
}
TableIndexEntry entry=null;
// Handle index entry caching
if(INDEXCACHESIZE>0){
+ // System.out.println("in h");
synchronized(indexcache){
entry=getCacheEntry(id);
+ // System.out.println(entry);
if(entry==null){
entry=index.scanIndex(id);
if(entry!=null){
if(entry!=null){
long dataoffset=0;
DataInputStream data=null;
+ // System.out.println(entry);
if(entry.location==Table.FILEA){
data=new DataInputStream(new BufferedInputStream(new FileInputStream(getFileName(Table.FILEA))));
}else if(entry.location==Table.FILEB){
args.add(row);
Thread.doIt(new Callable<Boolean>() {
public Boolean call() throws Exception{
- openFile(FILEA);
+
+ openFile(FILEA);
+
//int pre=fileastream.size();
int pre= (int)fileastream.getFilePointer();
//row.writeToStream(fileastream);
TableIndexEntryTransactional entry=new TableIndexEntryTransactional(((RowTransactional)args.get(0)).getId(),((RowTransactional)args.get(0)).getSize(),FILEA,atomicfields.getFileaposition());
addCacheEntry(entry);
}
- atomicfields.setFileaposition(atomicfields.getFileaposition()+Row.calcSize(pre,post));
+ atomicfields.setFileaposition(atomicfields.getFileaposition()+RowTransactional.calcSize(pre,post));
return true;
}
});
TableIndexEntryTransactional entry=new TableIndexEntryTransactional(((RowTransactional)args.get(0)).getId(),((RowTransactional)args.get(0)).getSize(),FILEB,atomicfields.getFilebposition());
addCacheEntry(entry);
}
- atomicfields.setFilebposition(atomicfields.getFilebposition()+Row.calcSize(pre,post));
+ atomicfields.setFilebposition(atomicfields.getFilebposition()+RowTransactional.calcSize(pre,post));
return true;
}
});
TableIndexEntryTransactional entry=null;
final Vector args = new Vector();
args.add(row);
- args.add(entry);
+ //args.add(entry);
// Handle index entry caching
if(INDEXCACHESIZE>0){
- Thread.doIt(new Callable<Boolean>() {
- public Boolean call() throws Exception {
- TableIndexEntryTransactional entry = (TableIndexEntryTransactional) (args.get(1));
+ entry = Thread.doIt(new Callable<TableIndexEntryTransactional>() {
+ public TableIndexEntryTransactional call() throws Exception {
+ TableIndexEntryTransactional entry;// = (TableIndexEntryTransactional) (args.get(1));
RowTransactional row = (RowTransactional) (args.get(0));
entry = getCacheEntry(row.getId());
if(entry==null){
entry=index.scanIndex(row.getId());
addCacheEntry(entry);
}
- return true;
+ return entry;
}
});
/* synchronized(indexcache){
private void updateRowA(RowTransactional row) throws IOException{
final Vector args = new Vector();
args.add(row);
+ System.out.println("b");
Thread.doIt(new Callable<Boolean>() {
public Boolean call() throws Exception{
//synchronized(filealock){
+ System.out.println("add a");
openFile(FILEA);
//int pre=filebstream.size();
int pre=(int)fileastream.getFilePointer();
private void updateRowB(RowTransactional row) throws IOException{
final Vector args = new Vector();
+ System.out.println("b");
args.add(row);
Thread.doIt(new Callable<Boolean>() {
public Boolean call() throws Exception{
-
+ System.out.println("add b");
//synchronized(fileblock){
openFile(FILEB);
//int pre=filebstream.size();
*/
public RowTransactional getRow(String id) throws IOException{
TableIndexEntryTransactional entry=null;
+ final Vector args = new Vector();
+ args.add(id);
+ // args.add(entry);
// Handle index entry caching
if(INDEXCACHESIZE>0){
- final Vector args = new Vector();
- args.add(id);
- args.add(entry);
+
//synchronized(indexcache){
- Thread.doIt(new Callable<Boolean>() {
- public Boolean call() throws Exception{
- TableIndexEntryTransactional entry = (TableIndexEntryTransactional) (args.get(1));
+ entry = Thread.doIt(new Callable<TableIndexEntryTransactional>() {
+ public TableIndexEntryTransactional call() throws Exception{
+ TableIndexEntryTransactional entry;// = (TableIndexEntryTransactional) (args.get(1));
String id = (String) (args.get(0));
entry=getCacheEntry(id);
+ // System.out.println("presalam " + (TableIndexEntryTransactional) (args.get(1)));
if(entry==null){
entry=index.scanIndex(id);
if(entry!=null){
addCacheEntry(entry);
}
}
- return true;
+ return entry;
}
});
}else{
entry=index.scanIndexTransactional(id);
}
+// entry = (TableIndexEntryTransactional) (args.get(1));
+ // args.clear();
+
if(entry!=null){
long dataoffset=0;
- DataInputStream data=null;
- if(entry.getLocation()==Table.FILEA){
- data=new DataInputStream(new BufferedInputStream(new FileInputStream(getFileName(Table.FILEA))));
- }else if(entry.getLocation()==Table.FILEB){
- data=new DataInputStream(new BufferedInputStream(new FileInputStream(getFileName(Table.FILEB))));
+ //DataInputStream data=null;
+ TransactionalFile data=null;
+ if(entry.getLocation()==TableTransactional.FILEA){
+ //data=new DataInputStream(new BufferedInputStream(new FileInputStream(getFileName(TableTransactional.FILEA))));
+ data=new TransactionalFile(getFileName(TableTransactional.FILEA), "rw");
+ }else if(entry.getLocation()==TableTransactional.FILEB){
+ data=new TransactionalFile(getFileName(TableTransactional.FILEB), "rw");
+ //data=new DataInputStream(new BufferedInputStream(new FileInputStream(getFileName(TableTransactional.FILEB))));
}
if(data!=null){
while(dataoffset!=entry.getPosition()){
}
RowTransactional row=RowTransactional.readFromStream(data);
data.close();
- final Vector args = new Vector();
- args.add(row);
+ final Vector args2 = new Vector();
+ args2.add(row);
Thread.doIt(new Callable<Boolean>() {
public Boolean call() throws Exception{
//synchronized(statlock){
atomicfields.setstat_read(atomicfields.getstat_read()+1);
- atomicfields.setstat_read_size(atomicfields.getstat_read_size()+((RowTransactional)args.get(0)).getSize());
+ atomicfields.setstat_read_size(atomicfields.getstat_read_size()+((RowTransactional)args2.get(0)).getSize());
return true;
}
});
package com.solidosystems.tuplesoup.core;
+import TransactionalIO.core.TransactionalFile;
import com.solidosystems.tuplesoup.filter.*;
import java.io.*;
import java.util.*;
public class IndexedTableReaderTransactional extends TupleStreamTransactional{
- private DataInputStream fileastream=null;
- private DataInputStream filebstream=null;
+ private TransactionalFile fileastream=null;
+ private TransactionalFile filebstream=null;
+
+ //private DataInputStream fileastream=null;
+ //private DataInputStream filebstream=null;
private long fileaposition=0;
private long filebposition=0;
TableIndexEntryTransactional entry=it.next();
// TODO: we really shouldn't get nulls here
if(entry!=null){
- if(entry.getLocation()==Table.FILEA){
+ if(entry.getLocation()==TableTransactional.FILEA){
fileaentries.add(entry);
- }else if(entry.getLocation()==Table.FILEB){
+ }else if(entry.getLocation()==TableTransactional.FILEB){
filebentries.add(entry);
}
}
TableIndexEntryTransactional entry=it.next();
// TODO: we really shouldn't get nulls here
if(entry!=null){
- if(entry.getLocation()==Table.FILEA){
+ if(entry.getLocation()==TableTransactional.FILEA){
fileaentries.add(entry);
- }else if(entry.getLocation()==Table.FILEB){
+ }else if(entry.getLocation()==TableTransactional.FILEB){
filebentries.add(entry);
}
}
if(fileaentries.size()>0){
TableIndexEntryTransactional nextfilea=fileaentries.remove(0);
if(fileastream==null){
- fileastream=new DataInputStream(new BufferedInputStream(new FileInputStream(table.getFileName(Table.FILEA))));
+ fileastream=new TransactionalFile(table.getFileName(TableTransactional.FILEA), "rw");
+ // fileastream=new DataInputStream(new BufferedInputStream(new FileInputStream(table.getFileName(TableTransactional.FILEA))));
fileaposition=0;
}
if(fileaposition>nextfilea.getPosition()){
if(filebentries.size()>0){
TableIndexEntryTransactional nextfileb=filebentries.remove(0);
if(filebstream==null){
- filebstream=new DataInputStream(new BufferedInputStream(new FileInputStream(table.getFileName(Table.FILEB))));
+ fileastream=new TransactionalFile(table.getFileName(TableTransactional.FILEB), "rw");
+ //filebstream=new DataInputStream(new BufferedInputStream(new FileInputStream(table.getFileName(TableTransactional.FILEB))));
filebposition=0;
}
if(filebposition>nextfileb.getPosition()){
TableIndexEntryTransactional entry=entries.get(rowpointer++);
if(entry!=null){
switch(entry.getLocation()){
- case Table.FILEA : readNextFromFileA(entry);
+ case TableTransactional.FILEA : readNextFromFileA(entry);
// return;
break;
- case Table.FILEB : readNextFromFileB(entry);
+ case TableTransactional.FILEB : readNextFromFileB(entry);
// return;
break;
}
public class PagedIndex implements TableIndex{
-protected static final int INITIALPAGEHASH=1024;
- protected static final int PAGESIZE=2048;
+//protected static final int INITIALPAGEHASH=1024;
+ // protected static final int PAGESIZE=2048;
+
+ protected static final int INITIALPAGEHASH=32;
+ protected static final int PAGESIZE=64;
private RandomAccessFile out=null;
private String filename;
for(int i=0;i<INITIALPAGEHASH;i++){
root[i]=new TableIndexPage(this,out);
root[i].setFirst();
- System.out.println("In loop " + root[i].getEndLocation());
out.seek(root[i].getEndLocation());
}
}else{
for(int i=0;i<INITIALPAGEHASH;i++){
root[i]=TableIndexPage.createNewPage(this,out,PAGESIZE);
- System.out.println("In Othe loop " + root[i].getEndLocation());
root[i].setFirst();
}
}
private TransactionalFile out=null;
- protected static final int INITIALPAGEHASH=1024;
- protected static final int PAGESIZE=2048;
+
+ //protected static final int INITIALPAGEHASH=1024;
+ //protected static final int PAGESIZE=2048;
+
+ protected static final int INITIALPAGEHASH=32;
+ protected static final int PAGESIZE=64;
public PagedIndexTransactional(String filename) throws IOException{
atomicfields = factory.create();
if(!ftest.exists())ftest.createNewFile();
out=new TransactionalFile(filename,"rw");
atomicfields.setRoots(new AtomicArray<TableIndexPageTransactional>(TableIndexPageTransactional.class, INITIALPAGEHASH));
- System.out.println(filename);
- System.out.println(out.length());
+ // System.out.println(filename);
+ // System.out.println(out.length());
if(out.length()>0){
for(int i=0;i<INITIALPAGEHASH;i++){
atomicfields.getRoots().set(i, new TableIndexPageTransactional(this,out));
atomicfields.getRoots().get(i).setFirst();
- System.out.println("In loop " + atomicfields.getRoots().get(i).getEndLocation());
+ // System.out.println("In loop " + atomicfields.getRoots().get(i).getEndLocation());
out.seek(atomicfields.getRoots().get(i).getEndLocation());
}
}else{
for(int i=0;i<INITIALPAGEHASH;i++){
atomicfields.getRoots().set(i, TableIndexPageTransactional.createNewPage(this,out,PAGESIZE));
- System.out.println("In Othe loop " + atomicfields.getRoots().get(i).getEndLocation());
+ // System.out.println("In Othe loop " + atomicfields.getRoots().get(i).getEndLocation());
atomicfields.getRoots().get(i).setFirst();
}
}
});
}
- public synchronized List<TableIndexEntryTransactional> scanIndex(List<String> rows) throws IOException{
+ public /*synchronized*/ List<TableIndexEntryTransactional> scanIndex(List<String> rows) throws IOException{
final List<String> rows2 = rows;
return Thread.doIt(new Callable<List<TableIndexEntryTransactional>>() {
public List<TableIndexEntryTransactional> call() throws Exception{
String id=rows2.get(i);
TableIndexEntryTransactional entry=scanIndex(id);
if(entry!=null){
- if(entry.getLocation()!=Table.DELETE)lst.add(entry);
+ if(entry.getLocation()!=TableTransactional.DELETE)lst.add(entry);
}
}
return lst;
return Thread.doIt(new Callable<List<TableIndexEntryTransactional>>() {
public List<TableIndexEntryTransactional> call() throws Exception{
ArrayList<TableIndexEntryTransactional> lst=new ArrayList<TableIndexEntryTransactional>();
+ System.out.println(Thread.currentThread() + " start");
for(int i=0;i<INITIALPAGEHASH;i++){
atomicfields.getRoots().get(i).addEntriesToList(lst);
}
+ System.out.println(Thread.currentThread() +" done");
return lst;
}
});
/**
* Reads a full row from the given DataInputStream and returns it.
*/
- public static RowTransactional readFromStream(DataInputStream in) throws IOException{
+ /*public static RowTransactional readFromStream(DataInputStream in) throws IOException{
String id=in.readUTF();
+ //System.out.println("id " + id);
+ RowTransactional row=new RowTransactional(id);
+ int size=in.readInt();
+ for(int i=0;i<size;i++){
+ String key=in.readUTF();
+ ValueTransactional value=ValueTransactional.readFromStream(in);
+ row.put(key,value);
+ }
+ size=in.readInt();
+ row.atomicfields.setSize(size);
+ return row;
+ }*/
+
+ public static RowTransactional readFromStream(TransactionalFile in) throws IOException{
+ String id=in.readUTF();
+ //System.out.println("id " + id);
RowTransactional row=new RowTransactional(id);
int size=in.readInt();
for(int i=0;i<size;i++){
return row;
}
+
/**
* Returns a string representing this row formatted as the following example:
* (1732)=>{"name":string:"Kasper J. Jeppesen","age":int:31}
protected static TableIndexEntryTransactional readData(TransactionalFile in) throws IOException{
long pre=in.getFilePointer();
in.readInt();
+ //short num=in.readShort();
int num=in.readShort();
//System.out.println("num= " + num);
StringBuilder buf=new StringBuilder(num);
this.index=index;
first=false;
location=file.getFilePointer();
- System.out.println(location);
size=file.readInt();
next=file.readLong();
lower=file.readLong();
offset=file.readInt();
endhash=file.readInt();
- System.out.println("si " + size);
- System.out.println("next " + next);
- System.out.println("lower " + lower);
- System.out.println("offset " + offset);
- System.out.println("endhash " + endhash);
+ // System.out.println("si " + size);
+ // System.out.println("next " + next);
+ // System.out.println("lower " + lower);
+ // System.out.println("offset " + offset);
+ // System.out.println("endhash " + endhash);
if(offset>0)starthash=file.readInt();
- System.out.println("here tav;eindepage");
+ // System.out.println("here tav;eindepage");
}
public static TableIndexPage createNewPage(PagedIndex index,RandomAccessFile file,int size) throws IOException{
long pre=file.length();
- System.out.println("pre " + pre);
- System.out.println("pointer1 " + file.length()+size+BASEOFFSET);
+
file.setLength(file.length()+size+BASEOFFSET);
file.seek(pre);
- System.out.println("pointer2 " + file.getFilePointer());
- file.writeInt(size);
- System.out.println("pointer2 " + file.getFilePointer());
+
+ file.writeInt(size);
file.writeLong(-1l);
- System.out.println("pointer2 " + file.getFilePointer());
file.writeLong(-1l);
- System.out.println("pointer2 " + file.getFilePointer());
file.writeInt(0);
- System.out.println("pointer2 " + file.getFilePointer());
file.writeInt(-1);
file.seek(pre);
index.stat_create_page++;
}
file.seek(location+BASEOFFSET);
long pre=file.getFilePointer();
+ System.out.println(Thread.currentThread() + " " +offset + " " + pre);
while(file.getFilePointer()<pre+offset){
TableIndexEntry entry=TableIndexEntry.readData(file);
if(entry!=null){
this.atomicfields.setIndex(index);
this.atomicfields.setFirst(false);
this.atomicfields.setLocation(file.getFilePointer());
- System.out.println(file.getFilePointer());
+ // System.out.println(file.getFilePointer());
this.atomicfields.setSize(file.readInt());
- System.out.println(file.getFilePointer());
+ // System.out.println(file.getFilePointer());
this.atomicfields.setNext(file.readLong());
- System.out.println(file.getFilePointer());
+ // System.out.println(file.getFilePointer());
this.atomicfields.setLower(file.readLong());
- System.out.println(file.getFilePointer());
- System.out.println(file.getFilePointer());
+ // System.out.println(file.getFilePointer());
+ // System.out.println(file.getFilePointer());
this.atomicfields.setOffset(file.readInt());
- System.out.println(file.getFilePointer());
+ // System.out.println(file.getFilePointer());
this.atomicfields.setEndhash(file.readInt());
- System.out.println("size " + atomicfields.getSize());
+ // System.out.println("size " + atomicfields.getSize());
System.out.println("next " + atomicfields.getNext());
System.out.println("lower " + atomicfields.getLower());
System.out.println("offset " + atomicfields.getOffset());
public static TableIndexPageTransactional createNewPage(PagedIndexTransactional index,TransactionalFile file,int size) throws IOException{
long pre=file.length();
- System.out.println("pre " + pre);
+ // System.out.println("pre " + pre);
// file.setLength(file.length()+size+BASEOFFSET);
file.seek(pre);
byte[] dummy = new byte[size+BASEOFFSET];
file.write(dummy);
- System.out.println("pointer " + file.getFilePointer());
+ // System.out.println("pointer " + file.getFilePointer());
file.seek(pre);
- System.out.println("pointer2 " + file.getFilePointer());
+ // System.out.println("pointer2 " + file.getFilePointer());
file.writeInt(size);
- System.out.println("pointer2 " + file.getFilePointer());
+ // System.out.println("pointer2 " + file.getFilePointer());
file.writeLong(-1l);
- System.out.println("pointer2 " + file.getFilePointer());
+ // System.out.println("pointer2 " + file.getFilePointer());
file.writeLong(-1l);
- System.out.println("pointer2 " + file.getFilePointer());
+ // System.out.println("pointer2 " + file.getFilePointer());
file.writeInt(0);
- System.out.println("pointer2 " + file.getFilePointer());
+ // System.out.println("pointer2 " + file.getFilePointer());
file.writeInt(-1);
file.seek(pre);
- file.readInt();
- file.readLong();
- file.readLong();
- file.readInt();
- file.readInt();
- file.seek(pre);
+ // file.readInt();
+ // file.readLong();
+ // file.readLong();
+ // file.readInt();
+ // file.readInt();
+ // file.seek(pre);
//index.atomicfields.setStat_create_page((long)2);
index.atomicfields.setStat_create_page(index.atomicfields.getStat_create_page()+1);
}
file.seek(this.atomicfields.getLocation()+BASEOFFSET);
long pre=file.getFilePointer();
+ // System.out.println(Thread.currentThread() + " " +this.atomicfields.getOffset() + " " + pre);
while(file.getFilePointer()<pre+this.atomicfields.getOffset()){
+
TableIndexEntryTransactional entry=TableIndexEntryTransactional.readData(file);
if(entry!=null){
- if(entry.getLocation()!=Table.DELETE)lst.add(entry);
+ if(entry.getLocation()!=TableTransactional.DELETE)lst.add(entry);
}
}
}
file.seek(this.atomicfields.getLocation()+BASEOFFSET);
long pre=file.getFilePointer();
while(file.getFilePointer()<pre+this.atomicfields.getOffset()){
- System.out.println("neddddxtex " + atomicfields.getNext());
+ //System.out.println("neddddxtex " + atomicfields.getNext());
TableIndexEntryTransactional entry=TableIndexEntryTransactional.lookForData(id,file);
if(entry!=null)return entry;
}
* @param in the DataInputStream the Value should be read from
* @return the Value read from the stream
*/
- public static ValueTransactional readFromStream(DataInputStream in) throws IOException{
+ /* public static ValueTransactional readFromStream(DataInputStream in) throws IOException{
byte type=in.readByte();
switch(type){
case STRING : int size=in.readInt();
}
return new ValueTransactional(abuf);
+ }
+ return new ValueTransactional();
+ }*/
+
+ public static ValueTransactional readFromStream(TransactionalFile in) throws IOException{
+ byte type=in.readByte();
+ switch(type){
+ case STRING : int size=in.readInt();
+ StringBuffer buf=new StringBuffer();
+ for(int i=0;i<size;i++){
+ buf.append(in.readChar());
+ }
+ return new ValueTransactional(buf.toString());
+ case INT : return new ValueTransactional(in.readInt());
+ case LONG : return new ValueTransactional(in.readLong());
+ case FLOAT : return new ValueTransactional(in.readFloat());
+ case DOUBLE : return new ValueTransactional(in.readDouble());
+ case BOOLEAN: return new ValueTransactional(in.readBoolean());
+ case TIMESTAMP: return new ValueTransactional(new Date(in.readLong()));
+ case BINARY : int length=in.readInt();
+ byte[] abuf=new byte[length];
+ int read=0;
+ while(read<length){
+ read+=in.read(abuf);//,read,length-read);
+ }
+ return new ValueTransactional(abuf);
+
}
return new ValueTransactional();
}