Search in sources :

Example 1 with EndianInputStream

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

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

EndianInputStream (com.revolsys.io.endian.EndianInputStream)2 LittleEndianRandomAccessFile (com.revolsys.io.endian.LittleEndianRandomAccessFile)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