Ejemplo n.º 1
0
    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;
    }
Ejemplo n.º 2
0
    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);
    }
Ejemplo n.º 3
0
    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;
    }
Ejemplo n.º 4
0
    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);
    }
Ejemplo n.º 5
0
    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);
    }
Ejemplo n.º 6
0
    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);
    }
Ejemplo n.º 7
0
 public void encodeWithCoder(Object receiver, NSCoder coder) {
   _encodeUTF8("c", coder);
   coder.encodeByte(((Byte) receiver).byteValue());
 }
Ejemplo n.º 8
0
 public Object decodeObject(NSCoder coder) {
   return ((coder.decodeBoolean()) ? Boolean.TRUE : Boolean.FALSE);
 }
Ejemplo n.º 9
0
 public void encodeWithCoder(Object receiver, NSCoder coder) {
   coder.encodeBoolean(((Boolean) receiver).booleanValue());
 }
Ejemplo n.º 10
0
    public Object decodeObject(NSCoder coder) {
      double seconds = coder.decodeDouble();
      long milliseconds = (long) seconds * 1000L;

      return new Date(milliseconds);
    }
Ejemplo n.º 11
0
    public void encodeWithCoder(Object receiver, NSCoder coder) {
      long milliseconds = ((Date) receiver).getTime();
      double seconds = milliseconds / 1000L;

      coder.encodeDouble(seconds);
    }
Ejemplo n.º 12
0
 public Object decodeObject(NSCoder coder) {
   return new Character(coder.decodeChar());
 }
Ejemplo n.º 13
0
 public static Object decodeObject(NSCoder coder) {
   return new NSSet<Object>(coder.decodeObjects());
 }
Ejemplo n.º 14
0
 public void encodeWithCoder(Object receiver, NSCoder coder) {
   coder.encodeInt(0);
   _encodeBigInteger(coder, (BigInteger) receiver);
 }
Ejemplo n.º 15
0
 public void encodeWithCoder(Object receiver, NSCoder coder) {
   _encodeUTF8("s", coder);
   coder.encodeShort(((Short) receiver).shortValue());
 }
Ejemplo n.º 16
0
 public void encodeWithCoder(Object receiver, NSCoder coder) {
   _encodeUTF8("i", coder);
   coder.encodeInt(((Integer) receiver).intValue());
 }
Ejemplo n.º 17
0
 public void encodeWithCoder(Object receiver, NSCoder coder) {
   _encodeUTF8("l", coder);
   coder.encodeLong(((Long) receiver).longValue());
 }
Ejemplo n.º 18
0
 public void encodeWithCoder(Object receiver, NSCoder coder) {
   _encodeUTF8("f", coder);
   coder.encodeFloat(((Float) receiver).floatValue());
 }
Ejemplo n.º 19
0
 public void encodeWithCoder(Object receiver, NSCoder coder) {
   _encodeUTF8("d", coder);
   coder.encodeDouble(((Double) receiver).doubleValue());
 }
Ejemplo n.º 20
0
    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);
    }
Ejemplo n.º 21
0
 public void encodeWithCoder(Object receiver, NSCoder coder) {
   coder.encodeChar(((Character) receiver).charValue());
 }
Ejemplo n.º 22
0
 public Object decodeObject(NSCoder coder) {
   int exponent = coder.decodeInt();
   return _decodeBigInteger(coder, exponent);
 }
Ejemplo n.º 23
0
 public void encodeWithCoder(NSCoder coder) {
   coder.encodeObjects(objectsNoCopy());
 }