/** * Write an Array of "slim" Points (without endianness, srid and type, part * of LinearRing and Linestring, but not MultiPoint! */ private void writePointArray(Point[] geom, ValueSetter dest) { // number of points dest.setInt(geom.length); for (int i = 0; i < geom.length; i++) { writePoint(geom[i], dest); } }
/** * Parse a hex encoded geometry * * Is synchronized to protect offset counter. (Unfortunately, Java does not * have neither call by reference nor multiple return values.) * * @param value String containing the data to be parsed * @return resulting geometry for the parsed data */ public synchronized Geometry parse(String value) { StringByteGetter bytes = new ByteGetter.StringByteGetter(value); return parseGeometry(valueGetterForEndian(bytes)); }
/** * Parse a binary encoded geometry. * * Is synchronized to protect offset counter. (Unfortunately, Java does not * have neither call by reference nor multiple return values.) * * @param value byte array containing the data to be parsed * @return resulting geometry for the parsed data */ public synchronized Geometry parse(byte[] value) { BinaryByteGetter bytes = new ByteGetter.BinaryByteGetter(value); return parseGeometry(valueGetterForEndian(bytes)); }
private MultiLineString parseMultiLineString(ValueGetter data) { int count = data.getInt(); LineString[] strings = new LineString[count]; parseGeometryArray(data, strings); return new MultiLineString(strings); }
protected long getLong(int index) { return ((long) data.get(index + 7) << 56) + ((long) data.get(index + 6) << 48) + ((long) data.get(index + 5) << 40) + ((long) data.get(index + 4) << 32) + ((long) data.get(index + 3) << 24) + ((long) data.get(index + 2) << 16) + ((long) data.get(index + 1) << 8) + ((long) data.get(index) << 0); } }
public int getInt() { int res = getInt(position); position += 4; return res; }
private void writePolygon(Polygon geom, ValueSetter dest) { dest.setInt(geom.numRings()); for (int i = 0; i < geom.numRings(); i++) { writeLinearRing(geom.getRing(i), dest); } }
/** Write an Array of "full" Geometries */ private int estimateGeometryArray(Geometry[] container) { int result = 0; for (int i = 0; i < container.length; i++) { result += estimateBytes(container[i]); } return result; }
public long getLong() { long res = getLong(position); position += 8; return res; }
/** Parse an Array of "full" Geometries */ private void parseGeometryArray(ValueGetter data, Geometry[] container) { for (int i = 0; i < container.length; i++) { container[i] = parseGeometry(data); } }
/** Write an Array of "full" Geometries */ private void writeGeometryArray(Geometry[] container, ValueSetter dest) { for (int i = 0; i < container.length; i++) { writeGeometry(container[i], dest); } }
/** * Parse a hex encoded geometry * * Is synchronized to protect offset counter. (Unfortunately, Java does not * have neither call by reference nor multiple return values.) * * @param value String containing the data to be parsed * @return resulting geometry for the parsed data */ public synchronized Geometry parse(String value) { StringByteGetter bytes = new ByteGetter.StringByteGetter(value); return parseGeometry(valueGetterForEndian(bytes)); }
/** * Parse a binary encoded geometry. * * Is synchronized to protect offset counter. (Unfortunately, Java does not * have neither call by reference nor multiple return values.) * * @param value byte array containing the data to be parsed * @return resulting geometry for the parsed data */ public synchronized Geometry parse(byte[] value) { BinaryByteGetter bytes = new ByteGetter.BinaryByteGetter(value); return parseGeometry(valueGetterForEndian(bytes)); }
private MultiPolygon parseMultiPolygon(ValueGetter data) { int count = data.getInt(); Polygon[] polys = new Polygon[count]; parseGeometryArray(data, polys); return new MultiPolygon(polys); }
protected long getLong(int index) { return ((long) data.get(index) << 56) + ((long) data.get(index + 1) << 48) + ((long) data.get(index + 2) << 40) + ((long) data.get(index + 3) << 32) + ((long) data.get(index + 4) << 24) + ((long) data.get(index + 5) << 16) + ((long) data.get(index + 6) << 8) + ((long) data.get(index + 7) << 0); } }
/** * Write an Array of "slim" Points (without endianness, srid and type, part * of LinearRing and Linestring, but not MultiPoint! */ private void writePointArray(Point[] geom, ValueSetter dest) { // number of points dest.setInt(geom.length); for (int i = 0; i < geom.length; i++) { writePoint(geom[i], dest); } }
protected void setLong(long value, int index) { data.set((byte) (value >>> 56), index + 7); data.set((byte) (value >>> 48), index + 6); data.set((byte) (value >>> 40), index + 5); data.set((byte) (value >>> 32), index + 4); data.set((byte) (value >>> 24), index + 3); data.set((byte) (value >>> 16), index + 2); data.set((byte) (value >>> 8), index + 1); data.set((byte) value, index); } }
/** * Get a byte, should be equal for all endians * * @return the byte value */ public byte getByte() { return (byte) data.get(position++); }
protected void setLong(long value, int index) { data.set((byte) (value >>> 56), index); data.set((byte) (value >>> 48), index + 1); data.set((byte) (value >>> 40), index + 2); data.set((byte) (value >>> 32), index + 3); data.set((byte) (value >>> 24), index + 4); data.set((byte) (value >>> 16), index + 5); data.set((byte) (value >>> 8), index + 6); data.set((byte) value, index + 7); } }