@Test
  @Ignore
  public void encode() {
    StopWatch stopWatch = new StopWatch();
    Coder coder = new JsonSmartCoder();

    stopWatch.start();
    byte[] bytes = coder.encode(new Bean());
    stopWatch.stop();

    System.out.printf("Encoded %d bytes in %s:%n%s%n", bytes.length, stopWatch, new String(bytes));

    Bean bean = coder.decode(bytes);
    System.out.println(bean);
  }
 @Override
 public String toString() {
   StringBuilder b = new StringBuilder();
   for (byte[] bs : this.commandElems) {
     b.append(Coder.bytesToString(bs));
     b.append(' ');
   }
   return b.toString();
 }
 /**
  * @Title: decrypt2BytesByDES @Description: TODO
  *
  * @param @param encryptBytes
  * @param @param key
  * @param @param charsetName
  * @param @return
  * @return byte[]
  * @throws
  */
 public static final byte[] decrypt2BytesByDES(byte[] decryptBytes, String charsetName) {
   byte[] encryptedBytes = null;
   try {
     String MD5Key = new String(Coder.encryptMD5(getBytes(key, charsetName)));
     String initkey = DESCoder.initKey(MD5Key);
     encryptedBytes = DESCoder.decrypt(decryptBytes, initkey);
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return encryptedBytes;
 }
示例#4
0
 public double code(int nodeInx, double[] codingDist) {
   double obsProb =
       codingDist[
           Integer.parseInt(
               SV.get(nodeInx).obs(),
               SV.get(nodeInx)
                   .r)]; // find out what was observed and record its probability for rate
                         // calulation
   // System.out.println("OBSERVED: "+SV.get(nodeInx).obs()+"
   // "+Integer.parseInt(SV.get(nodeInx).obs(),SV.get(nodeInx).r));
   // System.out.println(SV.get(nodeInx).V.size()+" nodes in supernode");
   return Coder.log2_1overpx(obsProb)
       / (double)
           SV.get(nodeInx)
               .V
               .size(); // return rate calculation (shannon-fano to code i.e. log_2(1/p(x)))
 }
  /**
   * Constructor for {@link Command}. Must initialize Command with a {@link SocketChannel} and a
   * {@link List} of command elements
   *
   * @param commandElems List of elements in command
   */
  public Command(List<byte[]> commandElems) {
    if (commandElems == null || commandElems.isEmpty())
      throw new IllegalArgumentException(
          "List of command elements cannot be empty -> List:" + commandElems);
    this.commandElems = commandElems;
    this.response = null;

    RedisCommandType type;

    try {
      byte[] charCommand = commandElems.get(0);
      String commandName = Coder.bytesToString(charCommand).toUpperCase();
      type = RedisCommandType.valueOf(commandName);
    } catch (Exception e) {
      type = RedisCommandType.UNKNOWN;
    }
    this.commandType = type;
  }
示例#6
0
 public static String create(Connection c, Details d) throws XmlRpcException {
   Object[] params = {d.toJson()};
   String res = (String) c.call("OvmNetwork.createVlan", params);
   Details ret = Coder.fromJson(res, Details.class);
   return ret.name;
 }
示例#7
0
 public String toJson() {
   return Coder.toJson(this);
 }
 public void start() {
   coder.writeCode();
 }
 public static void doWork(Person person) {
   if (person instanceof User) ((User) person).live();
   else if (person instanceof Looser) ((Looser) person).doNothing();
   else if (person instanceof Coder) ((Coder) person).coding();
   else if (person instanceof Proger) ((Proger) person).enjoy(); // пункт 3
 }