public int getLength(Object geometry) {
    MultiLineString multi = (MultiLineString) geometry;

    int numlines;
    int numpoints;
    int length;

    numlines = multi.getNumGeometries();
    numpoints = multi.getNumPoints();

    if (shapeType == ShapeType.ARC) {
      length = 44 + (4 * numlines) + (numpoints * 16);
    } else if (shapeType == ShapeType.ARCM) {
      length = 44 + (4 * numlines) + (numpoints * 16) + 8 + 8 + (8 * numpoints);
    } else if (shapeType == ShapeType.ARCZ) {
      length =
          44
              + (4 * numlines)
              + (numpoints * 16)
              + 8
              + 8
              + (8 * numpoints)
              + 8
              + 8
              + (8 * numpoints);
    } else {
      throw new IllegalStateException("Expected ShapeType of Arc, got " + shapeType);
    }

    return length;
  }
  public void write(WriteBufferManager buffer, Object geometry) throws IOException {
    MultiLineString multi = (MultiLineString) geometry;

    Envelope box = multi.getEnvelopeInternal();
    buffer.putDouble(box.getMinX());
    buffer.putDouble(box.getMinY());
    buffer.putDouble(box.getMaxX());
    buffer.putDouble(box.getMaxY());

    int numParts = multi.getNumGeometries();

    buffer.putInt(numParts);
    int npoints = multi.getNumPoints();
    buffer.putInt(npoints);

    LineString[] lines = new LineString[numParts];
    int idx = 0;

    for (int i = 0; i < numParts; i++) {
      lines[i] = (LineString) multi.getGeometryN(i);
      buffer.putInt(idx);
      idx = idx + lines[i].getNumPoints();
    }

    Coordinate[] coords = multi.getCoordinates();

    for (int t = 0; t < npoints; t++) {
      buffer.putDouble(coords[t].x);
      buffer.putDouble(coords[t].y);
    }

    if (shapeType == ShapeType.ARCZ) {
      double[] zExtreame = JTSUtilities.zMinMax(coords);

      if (Double.isNaN(zExtreame[0])) {
        buffer.putDouble(0.0);
        buffer.putDouble(0.0);
      } else {
        buffer.putDouble(zExtreame[0]);
        buffer.putDouble(zExtreame[1]);
      }

      for (int t = 0; t < npoints; t++) {
        double z = coords[t].z;

        if (Double.isNaN(z)) {
          buffer.putDouble(0.0);
        } else {
          buffer.putDouble(z);
        }
      }
    }

    if (shapeType == ShapeType.ARCZ) {
      buffer.putDouble(-10E40);
      buffer.putDouble(-10E40);

      for (int t = 0; t < npoints; t++) {
        buffer.putDouble(-10E40);
      }
    }
  }