1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
From: Markus Koschany <apo@debian.org>
Date: Fri, 12 Nov 2021 21:06:42 +0100
Subject: JTS 18.1 compatibility
Bug-Debian: https://bugs.debian.org/997743
Origin: https://github.com/locationtech/spatial4j/commit/9d75547c183f14b2bf5490394d06164d1d4f823b
Forwarded: not-needed
pom.xml | 2 +-
.../spatial4j/io/jts/JtsBinaryCodec.java | 4 +++-
.../spatial4j/io/JtsBinaryCodecTest.java | 20 +++++++++-----------
3 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/pom.xml b/pom.xml
index 3b6a698..a7adee8 100644
@@ -120,7 +120,7 @@
<dependency>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
- <version>1.17.0</version>
+ <version>1.18.1</version>
<optional>true</optional>
</dependency>
diff --git a/src/main/java/org/locationtech/spatial4j/io/jts/JtsBinaryCodec.java b/src/main/java/org/locationtech/spatial4j/io/jts/JtsBinaryCodec.java
index b355b93..3ea18de 100644
@@ -85,15 +85,17 @@ public class JtsBinaryCodec extends BinaryCodec {
InStream inStream = new InStream() {//a strange JTS abstraction
boolean first = true;
@Override
- public void read(byte[] buf) throws IOException {
+ public int read(byte[] buf) throws IOException {
if (first) {//we don't write JTS's leading BOM so synthesize reading it
if (buf.length != 1)
throw new IllegalStateException("Expected initial read of one byte, not: " + buf.length);
buf[0] = WKBConstants.wkbXDR;//0
first = false;
+ return 1;
} else {
//TODO for performance, specialize for common array lengths: 1, 4, 8
dataInput.readFully(buf);
+ return buf.length;
}
}
};
diff --git a/src/test/java/org/locationtech/spatial4j/io/JtsBinaryCodecTest.java b/src/test/java/org/locationtech/spatial4j/io/JtsBinaryCodecTest.java
index 0d16b45..ccc1ad0 100644
@@ -8,19 +8,16 @@
package org.locationtech.spatial4j.io;
-import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
-import org.locationtech.spatial4j.context.SpatialContext;
-import org.locationtech.spatial4j.context.jts.JtsSpatialContext;
-import org.locationtech.spatial4j.context.jts.JtsSpatialContextFactory;
-import org.locationtech.spatial4j.shape.Shape;
+import org.junit.Test;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.PrecisionModel;
import org.locationtech.jts.util.GeometricShapeFactory;
-
-import org.junit.Test;
-
-import java.util.Arrays;
+import org.locationtech.spatial4j.context.SpatialContext;
+import org.locationtech.spatial4j.context.jts.JtsSpatialContext;
+import org.locationtech.spatial4j.context.jts.JtsSpatialContextFactory;
+import org.locationtech.spatial4j.shape.Shape;
+import org.locationtech.spatial4j.shape.jts.JtsGeometry;
public class JtsBinaryCodecTest extends BinaryCodecTest {
@@ -32,9 +29,10 @@ public class JtsBinaryCodecTest extends BinaryCodecTest {
}
@Test
- public void testPoly() {
+ public void testPoly() throws Exception {
JtsSpatialContext ctx = (JtsSpatialContext)super.ctx;
- ctx.makeShape(randomGeometry(randomIntBetween(3, 20)), false, false);
+ final JtsGeometry shape = ctx.makeShape(randomGeometry(randomIntBetween(3, 20)), false, false);
+ assertRoundTrip(shape);
}
@Override
|