Package net.postgis.jdbc.geometry.binary
Class BinaryWriter
java.lang.Object
net.postgis.jdbc.geometry.binary.BinaryWriter
Create binary representation of geometries. Currently, only text rep (hexed)
implementation is tested.
It should be easy to add char[] and CharSequence ByteGetter instances,
although the latter one is not compatible with older jdks.
I did not implement real unsigned 32-bit integers or emulate them with long,
as both java Arrays and Strings currently can have only 2^31-1 elements
(bytes), so we cannot even get or build Geometries with more than approx.
2^28 coordinates (8 bytes each).
- Author:
- [email protected]
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected intestimateBytes(Geometry geom) Estimate how much bytes a geometry will need in WKB.static ValueSettervalueSetterForEndian(ByteSetter bytes, byte endian) Get the appropriate ValueGetter for my endiannessbyte[]writeBinary(Geometry geom) byte[]writeBinary(Geometry geom, byte REP) Write a binary encoded geometry.protected voidwriteGeometry(Geometry geom, ValueSetter dest) Parse a geometry starting at offset.writeHexed(Geometry geom) writeHexed(Geometry geom, byte REP) Write a hex encoded geometry Is synchronized to protect offset counter.
-
Constructor Details
-
BinaryWriter
public BinaryWriter()
-
-
Method Details
-
valueSetterForEndian
Get the appropriate ValueGetter for my endianness- Parameters:
bytes- The ByteSetter to useendian- the endian for the ValueSetter to use- Returns:
- the ValueGetter
-
writeHexed
Write a hex encoded geometry Is synchronized to protect offset counter. (Unfortunately, Java does not have neither call by reference nor multiple return values.) This is a TODO item. The geometry you put in must be consistent, geom.checkConsistency() must return true. If not, the result may be invalid WKB.- Parameters:
geom- the geometry to be writtenREP- endianness to write the bytes with- Returns:
- String containing the hex encoded geometry
- See Also:
-
writeHexed
-
writeBinary
Write a binary encoded geometry. Is synchronized to protect offset counter. (Unfortunately, Java does not have neither call by reference nor multiple return values.) This is a TODO item. The geometry you put in must be consistent, geom.checkConsistency() must return true. If not, the result may be invalid WKB.- Parameters:
geom- the geometry to be writtenREP- endianness to write the bytes with- Returns:
- byte array containing the encoded geometry
- See Also:
-
writeBinary
-
writeGeometry
Parse a geometry starting at offset.- Parameters:
geom- the geometry to writedest- the value setting to be used for writing
-
estimateBytes
Estimate how much bytes a geometry will need in WKB.- Parameters:
geom- Geometry to estimate.- Returns:
- estimated number of bytes
-