org.wkb4j.engine
Class WKBParser

java.lang.Object
  |
  +--org.wkb4j.engine.WKBParser
All Implemented Interfaces:
WKBGeometryTypes
Direct Known Subclasses:
WKBParser3D

public class WKBParser
extends java.lang.Object
implements WKBGeometryTypes

Generate events from the submitted array of bytes holding binary data in the Well-Known Binary format. It generates a beginGeometry event when it sees the beginning of a given Geometry, an endGeometry event when it sees the end of a given Geometry, and an abortGeometry event if something happens that makes the completion of the current Geometry impossible.
Points are treated differently from other Geometries: all the points in a Geometry are collected into a single array of byte and passed to the WKBFactory all at once. Events are nested, meaning that for a classical MultiLineString element with two LineStrings made of respectively 3 and 2 Points each, the following events will occur:


The basic idea is to provide the author of each factory with as much freedom as possible while allowing for strong performance. wkbByteOrder aren't taken into account because will rely on the database to provide the data in the Big-Endian format (MSB, Most Significant Byte), the Endian used in Java.
Inspired by the SAX API.
Creation date: 6 juil. 2002 23:49:28

Version:
$Revision: 1.12 $ $Date: 2003/07/28 22:21:26 $
Author:
David Garnier

Field Summary
static int DIMENSION2
           
static int DIMENSION3
           
protected  boolean endianess
           
protected  org.wkb4j.engine.WKBFactory factory
           
protected  java.io.DataInputStream inputStream
           
protected  org.wkb4j.engine.ResetableByteArrayInputStream internalBuffer
           
protected static org.apache.log4j.Logger log
           
protected  java.lang.String[] words
           
 
Fields inherited from interface org.wkb4j.engine.WKBGeometryTypes
linearRing, wkbGeometryCollection, wkbLineString, wkbMultiLineString, wkbMultiPoint, wkbMultiPolygon, wkbPoint, wkbPolygon
 
Constructor Summary
WKBParser(org.wkb4j.engine.WKBFactory _factory)
          Constructor for WKBParser.
WKBParser(org.wkb4j.engine.WKBFactory _factory, java.lang.String[] _words, boolean _endianess)
          Constructor for WKBParser.
 
Method Summary
protected  void decodeData(java.lang.String[] words, int[] values)
          Read the raw WKB data from the DataInputStream and generate the beginUnit/endUnit calls and the calls to the top-level geometries (MultiLineString, LineString, Polygon, MultiPolygon, GeometryCollection, Point)
All the readGeometry method can throw IOException if something goes wrong.
private  java.io.DataInputStream getInputStream()
          Returns the DataInputStream used to transform bytes into native types (int and double in our case).
private  org.wkb4j.engine.ResetableByteArrayInputStream getInternalBuffer()
          Returns the ResetableByteArrayInputStream
 void parseData(byte[] buffer, byte[] sridBuffer)
          Load the raw bytes in the WKB format representing one record of the DB and generates the events.
 void parseData(byte[] buffer, byte[][] datas)
          Load the raw bytes in the WKB format and generates the events.
 void parseData(byte[] buffer, int srid)
          Load the raw bytes in the WKB format and generates the events.
protected  int parseInt(byte[] intBuffer, boolean endianess)
           
protected  boolean parseType(int geotype, int dimension)
          Read the given and generates the corresponding events.
protected  void readGeometryCollection()
          Reads a GeometryCollection.
protected  void readLinearRing(int dimension)
          Method readLinearRing.
protected  void readLineString(int dimension)
          Reads a LineString.
protected  void readMultiLineString()
          Reads a MultiLineString.
protected  void readMultiPoint()
          Reads a MultiPoint.
protected  void readMultiPolygon(int dimension)
          Reads a MultiPolygon.
protected  void readPoint(int dimension)
          Reads a Point.
protected  void readPoints(int pointCount, int dimension)
          Reads a number of Points.
protected  void readPolygon(int dimension)
          Reads a Polygon.
private  void setInternalBuffer(org.wkb4j.engine.ResetableByteArrayInputStream internalBuffer)
          Sets the ResetableByteArrayInputStream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static org.apache.log4j.Logger log

factory

protected org.wkb4j.engine.WKBFactory factory

DIMENSION2

public static final int DIMENSION2
See Also:
Constant Field Values

DIMENSION3

public static final int DIMENSION3
See Also:
Constant Field Values

internalBuffer

protected org.wkb4j.engine.ResetableByteArrayInputStream internalBuffer

inputStream

protected java.io.DataInputStream inputStream

words

protected java.lang.String[] words

endianess

protected final boolean endianess
Constructor Detail

WKBParser

public WKBParser(org.wkb4j.engine.WKBFactory _factory)
Constructor for WKBParser.

Parameters:
_factory - that will receive the events.

WKBParser

public WKBParser(org.wkb4j.engine.WKBFactory _factory,
                 java.lang.String[] _words,
                 boolean _endianess)
Constructor for WKBParser.

Parameters:
_factory - that will receive the events.
Method Detail

parseData

public void parseData(byte[] buffer,
                      byte[] sridBuffer)
               throws java.io.IOException
Load the raw bytes in the WKB format representing one record of the DB and generates the events. The sridBuffer should contain an array of bytes holding the SRID of the current geometry. If sridBuffer is null or longer than 4 bytes, the SRID of the current geometry is set to -1

Parameters:
buffer - array of bytes holding the data in the WKB format
sridBuffer - .
java.io.IOException

parseInt

protected int parseInt(byte[] intBuffer,
                       boolean endianess)
                throws java.io.IOException
java.io.IOException

parseData

public void parseData(byte[] buffer,
                      byte[][] datas)
               throws java.io.IOException
Load the raw bytes in the WKB format and generates the events.

Parameters:
buffer - array of bytes holding the data in the WKB format
java.io.IOException

parseData

public void parseData(byte[] buffer,
                      int srid)
               throws java.io.IOException
Load the raw bytes in the WKB format and generates the events.

Parameters:
buffer - array of bytes holding the data in the WKB format
srid - The SRID of the current geometry.
java.io.IOException

getInternalBuffer

private org.wkb4j.engine.ResetableByteArrayInputStream getInternalBuffer()
Returns the ResetableByteArrayInputStream

Returns:
ResetableByteArrayInputStream

setInternalBuffer

private void setInternalBuffer(org.wkb4j.engine.ResetableByteArrayInputStream internalBuffer)
Sets the ResetableByteArrayInputStream

Parameters:
internalBuffer - The ResetableByteArrayInputStream to set

getInputStream

private java.io.DataInputStream getInputStream()
Returns the DataInputStream used to transform bytes into native types (int and double in our case).

Returns:
DataInputStream

decodeData

protected void decodeData(java.lang.String[] words,
                          int[] values)
Read the raw WKB data from the DataInputStream and generate the beginUnit/endUnit calls and the calls to the top-level geometries (MultiLineString, LineString, Polygon, MultiPolygon, GeometryCollection, Point)
All the readGeometry method can throw IOException if something goes wrong.


parseType

protected boolean parseType(int geotype,
                            int dimension)
                     throws java.io.IOException
Read the given and generates the corresponding events. Do not call beginUnit(); nor endUnit():

Parameters:
geotype - type of the next Geometry.
dimension - dimension of the points contained in the next geometry.
Throws:
java.io.IOException

readMultiLineString

protected void readMultiLineString()
                            throws java.io.IOException
Reads a MultiLineString.

Throws:
java.io.IOException

readLineString

protected void readLineString(int dimension)
                       throws java.io.IOException
Reads a LineString.

Parameters:
dimension - dimension of the points contained in this geometry.
Throws:
java.io.IOException

readPoints

protected void readPoints(int pointCount,
                          int dimension)
                   throws java.io.IOException
Reads a number of Points.

Parameters:
pointCount -
dimension - unused parameter
Throws:
java.io.IOException

readMultiPolygon

protected void readMultiPolygon(int dimension)
                         throws java.io.IOException
Reads a MultiPolygon.

Parameters:
dimension - dimension of the points contained in this geometry.
Throws:
java.io.IOException

readPolygon

protected void readPolygon(int dimension)
                    throws java.io.IOException
Reads a Polygon.

Parameters:
dimension - dimension of the points contained in this geometry.
Throws:
java.io.IOException

readLinearRing

protected void readLinearRing(int dimension)
                       throws java.io.IOException
Method readLinearRing.

Parameters:
dimension - dimension of the points contained in this geometry.
Throws:
java.io.IOException

readMultiPoint

protected void readMultiPoint()
                       throws java.io.IOException
Reads a MultiPoint.

Throws:
java.io.IOException

readGeometryCollection

protected void readGeometryCollection()
                               throws java.io.IOException
Reads a GeometryCollection.

Throws:
java.io.IOException

readPoint

protected void readPoint(int dimension)
                  throws java.io.IOException
Reads a Point.

Parameters:
dimension - dimension of the points contained in this geometry.
Throws:
java.io.IOException


Copyright © 2002-2003 David Garnier. All Rights Reserved.