Search in sources :

Example 1 with EndianMappedByteBuffer

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();
    }
}
Also used : EndianMappedByteBuffer(com.revolsys.io.endian.EndianMappedByteBuffer) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) DataType(com.revolsys.datatype.DataType)

Example 2 with EndianMappedByteBuffer

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");
    }
}
Also used : EndianMappedByteBuffer(com.revolsys.io.endian.EndianMappedByteBuffer) IOException(java.io.IOException)

Example 3 with EndianMappedByteBuffer

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);
        }
    }
}
Also used : EndianMappedByteBuffer(com.revolsys.io.endian.EndianMappedByteBuffer) EndianInputStream(com.revolsys.io.endian.EndianInputStream) FileNotFoundException(java.io.FileNotFoundException) LittleEndianRandomAccessFile(com.revolsys.io.endian.LittleEndianRandomAccessFile) IOException(java.io.IOException) File(java.io.File) LittleEndianRandomAccessFile(com.revolsys.io.endian.LittleEndianRandomAccessFile)

Aggregations

EndianMappedByteBuffer (com.revolsys.io.endian.EndianMappedByteBuffer)3 IOException (java.io.IOException)2 DataType (com.revolsys.datatype.DataType)1 EndianInputStream (com.revolsys.io.endian.EndianInputStream)1 LittleEndianRandomAccessFile (com.revolsys.io.endian.LittleEndianRandomAccessFile)1 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1