Class BinaryWriter

java.lang.Object
net.postgis.jdbc.geometry.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 Details

    • BinaryWriter

      public BinaryWriter()
  • Method Details

    • valueSetterForEndian

      public static ValueSetter valueSetterForEndian(ByteSetter bytes, byte endian)
      Get the appropriate ValueGetter for my endianness
      Parameters:
      bytes - The ByteSetter to use
      endian - 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 written
      REP - endianness to write the bytes with
      Returns:
      String containing the hex encoded geometry
      See Also:
    • writeHexed

      public 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.
      Parameters:
      geom - the geometry to be written
      REP - endianness to write the bytes with
      Returns:
      byte array containing the encoded geometry
      See Also:
    • 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 write
      dest - 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