use of com.revolsys.io.endian.EndianMappedByteBuffer in project com.revolsys.open by revolsys.
the class XbaseIterator method readRecordDefinition.
private void readRecordDefinition() throws IOException {
this.recordDefinition = new RecordDefinitionImpl(this.typeName);
int b = this.in.read();
while (b != 0x0D) {
final StringBuilder fieldName = new StringBuilder();
boolean endOfName = false;
for (int i = 0; i < 11; i++) {
if (!endOfName && b != 0) {
fieldName.append((char) b);
} else {
endOfName = true;
}
if (i != 10) {
b = this.in.read();
}
}
final char fieldType = (char) this.in.read();
this.in.skipBytes(4);
int length = this.in.read();
final int decimalCount = this.in.read();
this.in.skipBytes(14);
b = this.in.read();
final DataType dataType = DATA_TYPES.get(fieldType);
if (fieldType == MEMO_TYPE) {
length = Integer.MAX_VALUE;
}
this.recordDefinition.addField(fieldName.toString(), dataType, length, decimalCount, false);
}
if (this.mappedFile) {
final EndianMappedByteBuffer file = (EndianMappedByteBuffer) this.in;
this.firstIndex = file.getFilePointer();
}
}
use of com.revolsys.io.endian.EndianMappedByteBuffer in project com.revolsys.open by revolsys.
the class XbaseIterator method setPosition.
public void setPosition(final int position) {
if (this.mappedFile) {
final EndianMappedByteBuffer file = (EndianMappedByteBuffer) this.in;
this.position = position;
try {
final long offset = this.firstIndex + (long) (this.recordSize + 1) * position;
file.seek(offset);
setLoadNext(true);
} catch (final IOException e) {
throw new RuntimeException("Unable to seek to " + this.firstIndex, e);
}
} else {
throw new UnsupportedOperationException("The position can only be set on files");
}
}
use of com.revolsys.io.endian.EndianMappedByteBuffer in project com.revolsys.open by revolsys.
the class XbaseIterator method initDo.
@Override
protected void initDo() {
if (this.in == null) {
try {
try {
final File file = this.resource.getFile();
final Boolean memoryMapped = getProperty("memoryMapped");
if (Boolean.TRUE == memoryMapped) {
this.in = new EndianMappedByteBuffer(file, MapMode.READ_ONLY);
this.mappedFile = true;
} else {
this.in = new LittleEndianRandomAccessFile(file, "r");
}
} catch (final IllegalArgumentException e) {
this.in = new EndianInputStream(this.resource.getInputStream());
} catch (final FileNotFoundException e) {
this.in = new EndianInputStream(this.resource.getInputStream());
}
loadHeader();
readRecordDefinition();
this.recordBuffer = new byte[this.recordSize];
if (this.initCallback != null) {
this.initCallback.run();
}
} catch (final IOException e) {
throw new RuntimeException("Error initializing mappedFile ", e);
}
}
}
Aggregations