Package net.razorvine.pickle

Examples of net.razorvine.pickle.PickleException


    for (int index = 0; index < data.length / 4; ++index) {
      if (machinecode == 20) {
        int codepoint=PickleUtils.bytes_to_integer(data, index*4, 4);
        char[] cc=Character.toChars(codepoint);
        if(cc.length>1)
          throw new PickleException("cannot process UTF-32 character codepoint "+codepoint);
        result[index] = cc[0];
      }
      else {
        // big endian, swap
        bigendian[0]=data[3+index*4];
        bigendian[1]=data[2+index*4];
        bigendian[2]=data[1+index*4];
        bigendian[3]=data[index*4];
        int codepoint=PickleUtils.bytes_to_integer(bigendian);
        char[] cc=Character.toChars(codepoint);
        if(cc.length>1)
          throw new PickleException("cannot process UTF-32 character codepoint "+codepoint);
        result[index] = cc[0];
      }
    }
    return result;
  }
View Full Code Here


  public Object construct(Object[] args) throws PickleException {
    // args for bytearray constructor: [ String string, String encoding ]
    // args for bytearray constructor (from python3 bytes): [ ArrayList<Number> ]
    if (args.length != 1 && args.length != 2)
      throw new PickleException("invalid pickle data for bytearray; expected 1 or 2 args, got "+args.length);

    if(args.length==1) {
      @SuppressWarnings("unchecked")
      ArrayList<Number>values=(ArrayList<Number>)args[0];
      byte[] data=new byte[values.size()];
      for(int i=0; i<data.length; ++i) {
        data[i] = values.get(i).byteValue();
      }
      return data;
    } else {
      String data = (String) args[0];
      String encoding = (String) args[1];
      if (encoding.startsWith("latin-"))
        encoding = "ISO-8859-" + encoding.substring(6);
      try {
        return data.getBytes(encoding);
      } catch (UnsupportedEncodingException e) {
        throw new PickleException("error creating bytearray: " + e);
      }
    }
  }
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.