@Override public void write(WriteBuffer buffer, Geoshape attribute) { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); GeoshapeBinarySerializer.write(outputStream, attribute); byte[] bytes = outputStream.toByteArray(); VariableLong.writePositive(buffer,bytes.length); buffer.putBytes(bytes); } catch (IOException e) { throw new RuntimeException("I/O exception writing 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"); } } }
@Override public void write(Kryo kryo, Output output, Geoshape geoshape) { try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { Geoshape.GeoshapeBinarySerializer.write(outputStream, geoshape); byte[] bytes = outputStream.toByteArray(); output.write(bytes.length); output.write(bytes); } catch (IOException e) { throw new RuntimeException("I/O exception writing geoshape"); } }
@Override public void write(Kryo kryo, Output output, Geoshape geoshape) { try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { Geoshape.GeoshapeBinarySerializer.write(outputStream, geoshape); byte[] bytes = outputStream.toByteArray(); output.write(bytes.length); output.write(bytes); } catch (IOException e) { throw new RuntimeException("I/O exception writing geoshape"); } }
@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) { 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 void write(Kryo kryo, Output output, Geoshape geoshape) { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); GeoshapeBinarySerializer.write(outputStream, geoshape); byte[] bytes = outputStream.toByteArray(); output.writeLong(bytes.length); output.write(bytes); } catch (IOException e) { throw new RuntimeException("I/O exception writing geoshape", e); } }