@Override public Geoshape read(Kryo kryo, Input input, Class<Geoshape> aClass) { final long l = input.readLong(); assert l>0 && l<Integer.MAX_VALUE; final int length = (int) l; try { final InputStream inputStream = new ByteArrayInputStream(input.readBytes(length)); return GeoshapeBinarySerializer.read(inputStream); } catch (IOException | KryoException e) { // retry using legacy point deserialization try { input.setPosition(0); input.readLong(); final float lat = input.readFloat(); final float lon = input.readFloat(); return point(lat, lon); } catch (KryoException ignored) { } // throw original exception throw new RuntimeException("I/O exception reading geoshape", e); } } }
@Override public Geoshape read(ScanBuffer buffer) { long l = VariableLong.readPositive(buffer); assert l>0 && l<Integer.MAX_VALUE; int length = (int)l; int position = ((ReadArrayBuffer) buffer).getPosition(); InputStream inputStream = new ByteArrayInputStream(buffer.getBytes(length)); try { return GeoshapeBinarySerializer.read(inputStream); } catch (IOException e) { // retry using legacy point deserialization try { ((ReadArrayBuffer) buffer).movePositionTo(position); final float lat = buffer.getFloat(); final float lon = buffer.getFloat(); return point(lat, lon); } catch (Exception ignored) { } // throw original exception throw new RuntimeException("I/O exception reading geoshape", e); } }
@Override public Geoshape read(Kryo kryo, Input input, Class<Geoshape> aClass) { int length = input.read(); Preconditions.checkArgument(length>0); try (InputStream inputStream = new ByteArrayInputStream(input.readBytes(length))) { return Geoshape.GeoshapeBinarySerializer.read(inputStream); } catch (IOException e) { throw new RuntimeException("I/O exception reading geoshape"); } } }
@Override public Geoshape read(Kryo kryo, Input input, Class<Geoshape> aClass) { int length = input.read(); Preconditions.checkArgument(length>0); try (InputStream inputStream = new ByteArrayInputStream(input.readBytes(length))) { return Geoshape.GeoshapeBinarySerializer.read(inputStream); } catch (IOException e) { throw new RuntimeException("I/O exception reading geoshape"); } } }