protected static BigInteger _decodeBigInteger(NSCoder coder, int exponent) { short length = coder.decodeShort(); boolean isNegative = coder.decodeBoolean(); coder.decodeBoolean(); int shortCount = coder.decodeInt(); byte[] bytes = new byte[length * 2]; int i; for (i = 0; i < shortCount; ++i) { short part = coder.decodeShort(); if (i < length) { _copyShortToByteArray(part, bytes, (length - (i + 1)) * 2); } } BigInteger result = new BigInteger((isNegative) ? -1 : 1, bytes); if (exponent != 0) { bytes = new byte[4]; int powerOfTen = 10; for (i = 1; i < exponent; ++i) { powerOfTen *= 10; } _copyIntToByteArray(powerOfTen, bytes, 0); BigInteger factor = new BigInteger(bytes); result = (exponent > 0) ? result.multiply(factor) : result.divide(factor); } return result; }
protected static void _encodeUTF8(String string, NSCoder coder) { byte[] bytes = null; try { bytes = string.getBytes(_UTF8StringEncoding); } catch (UnsupportedEncodingException exception) { throw NSForwardException._runtimeExceptionForThrowable(exception); } coder.encodeBytes(bytes); }
protected static String _decodeUTF8(NSCoder coder) { byte[] bytes = coder.decodeBytes(); String result; try { result = new String(bytes, _UTF8StringEncoding); } catch (UnsupportedEncodingException exception) { throw NSForwardException._runtimeExceptionForThrowable(exception); } return result; }
public Object decodeObject(NSCoder coder) { String type = _decodeUTF8(coder); switch (type.charAt(0)) { case 'c': return new Byte(coder.decodeByte()); case 's': return new Short(coder.decodeShort()); case 'i': return new Integer(coder.decodeInt()); case 'l': return new Long(coder.decodeLong()); case 'f': return new Float(coder.decodeFloat()); case 'd': return new Double(coder.decodeDouble()); case 'e': case 'g': case 'h': case 'j': case 'k': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': } throw new IllegalStateException("decodeObject: unsupported number type: " + type); }
public void encodeWithCoder(Object receiver, NSCoder coder) { int scale = ((BigDecimal) receiver).scale(); BigInteger mantissa = ((BigDecimal) receiver).movePointRight(scale).toBigInteger(); int byteLength = mantissa.bitLength(); while (++byteLength / 8 > _MaxMantissaSize) { int byteDifference = byteLength - _MaxMantissaSize; if (byteDifference > _MaxByteDifference) { byteDifference = _MaxByteDifference; } int exponentDelta = (int) _logBaseTen(Math.pow(2.0D, 8 * byteDifference)); BigInteger divisor = new BigInteger("10").pow(exponentDelta); scale -= exponentDelta; mantissa = mantissa.divide(divisor); } coder.encodeInt(-scale); _encodeBigInteger(coder, mantissa); }
protected static void _encodeBigInteger(NSCoder coder, BigInteger bigInteger) { BigInteger integer = bigInteger; boolean isNegative = integer.signum() < 0; if (isNegative) { integer = integer.negate(); } byte[] bytes = integer.toByteArray(); int length = bytes.length; short shortCount = (short) (length / 2 + length % 2); coder.encodeShort(shortCount); coder.encodeBoolean(isNegative); coder.encodeBoolean(false); coder.encodeInt(8); for (int i = 0; i < _MaxShortArrayLength; ++i) if (i < shortCount) coder.encodeShort(_shortFromByteArray(bytes, length - (2 * (i + 1)))); else coder.encodeShort((short) 0); }
public void encodeWithCoder(Object receiver, NSCoder coder) { _encodeUTF8("c", coder); coder.encodeByte(((Byte) receiver).byteValue()); }
public Object decodeObject(NSCoder coder) { return ((coder.decodeBoolean()) ? Boolean.TRUE : Boolean.FALSE); }
public void encodeWithCoder(Object receiver, NSCoder coder) { coder.encodeBoolean(((Boolean) receiver).booleanValue()); }
public Object decodeObject(NSCoder coder) { double seconds = coder.decodeDouble(); long milliseconds = (long) seconds * 1000L; return new Date(milliseconds); }
public void encodeWithCoder(Object receiver, NSCoder coder) { long milliseconds = ((Date) receiver).getTime(); double seconds = milliseconds / 1000L; coder.encodeDouble(seconds); }
public Object decodeObject(NSCoder coder) { return new Character(coder.decodeChar()); }
public static Object decodeObject(NSCoder coder) { return new NSSet<Object>(coder.decodeObjects()); }
public void encodeWithCoder(Object receiver, NSCoder coder) { coder.encodeInt(0); _encodeBigInteger(coder, (BigInteger) receiver); }
public void encodeWithCoder(Object receiver, NSCoder coder) { _encodeUTF8("s", coder); coder.encodeShort(((Short) receiver).shortValue()); }
public void encodeWithCoder(Object receiver, NSCoder coder) { _encodeUTF8("i", coder); coder.encodeInt(((Integer) receiver).intValue()); }
public void encodeWithCoder(Object receiver, NSCoder coder) { _encodeUTF8("l", coder); coder.encodeLong(((Long) receiver).longValue()); }
public void encodeWithCoder(Object receiver, NSCoder coder) { _encodeUTF8("f", coder); coder.encodeFloat(((Float) receiver).floatValue()); }
public void encodeWithCoder(Object receiver, NSCoder coder) { _encodeUTF8("d", coder); coder.encodeDouble(((Double) receiver).doubleValue()); }
public Object decodeObject(NSCoder coder) { int exponent = coder.decodeInt(); BigInteger mantissa = _decodeBigInteger(coder, (exponent > 0) ? exponent : 0); return new BigDecimal(mantissa, (exponent > 0) ? 0 : -exponent); }
public void encodeWithCoder(Object receiver, NSCoder coder) { coder.encodeChar(((Character) receiver).charValue()); }
public Object decodeObject(NSCoder coder) { int exponent = coder.decodeInt(); return _decodeBigInteger(coder, exponent); }
public void encodeWithCoder(NSCoder coder) { coder.encodeObjects(objectsNoCopy()); }