コード例 #1
0
ファイル: MemoStorable.java プロジェクト: almende/memo-nodes
  // Factory methods:
  public static MemoStorable load(Entity ent) {
    //		long start = System.currentTimeMillis();
    byte[] result;
    Key key = ent.getKey();
    int size = 0;
    long spread = 0;
    //		int count=0;
    try {
      Blob blob = (Blob) ent.getProperty("payload");
      size = (int) ((Long) ent.getProperty("size") % Integer.MAX_VALUE);
      spread = ((Long) ent.getProperty("spread"));

      byte[] data = blob.getBytes();
      result = Arrays.copyOf(data, data.length);
      //			count++;
      while (ent.hasProperty("next")) {
        // Expensive, should not be used too much!
        Key next = (Key) ent.getProperty("next");
        ent = datastore.get(next);
        blob = (Blob) ent.getProperty("payload");
        data = blob.getBytes();
        result = concat(data, result); // Add to front of result, due to
        //				count++;						// the storing order
      }

    } catch (EntityNotFoundException e) {
      e.printStackTrace();
      return null;
    }
    MemoStorable res = _unserialize(result, size);
    res.spread = spread;
    res.storedSize = result.length;
    if (res != null) res.myKey = key;
    return res;
  }
コード例 #2
0
ファイル: Deferred.java プロジェクト: armhold/gwtquickstarter
 /**
  * Executes a background task.
  *
  * <p>The task payload is either type Deferrable or Key; in the latter case, retrieve (then
  * delete) the Deferrable instance from the datastore.
  */
 @Override
 public void doPost(HttpServletRequest req, HttpServletResponse res)
     throws ServletException, IOException {
   try {
     Object payload = deserialize(req);
     if (payload instanceof Key) {
       // get Deferrable from datastore
       Blob taskBlob = (Blob) getDatastoreService().get((Key) payload).getProperty(TASK_PROPERTY);
       deleteEntity((Key) payload);
       if (taskBlob != null) {
         payload = deserialize(taskBlob.getBytes());
       }
     }
     if (payload instanceof Deferrable) {
       ((Deferrable) payload).doTask();
     } else if (payload != null) {
       log.severe("invalid payload type: " + payload.getClass().getName());
       // don't retry task
     }
   } catch (EntityNotFoundException e) {
     log.severe(e.toString()); // don't retry task
   } catch (PermanentTaskFailure e) {
     log.severe(e.toString()); // don't retry task
   }
 }
コード例 #3
0
 public InputStream getInputStream() throws IOException {
   ByteArrayInputStream bais;
   if (content != null) {
     bais = new ByteArrayInputStream(content.getBytes());
   } else {
     bais = new ByteArrayInputStream(content_out.toByteArray());
   }
   return bais;
 }
コード例 #4
0
  public Object process() throws xMethodException {
    int width = 2, height = 2;
    try {
      width = Integer.parseInt(getArguments("w"));
    } catch (Exception e) {
    }
    try {
      height = Integer.parseInt(getArguments("h"));
    } catch (Exception e) {
    }
    int color = 0xffffff;
    try {
      color = Integer.parseInt(getArguments("c"), 16);
    } catch (Exception e) {
    }
    int border_color = color;
    try {
      border_color = Integer.parseInt(getArguments("bc"), 16);
    } catch (Exception e) {
    }
    float opaque = 1f;
    try {
      opaque = Float.parseFloat(getArguments("o"));
    } catch (Exception e) {
    }
    int rc = -1;
    try {
      rc = Integer.parseInt(getArguments("rc"));
    } catch (Exception e) {
    }

    byte[] pngbytes = null;
    StringBuffer memkey = new StringBuffer();
    memkey
        .append(width)
        .append(height)
        .append(color)
        .append(border_color)
        .append(rc)
        .append(opaque);
    Blob blob = (Blob) xMemCache.pngService().get(memkey);
    if (blob != null) pngbytes = blob.getBytes();
    if (pngbytes == null || pngbytes.length == 0) {
      pngPixelSource ps = new pngPixelSource(width, height, color, border_color, rc, opaque);
      try {
        pngbytes = new PngWriter().generateImage(ps);
        xMemCache.pngService().put(memkey, new Blob(pngbytes));
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    //
    HttpServletResponse response = getServiceContext().customizeResponse();
    response.setHeader("Cache-Control", "no-cache");
    response.setContentType("image/png");
    try {
      response.getOutputStream().write(pngbytes);
    } catch (IOException ioe) {
      ioe.printStackTrace();
      throw createMethodException("QrcodeException", ioe.getLocalizedMessage());
    }
    //

    return getServiceContext().doNextProcess();
  }
コード例 #5
0
 public long getSize() {
   return (content != null) ? content.getBytes().length : content_out.size();
 }
コード例 #6
0
 public byte[] get() {
   return (content != null) ? content.getBytes() : content_out.toByteArray();
 }
コード例 #7
0
 public String getString(String arg0) throws UnsupportedEncodingException {
   return (content != null)
       ? new String(content.getBytes(), arg0)
       : new String(content_out.toByteArray(), arg0);
 }
コード例 #8
0
 public String getString() {
   return (content != null)
       ? new String(content.getBytes())
       : new String(content_out.toByteArray());
 }
コード例 #9
0
ファイル: TaskletVO.java プロジェクト: smee/elatexam-demo
 /** @return the xml */
 public byte[] getXml() {
   if (xml == null) return null;
   return xml.getBytes();
 }
コード例 #10
0
ファイル: BlobImpl.java プロジェクト: matejonnet/lhotse
 public byte[] getBytes() {
   return blob.getBytes();
 }
コード例 #11
0
  public byte[] getImage() {

    if (image == null) return null;

    return image.getBytes();
  }