@Override public T deserialize(T reuse, DataInputView source) throws IOException { reuse.read(source); return reuse; }
@Override public void serialize(T value, DataOutputView target) throws IOException { value.write(target); }
@Override public int compareSerialized(DataInputView firstSource, DataInputView secondSource) throws IOException { if (reference == null) { reference = InstantiationUtil.instantiate(type, Value.class); } if (tempReference == null) { tempReference = InstantiationUtil.instantiate(type, Value.class); } reference.read(firstSource); tempReference.read(secondSource); int comp = reference.compareTo(tempReference); return ascendingComparison ? comp : -comp; }
@Override public void read(final DataInputView in) throws IOException { int size = in.readInt(); this.map.clear(); try { for (; size > 0; size--) { final K key = this.keyClass.newInstance(); final V val = this.valueClass.newInstance(); key.read(in); val.read(in); this.map.put(key, val); } } catch (final InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } }
@Override public void write(final DataOutputView out) throws IOException { out.writeInt(this.list.size()); for (final V value : this.list) { value.write(out); } }
@Override public void read(final DataInputView in) throws IOException { int size = in.readInt(); this.list.clear(); try { for (; size > 0; size--) { final V val = this.valueClass.newInstance(); val.read(in); this.list.add(val); } } catch (final InstantiationException e) { throw new RuntimeException(e); } catch (final IllegalAccessException e) { throw new RuntimeException(e); } }
this.writeFields[i].write(serializer);
public static <T extends Value> T writeAndReadValue(Class<T> clazz, T in) throws Exception { // write to byte[] java.io.ByteArrayOutputStream outStream = new java.io.ByteArrayOutputStream(); DataOutputView dataOutputView = new DataOutputViewStreamWrapper(outStream); in.write(dataOutputView); T out; try { out = clazz.newInstance(); } catch (Exception e) { e.printStackTrace(); throw new IOException("Cannot initialize the class: " + clazz); } // read from byte[] ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray()); DataInputView dataInputView = new DataInputViewStreamWrapper(inStream); out.read(dataInputView); return out; }
/** * Deserializes the given object from the binary string, starting at the given position. * If the deserialization asks for more that <code>limit - offset</code> bytes, than * an exception is thrown. * * @param <T> The generic type of the value to be deserialized. * @param target The object to deserialize the data into. * @param offset The offset in the binary string. * @param limit The limit in the binary string. */ private <T extends Value> void deserialize(T target, int offset, int limit, int fieldNumber) { final InternalDeSerializer serializer = this.serializer; serializer.memory = this.binaryData; serializer.position = offset; serializer.end = limit; try { target.read(serializer); } catch (Exception e) { throw new DeserializationException("Error reading field " + fieldNumber + " as " + target.getClass().getName(), e); } }
other.writeFields[i].write(this.serializer); lengths[i] = this.serializer.position - offsets[i]; } else { this.writeFields[i].write(this.serializer); lengths[i] = this.serializer.position - offsets[i]; } else { sourceForRemainder.writeFields[k].write(this.serializer); lengths[k] = this.serializer.position - offsets[k]; } else {
public static <T extends Value> T writeAndReadFields(Class<T> clazz, T in) throws IOException { // write to byte[] ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); DataOutputView outputView = new DataOutputViewStreamWrapper(outputStream); in.write(outputView); outputStream.flush(); T out; try { out = clazz.newInstance(); } catch (Exception e) { e.printStackTrace(); throw new IOException("Cannot initialize the class: " + clazz); } // read from byte[] ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); DataInputView inputView = new DataInputViewStreamWrapper(inputStream); out.read(inputView); return out; }
@Override public T deserialize(T reuse, DataInputView source) throws IOException { reuse.read(source); return reuse; }
@Override public void serialize(T value, DataOutputView target) throws IOException { value.write(target); }
@Override public T deserialize(T reuse, DataInputView source) throws IOException { reuse.read(source); return reuse; }
@Override public void serialize(T value, DataOutputView target) throws IOException { value.write(target); }
@Override public void read(final DataInputView in) throws IOException { int size = in.readInt(); this.map.clear(); try { for (; size > 0; size--) { final K key = this.keyClass.newInstance(); final V val = this.valueClass.newInstance(); key.read(in); val.read(in); this.map.put(key, val); } } catch (final InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } }