예제 #1
0
 public byte[] digest(byte[] input) {
   String function = DigestFunction.class.getCanonicalName();
   String uniqueId = null;
   byte[] algoNameBytes = ALGO_NAME.getBytes();
   byte[] digestParms = new byte[input.length + algoNameBytes.length + 1];
   System.arraycopy(algoNameBytes, 0, digestParms, 0, algoNameBytes.length);
   digestParms[algoNameBytes.length] = '\0';
   System.arraycopy(input, 0, digestParms, algoNameBytes.length + 1, input.length);
   GearmanJob job = GearmanJobImpl.createJob(function, digestParms, uniqueId);
   Future<GearmanJobResult> f = client.submit(job);
   GearmanJobResult jr = null;
   try {
     jr = f.get();
   } catch (Exception e) {
     e.printStackTrace(); // NOPMD
   }
   if (jr == null) {
     return new byte[0];
   } else {
     if (jr.jobSucceeded()) {
       return jr.getResults();
     } else {
       System.err.println(ByteUtils.fromUTF8Bytes(jr.getExceptions())); // NOPMD
       return new byte[0];
     }
   }
 }