Beispiel #1
0
  private void init(boolean strict, GeometryFactory gf) throws IOException, ShapefileException {
    geometryFactory = gf;

    if (channel instanceof FileChannel && useMemoryMappedBuffer) {
      FileChannel fc = (FileChannel) channel;
      buffer = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
      buffer.position(0);
      this.currentOffset = 0;
    } else {
      // force useMemoryMappedBuffer to false
      this.useMemoryMappedBuffer = false;
      // start small
      buffer = NIOUtilities.allocate(1024);
      fill(buffer, channel);
      buffer.flip();
      this.currentOffset = 0;
    }
    header = new ShapefileHeader();
    header.read(buffer, strict);
    fileShapeType = header.getShapeType();
    handler = fileShapeType.getShapeHandler(gf);
    if (handler == null) {
      throw new IOException("Unsuported shape type:" + fileShapeType);
    }

    headerTransfer = ByteBuffer.allocate(8);
    headerTransfer.order(ByteOrder.BIG_ENDIAN);

    // make sure the record end is set now...
    record.end = this.toFileOffset(buffer.position());
  }
Beispiel #2
0
  private void init(WarningListener warningListener) throws IOException, ShapefileException {
    header = readHeader(channel, warningListener);
    fileShapeType = header.getShapeType();
    handler = fileShapeType.getShapeHandler();

    // recordHeader = ByteBuffer.allocateDirect(8);
    // recordHeader.order(ByteOrder.BIG_ENDIAN);

    if (handler == null) {
      throw new IOException("Unsuported shape type:" + fileShapeType);
    }
    buffer = new ReadBufferManager(channel);
  }