/** * Uses a serialization delegate. * * @return the replacing object, never null */ private Object writeReplace() { return new Ser(Ser.CURRENCY_UNIT, this); }
/** * Outputs the data. * * @param in the input stream * @throws IOException if an error occurs */ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { type = in.readByte(); switch (type) { case BIG_MONEY: { object = readBigMoney(in); return; } case MONEY: { object = new Money(readBigMoney(in)); return; } case CURRENCY_UNIT: { object = readCurrency(in); return; } } throw new StreamCorruptedException("Serialization input has invalid type"); }
/** * Outputs the data. * * @serialData One byte type code, then data specific to the type. * @param out the output stream * @throws IOException if an error occurs */ @Override public void writeExternal(ObjectOutput out) throws IOException { out.writeByte(type); switch (type) { case BIG_MONEY: { BigMoney obj = (BigMoney) object; writeBigMoney(out, obj); return; } case MONEY: { Money obj = (Money) object; writeBigMoney(out, obj.toBigMoney()); return; } case CURRENCY_UNIT: { CurrencyUnit obj = (CurrencyUnit) object; writeCurrency(out, obj); return; } } throw new InvalidClassException("Joda-Money bug: Serialization broken"); }
private BigMoney readBigMoney(ObjectInput in) throws IOException { CurrencyUnit currency = readCurrency(in); byte[] bytes = new byte[in.readInt()]; in.readFully(bytes); BigDecimal bd = new BigDecimal(new BigInteger(bytes), in.readInt()); BigMoney bigMoney = new BigMoney(currency, bd); return bigMoney; }
private void writeBigMoney(ObjectOutput out, BigMoney obj) throws IOException { writeCurrency(out, obj.getCurrencyUnit()); byte[] bytes = obj.getAmount().unscaledValue().toByteArray(); out.writeInt(bytes.length); out.write(bytes); out.writeInt(obj.getScale()); }
/** * Uses a serialization delegate. * * @return the replacing object, never null */ private Object writeReplace() { return new Ser(Ser.BIG_MONEY, this); }
/** * Uses a serialization delegate. * * @return the replacing object, never null */ private Object writeReplace() { return new Ser(Ser.MONEY, this); }