/** * Reads the state from the stream. * * @param in the input stream, not null * @return the created object, not null * @throws IOException if an error occurs */ static ZoneRules readExternal(DataInput in) throws IOException, ClassNotFoundException { int stdSize = in.readInt(); long[] stdTrans = (stdSize == 0) ? EMPTY_LONG_ARRAY : new long[stdSize]; for (int i = 0; i < stdSize; i++) { stdTrans[i] = Ser.readEpochSec(in); } ZoneOffset[] stdOffsets = new ZoneOffset[stdSize + 1]; for (int i = 0; i < stdOffsets.length; i++) { stdOffsets[i] = Ser.readOffset(in); } int savSize = in.readInt(); long[] savTrans = (savSize == 0) ? EMPTY_LONG_ARRAY : new long[savSize]; for (int i = 0; i < savSize; i++) { savTrans[i] = Ser.readEpochSec(in); } ZoneOffset[] savOffsets = new ZoneOffset[savSize + 1]; for (int i = 0; i < savOffsets.length; i++) { savOffsets[i] = Ser.readOffset(in); } int ruleSize = in.readByte(); ZoneOffsetTransitionRule[] rules = (ruleSize == 0) ? EMPTY_LASTRULES : new ZoneOffsetTransitionRule[ruleSize]; for (int i = 0; i < ruleSize; i++) { rules[i] = ZoneOffsetTransitionRule.readExternal(in); } return new ZoneRules(stdTrans, stdOffsets, savTrans, savOffsets, rules); }
/** * Reads the state from the stream. * * @param in the input stream, not null * @return the created object, not null * @throws IOException if an error occurs */ static ZoneOffsetTransition readExternal(DataInput in) throws IOException { long epochSecond = Ser.readEpochSec(in); ZoneOffset before = Ser.readOffset(in); ZoneOffset after = Ser.readOffset(in); if (before.equals(after)) { throw new IllegalArgumentException("Offsets must not be equal"); } return new ZoneOffsetTransition(epochSecond, before, after); }
private static <T> void test(String label, Box<T> m, Ser<T> ser) throws Exception { long start = Time.now(); byte[] bytes = null; for (int i = 0; i < 1000000; i++) { bytes = ser.toBytes(m.get()); ser.fromBytes(bytes); } System.out.println(label + " ms: " + Time.since(start) + ", size: " + bytes.length); }
/** * Writes the state to the stream. * * @param out the output stream, not null * @throws IOException if an error occurs */ void writeExternal(DataOutput out) throws IOException { out.writeInt(standardTransitions.length); for (long trans : standardTransitions) { Ser.writeEpochSec(trans, out); } for (ZoneOffset offset : standardOffsets) { Ser.writeOffset(offset, out); } out.writeInt(savingsInstantTransitions.length); for (long trans : savingsInstantTransitions) { Ser.writeEpochSec(trans, out); } for (ZoneOffset offset : wallOffsets) { Ser.writeOffset(offset, out); } out.writeByte(lastRules.length); for (ZoneOffsetTransitionRule rule : lastRules) { rule.writeExternal(out); } }
/** * Writes the state to the stream. * * @param out the output stream, not null * @throws IOException if an error occurs */ void writeExternal(DataOutput out) throws IOException { Ser.writeEpochSec(toEpochSecond(), out); Ser.writeOffset(offsetBefore, out); Ser.writeOffset(offsetAfter, out); }
/** * Reads the state from the stream. * * @param in the input stream, not null * @return the created object, not null * @throws IOException if an error occurs */ static ZoneOffsetTransition readExternal(DataInput in) throws IOException { long epochSecond = Ser.readEpochSec(in); ZoneOffset before = Ser.readOffset(in); ZoneOffset after = Ser.readOffset(in); return ZoneOffsetTransition.of(OffsetDateTime.ofEpochSecond(epochSecond, before), after); }
/** * Writes the state to the stream. * * @param out the output stream, not null * @throws IOException if an error occurs */ void writeExternal(DataOutput out) throws IOException { Ser.writeEpochSec(transition.toEpochSecond(), out); Ser.writeOffset(transition.getOffset(), out); Ser.writeOffset(transitionAfter.getOffset(), out); }