Package net.razorvine.pickle

Examples of net.razorvine.pickle.PickleException


      return createTime(args);
    if (this.pythontype == DATETIME)
      return createDateTime(args);
    if (this.pythontype == TIMEDELTA)
      return createTimedelta(args);
    throw new PickleException("invalid object type");
  }
View Full Code Here


  private TimeDelta createTimedelta(Object[] args) {
    // python datetime.timedelta -> dt.TimeDelta
    // args is a tuple of 3 ints: days,seconds,microseconds
    if (args.length != 3)
      throw new PickleException("invalid pickle data for timedelta; expected 3 args, got "+args.length);
    int days=((Number)args[0]).intValue();
    int seconds=((Number)args[1]).intValue();
    int micro=((Number)args[2]).intValue();
    return new TimeDelta(days, seconds, micro);
  }
View Full Code Here

  private Calendar createDateTime(Object[] args) {
    // python datetime.time --> GregorianCalendar
    // args is 10 bytes: yhi, ylo, month, day, hour, minute, second, ms1, ms2, ms3
    // (can be String or byte[])
    if (args.length != 1)
      throw new PickleException("invalid pickle data for datetime; expected 1 arg, got "+args.length);
   
    int yhi, ylo, month, day, hour, minute, second, microsec;
    if(args[0] instanceof String) {
      String params = (String) args[0];
      if (params.length() != 10)
        throw new PickleException("invalid pickle data for datetime; expected arg of length 10, got length "+params.length());
      yhi = params.charAt(0);
      ylo = params.charAt(1);
      month = params.charAt(2) - 1; // blargh: months start at 0 in Java
      day = params.charAt(3);
      hour = params.charAt(4);
      minute = params.charAt(5);
      second = params.charAt(6);
      int ms1 = params.charAt(7);
      int ms2 = params.charAt(8);
      int ms3 = params.charAt(9);
      microsec = ((ms1 << 8) | ms2) << 8 | ms3;
    } else {
      byte[] params=(byte[])args[0];
      if (params.length != 10)
        throw new PickleException("invalid pickle data for datetime; expected arg of length 10, got length "+params.length);
      yhi=params[0]&0xff;
      ylo=params[1]&0xff;
      month=(params[2]&0xff) - 1; // blargh: months start at 0 in java
      day=params[3]&0xff;
      hour=params[4]&0xff;
View Full Code Here

  private Time createTime(Object[] args) {
    // python datetime.time --> Time object
    // args is 6 bytes: hour, minute, second, ms1,ms2,ms3  (String or byte[])
    if (args.length != 1)
      throw new PickleException("invalid pickle data for time; expected 1 arg, got "+args.length);
    int hour, minute, second, microsec;
    if(args[0] instanceof String) {
      String params = (String) args[0];
      if (params.length() != 6)
        throw new PickleException("invalid pickle data for time; expected arg of length 6, got length "+params.length());
      hour = params.charAt(0);
      minute = params.charAt(1);
      second = params.charAt(2);
      int ms1 = params.charAt(3);
      int ms2 = params.charAt(4);
      int ms3 = params.charAt(5);
      microsec = ((ms1 << 8) | ms2) << 8 | ms3;
    } else {
      byte[] params=(byte[])args[0];
      if (params.length != 6)
        throw new PickleException("invalid pickle data for datetime; expected arg of length 6, got length "+params.length);
      hour=params[0]&0xff;
      minute=params[1]&0xff;
      second=params[2]&0xff;
      int ms1 = params[3]&0xff;
      int ms2 = params[4]&0xff;
View Full Code Here

  private Calendar createDate(Object[] args) {
    // python datetime.date --> GregorianCalendar
    // args is a string of 4 bytes yhi, ylo, month, day (String or byte[])
    if (args.length != 1)
      throw new PickleException("invalid pickle data for date; expected 1 arg, got "+args.length);
    int yhi, ylo, month, day;
    if(args[0] instanceof String) {
      String params = (String) args[0];
      if (params.length() != 4)
        throw new PickleException("invalid pickle data for date; expected arg of length 4, got length "+params.length());
      yhi = params.charAt(0);
      ylo = params.charAt(1);
      month = params.charAt(2) - 1; // blargh: months start at 0 in Java
      day = params.charAt(3);
    } else {
      byte[] params=(byte[])args[0];
      if (params.length != 4)
        throw new PickleException("invalid pickle data for date; expected arg of length 4, got length "+params.length);
      yhi=params[0]&0xff;
      ylo=params[1]&0xff;
      month=(params[2]&0xff) - 1; // blargh: months start at 0 in java
      day=params[3]&0xff;
    }
View Full Code Here

    } else if(args.length==1 && args[0] instanceof PyroURI) {
      // constructor with PyroURI arg
      try {
        return new PyroProxy((PyroURI)args[0]);
      } catch (IOException e) {
        throw new PickleException("can't create PyroProxy:" +e.getMessage());
      }
    } else if(args.length==3) {
      // constructor with hostname,port,objectid args
      String hostname=(String)args[0];
      Integer port=(Integer)args[1];
      String objectId=(String)args[2];
      try {
        return new PyroProxy(hostname, port, objectId);
      } catch (IOException e) {
        throw new PickleException("can't create PyroProxy:" +e.getMessage());
      }
    } else {
      throw new PickleException("invalid args for PyroProxy unpickling");
    }
  }
View Full Code Here

        paramtypes[i] = args[i].getClass();
      }
      Constructor<?> cons = type.getConstructor(paramtypes);
      return cons.newInstance(args);
    } catch (Exception x) {
      throw new PickleException("problem construction object: " + x);
    }
  }
View Full Code Here

      int machinecodeType = (Integer) args[2];
      byte[] data = (byte[]) args[3];
      return constructor.construct(typecode, machinecodeType, data);
    }
    if (args.length != 2) {
      throw new PickleException("invalid pickle data for array; expected 2 args, got " + args.length);
    }

    String typecode = (String) args[0];
    @SuppressWarnings("unchecked")
    ArrayList<Object> values = (ArrayList<Object>) args[1];

    switch (typecode.charAt(0)) {
    case 'c':// character 1 -> char[]
    case 'u':// Unicode character 2 -> char[]
    {
      char[] result = new char[values.size()];
      int i = 0;
      for (Object c : values) {
        result[i++] = ((String) c).charAt(0);
      }
      return result;
    }
    case 'b':// signed integer 1 -> byte[]
    {
      byte[] result = new byte[values.size()];
      int i = 0;
      for (Object c : values) {
        result[i++] = ((Number) c).byteValue();
      }
      return result;
    }
    case 'B':// unsigned integer 1 -> short[]
    case 'h':// signed integer 2 -> short[]
    {
      short[] result = new short[values.size()];
      int i = 0;
      for (Object c : values) {
        result[i++] = ((Number) c).shortValue();
      }
      return result;
    }
    case 'H':// unsigned integer 2 -> int[]
    case 'i':// signed integer 2 -> int[]
    case 'l':// signed integer 4 -> int[]
    {
      int[] result = new int[values.size()];
      int i = 0;
      for (Object c : values) {
        result[i++] = ((Number) c).intValue();
      }
      return result;
    }
    case 'I':// unsigned integer 4 -> long[]
    case 'L':// unsigned integer 4 -> long[]
    {
      long[] result = new long[values.size()];
      int i = 0;
      for (Object c : values) {
        result[i++] = ((Number) c).longValue();
      }
      return result;
    }
    case 'f':// floating point 4 -> float[]
    {
      float[] result = new float[values.size()];
      int i = 0;
      for (Object c : values) {
        result[i++] = ((Number) c).floatValue();
      }
      return result;
    }
    case 'd':// floating point 8 -> double[]
    {
      double[] result = new double[values.size()];
      int i = 0;
      for (Object c : values) {
        result[i++] = ((Number) c).doubleValue();
      }
      return result;
    }
    default:
      throw new PickleException("invalid array typecode: " + typecode);
    }
  }
View Full Code Here

    // UTF16_BE = 19
    // UTF32_LE = 20
    // UTF32_BE = 21

    if (machinecode < 0)
      throw new PickleException("unknown machine type format");

    switch (typecode) {
    case 'c':// character 1 -> char[]
    case 'u':// Unicode character 2 -> char[]
    {
      if (machinecode != 18 && machinecode != 19 && machinecode != 20 && machinecode != 21)
        throw new PickleException("for c/u type must be 18/19/20/21");
      if (machinecode == 18 || machinecode == 19) {
        // utf-16 , 2 bytes
        if (data.length % 2 != 0)
          throw new PickleException("data size alignment error");
        return constructCharArrayUTF16(machinecode, data);
      } else {
        // utf-32, 4 bytes
        if (data.length % 4 != 0)
          throw new PickleException("data size alignment error");
        return constructCharArrayUTF32(machinecode, data);
      }
    }
    case 'b':// signed integer 1 -> byte[]
    {
      if (machinecode != 1)
        throw new PickleException("for b type must be 1");
      return data;
    }
    case 'B':// unsigned integer 1 -> short[]
    {
      if (machinecode != 0)
        throw new PickleException("for B type must be 0");
      return constructShortArrayFromUByte(data);
    }
    case 'h':// signed integer 2 -> short[]
    {
      if (machinecode != 4 && machinecode != 5)
        throw new PickleException("for h type must be 4/5");
      if (data.length % 2 != 0)
        throw new PickleException("data size alignment error");
      return constructShortArraySigned(machinecode, data);
    }
    case 'H':// unsigned integer 2 -> int[]
    {
      if (machinecode != 2 && machinecode != 3)
        throw new PickleException("for H type must be 2/3");
      if (data.length % 2 != 0)
        throw new PickleException("data size alignment error");
      return constructIntArrayFromUShort(machinecode, data);
    }
    case 'i':// signed integer 4 -> int[]
    {
      if (machinecode != 8 && machinecode != 9)
        throw new PickleException("for i type must be 8/9");
      if (data.length % 4 != 0)
        throw new PickleException("data size alignment error");
      return constructIntArrayFromInt32(machinecode, data);
    }
    case 'l':// signed integer 4/8 -> int[]
    {
      if (machinecode != 8 && machinecode != 9 && machinecode != 12 && machinecode != 13)
        throw new PickleException("for l type must be 8/9/12/13");
      if ((machinecode==8 || machinecode==9) && (data.length % 4 != 0))
        throw new PickleException("data size alignment error");
      if ((machinecode==12 || machinecode==13) && (data.length % 8 != 0))
        throw new PickleException("data size alignment error");
      if(machinecode==8 || machinecode==9) {
        //32 bits
        return constructIntArrayFromInt32(machinecode, data);
      } else {
        //64 bits
        return constructLongArrayFromInt64(machinecode, data);
      }
    }
    case 'I':// unsigned integer 4 -> long[]
    {
      if (machinecode != 6 && machinecode != 7)
        throw new PickleException("for I type must be 6/7");
      if (data.length % 4 != 0)
        throw new PickleException("data size alignment error");
      return constructLongArrayFromUInt32(machinecode, data);
    }
    case 'L':// unsigned integer 4/8 -> long[]
    {
      if (machinecode != 6 && machinecode != 7 && machinecode != 10 && machinecode != 11)
        throw new PickleException("for L type must be 6/7/10/11");
      if ((machinecode==6 || machinecode==7) && (data.length % 4 != 0))
        throw new PickleException("data size alignment error");
      if ((machinecode==10 || machinecode==11) && (data.length % 8 != 0))
        throw new PickleException("data size alignment error");
      if(machinecode==6 || machinecode==7) {
        // 32 bits
        return constructLongArrayFromUInt32(machinecode, data);
      } else {
        // 64 bits
        return constructLongArrayFromUInt64(machinecode, data);
      }
    }
    case 'f':// floating point 4 -> float[]
    {
      if (machinecode != 14 && machinecode != 15)
        throw new PickleException("for f type must be 14/15");
      if (data.length % 4 != 0)
        throw new PickleException("data size alignment error");
      return constructFloatArray(machinecode, data);
    }
    case 'd':// floating point 8 -> double[]
    {
      if (machinecode != 16 && machinecode != 17)
        throw new PickleException("for d type must be 16/17");
      if (data.length % 8 != 0)
        throw new PickleException("data size alignment error");
      return constructDoubleArray(machinecode, data);
    }
    default:
      throw new PickleException("invalid array typecode: " + typecode);
    }
  }
View Full Code Here

    return result;
  }

  protected long[] constructLongArrayFromUInt64(int machinecode, byte[] data) {
    // java doesn't have a ulong (unsigned int 64-bits) datatype
    throw new PickleException("unsupported datatype: 64-bits unsigned long");
  }
View Full Code Here

TOP

Related Classes of net.razorvine.pickle.PickleException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.