Package org.postgis.binary
Class BinaryWriter
- java.lang.Object
-
- org.postgis.binary.BinaryWriter
-
public class BinaryWriter extends Object
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 Constructor Description BinaryWriter()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected 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.StringwriteHexed(Geometry geom)StringwriteHexed(Geometry geom, byte REP)Write a hex encoded geometry Is synchronized to protect offset counter.
-
-
-
Method Detail
-
valueSetterForEndian
public static ValueSetter valueSetterForEndian(ByteSetter bytes, byte endian)
Get the appropriate ValueGetter for my endianness- Parameters:
bytes- The ByteSetter to useendian- the endian for the ValueSetter to use- Returns:
- the ValueGetter
-
writeHexed
public String writeHexed(Geometry geom, byte REP)
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:
the consistency checker
-
writeBinary
public byte[] writeBinary(Geometry geom, byte REP)
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:
Geometry.checkConsistency()
-
writeBinary
public byte[] writeBinary(Geometry geom)
-
writeGeometry
protected void writeGeometry(Geometry geom, ValueSetter dest)
Parse a geometry starting at offset.- Parameters:
geom- the geometry to writedest- the value setting to be used for writing
-
estimateBytes
protected int estimateBytes(Geometry geom)
Estimate how much bytes a geometry will need in WKB.- Parameters:
geom- Geometry to estimate.- Returns:
- estimated number of bytes
-
-