/** * Reads a {@link Geometry} in binary WKB format from an {@link InStream}. * * @param is the stream to read from * @return the Geometry read * @throws IOException if the underlying stream creates an error * @throws ParseException if the WKB is ill-formed */ public Geometry read(InStream is) throws IOException, ParseException { dis.setInStream(is); Geometry g = readGeometry(); return g; }
/** * Reads a {@link Geometry} from an {@link InStream). * * @param is the stream to read from * @return the Geometry read * @throws IOException * @throws ParseException */ public Geometry read(InStream is) throws IOException, ParseException { dis.setInStream(is); Geometry g = readGeometry(); setSRID(g); return g; }
byte[] bytes = rs.getBytes(1); ByteOrderDataInStream dis = new ByteOrderDataInStream(); dis.setInStream(new ByteArrayInStream(bytes)); byte byteOrder = dis.readByte();
/** * Reads a {@link Geometry} in binary WKB format from an {@link InStream}. * * @param is the stream to read from * @return the Geometry read * @throws IOException if the underlying stream creates an error * @throws ParseException if the WKB is ill-formed */ public Geometry read(InStream is) throws IOException, ParseException { dis.setInStream(is); Geometry g = readGeometry(); return g; }
private void parse(InStream is) throws IOException { dis.setInStream(is); dis.setOrder(ByteOrderValues.LITTLE_ENDIAN); binary.setSrid(dis.readInt()); byte version = dis.readByte(); if (version != 1) { throw new SqlServerBinaryParseException( "Unsupported version (only supports version 1): " + version); } binary.setSerializationProperties(dis.readByte()); readNumberOfPoints(); readCoordinates(); readZValues(); readMValues(); if (binary.isSinglePoint()) { binary.setFigures(new Figure[] {new Figure(1, 0)}); binary.setShapes(new Shape[] {new Shape(-1, 0, 2)}); } else if (binary.hasSingleLineSegment()) { binary.setFigures(new Figure[] {new Figure(1, 0)}); binary.setShapes(new Shape[] {new Shape(-1, 0, 1)}); } else { readFigures(); readShapes(); } }
/** * 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); } }