@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 write(final DataOutput out) throws IOException { out.writeInt(this.list.size()); for (final V value : this.list) { value.write(out); } }
@Override public void read(final DataInput 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 e) { throw new RuntimeException(e); } catch (final IllegalAccessException e) { throw new RuntimeException(e); } }
@Override public void read(final DataInput 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 e) { throw new RuntimeException(e); } catch (final IllegalAccessException e) { throw new RuntimeException(e); } }
@Override public void write(final DataOutput out) throws IOException { out.writeInt(this.list.size()); for (final V value : this.list) { value.write(out); } }
@Override public void read(final DataInput 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); } }
@Override public void read(final DataInput 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); } }
@Override public void write(DataOutput out) throws IOException { int num = this.aggNames.length; out.writeInt(num); ByteArrayOutputStream boas = new ByteArrayOutputStream(); DataOutputStream bufferStream = new DataOutputStream(boas); for (int i = 0; i < num; i++) { // aggregator name and type out.writeUTF(this.aggNames[i]); out.writeUTF(this.aggregates[i].getClass().getName()); // aggregator value indirect as a byte array this.aggregates[i].write(bufferStream); bufferStream.flush(); byte[] bytes = boas.toByteArray(); out.writeInt(bytes.length); out.write(bytes); boas.reset(); } bufferStream.close(); boas.close(); }
@Override public int compare(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 write(DataOutput out) throws IOException { int num = this.aggNames.length; out.writeInt(num); ByteArrayOutputStream boas = new ByteArrayOutputStream(); DataOutputStream bufferStream = new DataOutputStream(boas); for (int i = 0; i < num; i++) { // aggregator name and type out.writeUTF(this.aggNames[i]); out.writeUTF(this.aggregates[i].getClass().getName()); // aggregator value indirect as a byte array this.aggregates[i].write(bufferStream); bufferStream.flush(); byte[] bytes = boas.toByteArray(); out.writeInt(bytes.length); out.write(bytes); boas.reset(); } bufferStream.close(); boas.close(); }
/** * 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 final <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); } }
this.writeFields[i].write(serializer);
/** * 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 final <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); } }
this.writeFields[i].write(serializer);
v.read(in); in.close(); } catch (IOException 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 {