Search in sources :

Example 1 with LittleEndianRandomAccessFile

use of com.revolsys.io.endian.LittleEndianRandomAccessFile in project com.revolsys.open by revolsys.

the class ShapefileRecordReader method initDo.

@Override
protected synchronized void initDo() {
    if (this.in == null) {
        try {
            try {
                if (this.resource.isFile()) {
                    final File file = this.resource.getFile();
                    this.in = new LittleEndianRandomAccessFile(file, "r");
                } else {
                    this.in = new EndianInputStream(this.resource.getInputStream());
                }
            } catch (final IllegalArgumentException | UnsupportedOperationException e) {
                this.in = new EndianInputStream(this.resource.getInputStream());
            }
            final Resource xbaseResource = this.resource.newResourceChangeExtension("dbf");
            if (xbaseResource != null && xbaseResource.exists()) {
                this.xbaseRecordReader = new XbaseRecordReader(xbaseResource, this.recordFactory, () -> updateRecordDefinition());
                this.xbaseRecordReader.setTypeName(this.typeName);
                this.xbaseRecordReader.setCloseFile(this.closeFile);
            }
            loadHeader();
            int axisCount;
            switch(this.shapeType) {
                // 1
                case ShapefileConstants.POINT_SHAPE:
                // 3
                case ShapefileConstants.POLYLINE_SHAPE:
                // 5
                case ShapefileConstants.POLYGON_SHAPE:
                case // 8
                ShapefileConstants.MULTI_POINT_SHAPE:
                    axisCount = 2;
                    break;
                // 9
                case ShapefileConstants.POINT_Z_SHAPE:
                // 10
                case ShapefileConstants.POLYLINE_Z_SHAPE:
                // 19
                case ShapefileConstants.POLYGON_Z_SHAPE:
                case // 20
                ShapefileConstants.MULTI_POINT_Z_SHAPE:
                    axisCount = 3;
                    break;
                // 11
                case ShapefileConstants.POINT_ZM_SHAPE:
                // 13
                case ShapefileConstants.POLYLINE_ZM_SHAPE:
                // 15
                case ShapefileConstants.POLYGON_ZM_SHAPE:
                // 18
                case ShapefileConstants.MULTI_POINT_ZM_SHAPE:
                // 21
                case ShapefileConstants.POINT_M_SHAPE:
                // 23
                case ShapefileConstants.POLYLINE_M_SHAPE:
                // 25
                case ShapefileConstants.POLYGON_M_SHAPE:
                case // 28
                ShapefileConstants.MULTI_POINT_M_SHAPE:
                    axisCount = 4;
                    break;
                default:
                    throw new RuntimeException("Unknown shape type:" + this.shapeType);
            }
            this.geometryFactory = getProperty(IoConstants.GEOMETRY_FACTORY);
            if (this.geometryFactory == null) {
                this.geometryFactory = GeometryFactory.floating(this.resource, axisCount);
            }
            if (this.geometryFactory == null) {
                this.geometryFactory = GeometryFactory.floating(0, axisCount);
            }
            setProperty(IoConstants.GEOMETRY_FACTORY, this.geometryFactory);
            if (this.xbaseRecordReader != null) {
                this.xbaseRecordReader.hasNext();
            }
            if (this.recordDefinition == null) {
                this.recordDefinition = Records.newGeometryRecordDefinition();
            }
            this.recordDefinition.setGeometryFactory(this.geometryFactory);
        } catch (final IOException e) {
            throw new RuntimeException("Error initializing mappedFile " + this.resource, e);
        }
    }
}
Also used : EndianInputStream(com.revolsys.io.endian.EndianInputStream) Resource(com.revolsys.spring.resource.Resource) XbaseRecordReader(com.revolsys.record.io.format.xbase.XbaseRecordReader) LittleEndianRandomAccessFile(com.revolsys.io.endian.LittleEndianRandomAccessFile) IOException(java.io.IOException) File(java.io.File) LittleEndianRandomAccessFile(com.revolsys.io.endian.LittleEndianRandomAccessFile)

Example 2 with LittleEndianRandomAccessFile

use of com.revolsys.io.endian.LittleEndianRandomAccessFile in project com.revolsys.open by revolsys.

the class FgdbUtil method newGdbTable.

public LittleEndianRandomAccessFile newGdbTable(final File file) {
    final LittleEndianRandomAccessFile out = new LittleEndianRandomAccessFile(file, "rw");
    // Magic
    out.write(0x03);
    out.write(0);
    out.write(0);
    out.write(0);
    // Number of valid rows
    out.writeLEInt(0);
    // 4 bytes: varying values - unknown role (TBC : this value does have
    // something to do with row size. A value larger than the size of the
    // largest row seems to be ok)
    out.write(0x03);
    out.write(0);
    out.write(0);
    out.write(0);
    // Unknown
    out.writeLEInt(0);
    // Unknown
    out.writeLEInt(0);
    // file size in bytes
    out.writeLEInt(40);
    // Unknown
    out.writeLEInt(0);
    // offset in bytes at which the field description
    out.writeLEInt(40);
    // section begins
    // Unknown
    out.writeLEInt(0);
    return out;
}
Also used : LittleEndianRandomAccessFile(com.revolsys.io.endian.LittleEndianRandomAccessFile)

Example 3 with LittleEndianRandomAccessFile

use of com.revolsys.io.endian.LittleEndianRandomAccessFile 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

LittleEndianRandomAccessFile (com.revolsys.io.endian.LittleEndianRandomAccessFile)3 EndianInputStream (com.revolsys.io.endian.EndianInputStream)2 File (java.io.File)2 IOException (java.io.IOException)2 EndianMappedByteBuffer (com.revolsys.io.endian.EndianMappedByteBuffer)1 XbaseRecordReader (com.revolsys.record.io.format.xbase.XbaseRecordReader)1 Resource (com.revolsys.spring.resource.Resource)1 FileNotFoundException (java.io.FileNotFoundException)1