/** * Reads a single {@link Geometry} in WKB format from a byte array. * * @param bytes the byte array to read from * @return the geometry read * @throws ParseException if the WKB is ill-formed */ public Geometry read(byte[] bytes) throws ParseException { // possibly reuse the ByteArrayInStream? // don't throw IOExceptions, since we are not doing any I/O try { return read(new ByteArrayInStream(bytes)); } catch (IOException ex) { throw new RuntimeException("Unexpected IOException caught: " + ex.getMessage()); } }
/** * Creates a new stream based on the given buffer. * * @param buffer the bytes to read */ public ByteArrayInStream(final byte[] buffer) { setBytes(buffer); }
public Geometry read(byte[] bytes) throws IOException { return read(new ByteArrayInStream(bytes)); }
/** * Creates a new stream based on the given buffer. * * @param buffer the bytes to read */ public ByteArrayInStream(final byte[] buffer) { setBytes(buffer); }
public Geometry read(byte[] bytes) throws IOException { return read(new ByteArrayInStream(bytes)); }
/** * This method will convert a Well Known Binary representation to a * JTS Geometry object. * * @param wkb te wkb encoded byte array * * @return a JTS Geometry object that is equivalent to the WTB * representation passed in by param wkb * * @throws IOException if more than one geometry object was found in the * WTB representation, or if the parser could not parse the WKB * representation. */ private Geometry wkb2Geometry(byte[] wkbBytes) throws IOException { if (wkbBytes == null) //DJB: null value from database --> null geometry (the same behavior as WKT). NOTE: sending back a GEOMETRYCOLLECTION(EMPTY) is also a possibility, but this is not the same as NULL return null; try { inStream.setBytes(wkbBytes); return wkbr.read(inStream); } catch (Exception e) { throw new DataSourceException("An exception occurred while parsing WKB data", e); } }
/** * Reads a single {@link Geometry} in WKB format from a byte array. * * @param bytes the byte array to read from * @return the geometry read * @throws ParseException if the WKB is ill-formed */ public Geometry read(byte[] bytes) throws ParseException { // possibly reuse the ByteArrayInStream? // don't throw IOExceptions, since we are not doing any I/O try { return read(new ByteArrayInStream(bytes)); } catch (IOException ex) { throw new RuntimeException("Unexpected IOException caught: " + ex.getMessage()); } }
/** * Reads a single {@link Geometry} from a byte array. * * @param bytes the byte array to read from * @return the geometry read * @throws ParseException if a parse exception occurs */ public Geometry read(byte[] bytes) throws ParseException { // possibly reuse the ByteArrayInStream? // don't throw IOExceptions, since we are not doing any I/O try { return read(new ByteArrayInStream(bytes)); } catch (IOException ex) { throw new RuntimeException("Unexpected IOException caught: " + ex.getMessage()); } }
byte[] bytes = rs.getBytes(1); ByteOrderDataInStream dis = new ByteOrderDataInStream(); dis.setInStream(new ByteArrayInStream(bytes)); byte byteOrder = dis.readByte();
/** * Read the first bytes of Geometry WKB. * @param bytes WKB Bytes * @return Geometry MetaData * @throws IOException If WKB meta is invalid (do not check the Geometry) */ public static GeometryMetaData getMetaDataFromWKB(byte[] bytes) throws IOException { ByteOrderDataInStream dis = new ByteOrderDataInStream(); dis.setInStream(new ByteArrayInStream(bytes)); // determine byte order byte byteOrderWKB = dis.readByte(); // always set byte order, since it may change from geometry to geometry int byteOrder = byteOrderWKB == WKBConstants.wkbNDR ? ByteOrderValues.LITTLE_ENDIAN : ByteOrderValues.BIG_ENDIAN; dis.setOrder(byteOrder); int typeInt = dis.readInt(); int geometryType = typeInt & 0xff; // determine if Z values are present boolean hasZ = (typeInt & 0x80000000) != 0; int inputDimension = hasZ ? 3 : 2; // determine if SRIDs are present boolean hasSRID = (typeInt & 0x20000000) != 0; int SRID = 0; if (hasSRID) { SRID = dis.readInt(); } return new GeometryMetaData(inputDimension, hasSRID, hasZ, geometryType, SRID); } }
/** * Read the first bytes of Geometry WKB. * @param bytes WKB Bytes * @return Geometry MetaData * @throws IOException If WKB meta is invalid (do not check the Geometry) */ public static GeometryMetaData getMetaDataFromWKB(byte[] bytes) throws IOException { ByteOrderDataInStream dis = new ByteOrderDataInStream(); dis.setInStream(new ByteArrayInStream(bytes)); // determine byte order byte byteOrderWKB = dis.readByte(); // always set byte order, since it may change from geometry to geometry int byteOrder = byteOrderWKB == WKBConstants.wkbNDR ? ByteOrderValues.LITTLE_ENDIAN : ByteOrderValues.BIG_ENDIAN; dis.setOrder(byteOrder); int typeInt = dis.readInt(); int geometryType = typeInt & 0xff; // determine if Z values are present boolean hasZ = (typeInt & 0x80000000) != 0; int inputDimension = hasZ ? 3 : 2; // determine if SRIDs are present boolean hasSRID = (typeInt & 0x20000000) != 0; int SRID = 0; if (hasSRID) { SRID = dis.readInt(); } return new GeometryMetaData(inputDimension, hasSRID, hasZ, geometryType, SRID); } }