/** * Constructor for deserialization. * @param planetModel is the planet model. * @param inputStream is the input stream. */ public GeoS2Shape(final PlanetModel planetModel, final InputStream inputStream) throws IOException { this(planetModel, (GeoPoint) SerializableObject.readObject(inputStream), (GeoPoint) SerializableObject.readObject(inputStream), (GeoPoint) SerializableObject.readObject(inputStream), (GeoPoint) SerializableObject.readObject(inputStream)); }
@Override public Point readPoint(DataInput dataInput) throws IOException { SerializableObject serializableObject = SerializableObject.readObject(planetModel, (InputStream) dataInput); if (serializableObject instanceof GeoPointShape) { GeoPointShape shape = (GeoPointShape) serializableObject; return new Geo3dPointShape(shape, ctx); } throw new IllegalArgumentException("trying to read a not supported point shape: " + serializableObject.getClass()); }
@Override public Shape readShape(DataInput dataInput) throws IOException { SerializableObject serializableObject = SerializableObject.readObject(planetModel, (InputStream) dataInput); if (serializableObject instanceof GeoAreaShape) { GeoAreaShape shape = (GeoAreaShape) serializableObject; return new Geo3dShape<>(shape, ctx); } throw new IllegalArgumentException("trying to read a not supported shape: " + serializableObject.getClass()); }
@Override public Circle readCircle(DataInput dataInput) throws IOException { SerializableObject serializableObject = SerializableObject.readObject(planetModel, (InputStream) dataInput); if (serializableObject instanceof GeoCircle) { GeoCircle shape = (GeoCircle) serializableObject; return new Geo3dCircleShape(shape, ctx); } throw new IllegalArgumentException("trying to read a not supported circle shape: " + serializableObject.getClass()); }
/** Read a PlanetObject from a stream. * @param inputStream is the input stream. * @return the PlanetObject. */ public static PlanetObject readPlanetObject(final InputStream inputStream) throws IOException { final PlanetModel pm = new PlanetModel(inputStream); final SerializableObject so = readObject(pm, inputStream); if (!(so instanceof PlanetObject)) { throw new IOException("Type of object is not expected PlanetObject: "+so.getClass().getName()); } return (PlanetObject)so; }
@Override public Rectangle readRect(DataInput dataInput) throws IOException { SerializableObject serializableObject = SerializableObject.readObject(planetModel, (InputStream) dataInput); if (serializableObject instanceof GeoBBox) { GeoBBox shape = (GeoBBox) serializableObject; return new Geo3dRectangleShape(shape, ctx); } throw new IllegalArgumentException("trying to read a not supported rectangle shape: " + serializableObject.getClass()); }
/** Read an object from a stream (for objects that do not need a PlanetModel). * @param inputStream is the input stream. * @return the deserialized object. */ public static SerializableObject readObject(final InputStream inputStream) throws IOException { try { // read the class final Class<?> clazz = readClass(inputStream); return readObject(inputStream, clazz); } catch (ClassNotFoundException e) { throw new IOException("Can't find class for deserialization: "+e.getMessage(), e); } }
/** Read an array. * @param planetModel is the planet model. * @param inputStream is the input stream. * @param clazz is the class of the objects to read. * @return the array. */ static <T extends SerializableObject> T[] readHomogeneousArray(final PlanetModel planetModel, final InputStream inputStream, final Class<T> clazz) throws IOException { final int count = readInt(inputStream); @SuppressWarnings("unchecked") final T[] rval = (T[])Array.newInstance(clazz, count); for (int i = 0; i < count; i++) { rval[i] = clazz.cast(readObject(planetModel, inputStream, clazz)); } return rval; }
/** Read an object from a stream (for objects that need a PlanetModel). * @param planetModel is the planet model to use to deserialize the object. * @param inputStream is the input stream. * @return the deserialized object. */ public static SerializableObject readObject(final PlanetModel planetModel, final InputStream inputStream) throws IOException { try { // Read the class final Class<?> clazz = readClass(inputStream); return readObject(planetModel, inputStream, clazz); } catch (ClassNotFoundException e) { throw new IOException("Can't find class for deserialization: "+e.getMessage(), e); } }
/** Read an array. * @param planetModel is the planet model. * @param inputStream is the input stream. * @return the array. */ static <T extends SerializableObject> T[] readHeterogeneousArray(final PlanetModel planetModel, final InputStream inputStream, final Class<T> clazz) throws IOException { final int count = readInt(inputStream); @SuppressWarnings("unchecked") final T[] rval = (T[])Array.newInstance(clazz, count); for (int i = 0; i < count; i++) { rval[i] = clazz.cast(readObject(planetModel, inputStream)); } return rval; }