org.postgis.binary
Class BinaryWriter

java.lang.Object
  extended by org.postgis.binary.BinaryWriter

public class BinaryWriter
extends java.lang.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:
markus.schaber@logi-track.com

Constructor Summary
BinaryWriter()
           
 
Method Summary
protected  int estimateBytes(Geometry geom)
          Estimate how much bytes a geometry will need in WKB.
static ValueSetter valueSetterForEndian(ByteSetter bytes, byte endian)
          Get the appropriate ValueGetter for my endianness
 byte[] writeBinary(Geometry geom)
           
 byte[] writeBinary(Geometry geom, byte REP)
          Write a binary encoded geometry.
protected  void writeGeometry(Geometry geom, ValueSetter dest)
          Parse a geometry starting at offset.
 java.lang.String writeHexed(Geometry geom)
           
 java.lang.String writeHexed(Geometry geom, byte REP)
          Write a hex encoded geometry Is synchronized to protect offset counter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BinaryWriter

public BinaryWriter()
Method Detail

valueSetterForEndian

public static ValueSetter valueSetterForEndian(ByteSetter bytes,
                                               byte endian)
Get the appropriate ValueGetter for my endianness

Parameters:
bytes - The appropriate Byte Getter
Returns:
the ValueGetter

writeHexed

public java.lang.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.

See Also:
the consistency checker

writeHexed

public java.lang.String writeHexed(Geometry geom)

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.

See Also:
Geometry.checkConsistency()

writeBinary

public byte[] writeBinary(Geometry geom)

writeGeometry

protected void writeGeometry(Geometry geom,
                             ValueSetter dest)
Parse a geometry starting at offset.


estimateBytes

protected int estimateBytes(Geometry geom)
Estimate how much bytes a geometry will need in WKB.