com.xxdb.data.EntityBlockReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of api-java Show documentation
Show all versions of api-java Show documentation
The messaging and data conversion protocol between Java and DolphinDB server
package com.xxdb.data;
import com.xxdb.io.ExtendedDataInput;
import com.xxdb.io.ExtendedDataOutput;
import java.io.IOException;
public class EntityBlockReader implements Entity {
private Entity currentValue ;
private int size ;
private int currentIndex = 0;
private ExtendedDataInput instream;
public EntityBlockReader(ExtendedDataInput in) throws IOException{
int rows = in.readInt();
int cols = in.readInt();
size = rows * cols;
currentIndex = 0;
instream = in;
}
public Entity read() throws IOException{
BasicEntityFactory factory = new BasicEntityFactory();
if(currentIndex>=size) return null;
short flag = instream.readShort();
int form = flag >> 8;
int type = flag & 0xff;
currentValue = factory.createEntity(Entity.DATA_FORM.values()[form], Entity.DATA_TYPE.values()[type], instream);
currentIndex++;
return currentValue;
}
public void skipAll() throws IOException{
BasicEntityFactory factory = new BasicEntityFactory();
for(int i=currentIndex;i> 8;
int type = flag & 0xff;
currentValue = factory.createEntity(Entity.DATA_FORM.values()[form], Entity.DATA_TYPE.values()[type], instream);
currentIndex++;
}
}
public Boolean hasNext(){
return currentIndex < size;
}
@Override
public DATA_FORM getDataForm() {
return DATA_FORM.DF_TABLE;
}
@Override
public DATA_CATEGORY getDataCategory() {
return DATA_CATEGORY.MIXED;
}
@Override
public DATA_TYPE getDataType() {
return DATA_TYPE.DT_ANY;
}
@Override
public int rows() {
return 0;
}
@Override
public int columns() {
return 0;
}
@Override
public String getString() {
return null;
}
@Override
public void write(ExtendedDataOutput output) throws IOException {
}
@Override
public boolean isScalar() {
return false;
}
@Override
public boolean isVector() {
return false;
}
@Override
public boolean isPair() {
return false;
}
@Override
public boolean isTable() {
return true;
}
@Override
public boolean isMatrix() {
return false;
}
@Override
public boolean isDictionary() {
return false;
}
@Override
public boolean isChart() {
return false;
}
@Override
public boolean isChunk() {
return false;
}
}