/** * 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); }
/** * 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); } }