Package com.google.appengine.api.datastore

Examples of com.google.appengine.api.datastore.Blob


        if (null != object){
            try {
                ByteArrayOutputStream buffer = new ByteArrayOutputStream();
                ObjectOutputStream out = new ObjectOutputStream(buffer);
                out.writeObject(object);
                return new Blob(buffer.toByteArray());
            }
            catch (java.io.IOException exc){
                throw new java.lang.RuntimeException(field.getFieldName(),exc);
            }
        }
View Full Code Here


            return null;
    }
    public Class define(Resource desc){
        String classname = desc.getJavaClassName(true);
        if (null != classname){
            Blob classfile = desc.getJavaClassBinary(true);
            if (null != classfile)
                return (Class<gap.service.Servlet>)this.define(classname,classfile.getBytes());
        }
        return null;
    }
View Full Code Here

    public void close()
        throws java.io.IOException
    {
        byte[] data = this.toByteArray();
        Blob blob = new Blob(data);
        this.table.define(this.field,blob);
    }
View Full Code Here

      return text.getValue();
    } else if (obj instanceof ShortBlob) {
      ShortBlob sbl = (ShortBlob) obj;
      return Base64.encodeBytes(sbl.getBytes());
    } else if (obj instanceof Blob) {
      Blob sbl = (Blob) obj;
      return Base64.encodeBytes(sbl.getBytes());
    } else if (obj instanceof Link) {
      Link lnk = (Link) obj;
      return lnk.getValue();
    } else if (obj instanceof Category) {
      Category cat = (Category) obj;
View Full Code Here

      } else if (obj == Text.class) {
        return new Text(args);
      } else if (obj == ShortBlob.class) {
        return new ShortBlob(Base64.decode(args));
      } else if (obj == Blob.class) {
        return new Blob(Base64.decode(args));
      } else if (obj == Link.class) {
        return new Link(args);
      } else if (obj == Category.class) {
        return new Category(args);
      } else if (obj == Email.class) {
View Full Code Here

    try {
      Entity asSingleEntity = DatastoreServiceFactory
          .getDatastoreService().get(getKey());

      if (asSingleEntity != null) {
        Blob bls = (Blob) asSingleEntity.getProperty(DATA);
        object = bls.getBytes();
        DataInputStream dataInputStream = new DataInputStream(
            new ByteArrayInputStream(object));
        try {
          int readInt = dataInputStream.readInt();
          if (readInt == 1) {
View Full Code Here

      byte[] byteArray = st.toByteArray();
      String version = getVersion();
      MemcacheServiceFactory.getMemcacheService().put(
          COM_ONPOSITIVE_TRAPS_CALL_STORAGE + version, byteArray);
      Entity entity = new Entity(getKey());
      entity.setProperty(DATA, new Blob(byteArray));
      DatastoreServiceFactory.getDatastoreService().put(entity);

    } catch (Throwable e) {
      e.printStackTrace();
    } finally {
View Full Code Here

                break;
              }
              s.write(k);
            }
            return isShort ? new ShortBlob(s.toByteArray())
                : new Blob(s.toByteArray());
          } catch (IOException e) {
            Activator.log(e);
            return null;
          }
        }
        return null;
      }

      public String getName() {
        return "Set from file";
      }

      public String getDescription() {
        return "";
      }
    });
    OneLineTextElement<Object> m = new OneLineTextElement<Object>(binding) {

      private org.eclipse.swt.widgets.Text txt;

      private Composite newComposite;
      private GridLayout layout;
      private boolean packFlg = false;

      private AbstractBlobVisualizer[] viewers = new AbstractBlobVisualizer[] {
          new ImageBlobVisualizer(),
          new SerializableBlobVisualizer(new IUpdateBlob() {

            public void updateBlob(byte[] data) {
              Blob blob = new Blob(data);
              onValue(blob);
            }

          }, project) };
      private AbstractBlobVisualizer last;

      protected void onValue(Object value) {
        commitToBinding(value);
        initBlobViewer(value);
      }

      public void initBlobViewer(Object value) {
        if (value != null) {
          if (value instanceof Blob) {
            Blob blob = (Blob) value;
            if (last == null || !last.isSupported(blob)) {
              boolean flg = false;
              for (AbstractBlobVisualizer handler : viewers) {
                if (last != null) {
                  last.dispose();
                  last = null;
                }
                if (handler.isSupported(blob)) {
                  last = handler;
                  last.init(newComposite);
                  last.handleBlob(blob);
                  // if (packFlg ) {
                  // newComposite.getShell().pack(true);
                  // } else {
                  // packFlg = true;
                  // }
                  Display.getCurrent().asyncExec(
                      new Runnable() {

                        public void run() {
                          newComposite.getShell()
                              .pack(true);
                          newComposite.getShell()
                              .layout(true, true);
                        }
                      });

                  // newComposite.getShell().layout(true,
                  // true);
                  flg = true;
                  break;

                }
              }
              if (!flg) {
                // if (packFlg) {
                // newComposite.getShell().pack(true);
                // } else {
                // packFlg = true;
                // }
                // newComposite.getShell().layout(true, true);
                Display.getCurrent().asyncExec(new Runnable() {

                  public void run() {
                    newComposite.getShell().pack(true);
                    newComposite.getShell().layout(true,
                        true);
                  }
                });
              }
            } else {
              last.handleBlob(blob);
              // newComposite.getShell().pack(true);
              // newComposite.getShell().layout(true, true);
              Display.getCurrent().asyncExec(new Runnable() {

                public void run() {
                  newComposite.getShell().pack(true);
                  newComposite.getShell().layout(true, true);
                }
              });

            }
          }
        }
      }

      protected void doCommit(final IBinding binding2) {
        // commitToBinding(this.getgetValue());
      }

      protected org.eclipse.swt.widgets.Text internalCreateControl(
          Composite conComposite) {
        newComposite = new Composite(conComposite, SWT.INHERIT_FORCE);
        layout = new GridLayout(1, false);
        layout.horizontalSpacing = 0;
        layout.verticalSpacing = 2;
        layout.marginWidth = 0;
        layout.marginHeight = 0;
        newComposite.setLayout(layout);
        txt = super.internalCreateControl(newComposite);
        Object value = binding.getValue();
        if (value instanceof Blob) {
          initBlobViewer(value);
        }

        // txt.setVisible(false);

        return txt;
      }

      protected void installSelector(Composite conComposite) {
        super.installSelector(conComposite);
        Button button = new Button(conComposite, SWT.NONE);
        button.setText("Store to File");
        this.registerPart(button);
        button.addListener(SWT.Selection, new Listener() {

          public void handleEvent(Event event) {
            FileDialog dlg = new FileDialog(Display.getCurrent()
                .getActiveShell(), SWT.SAVE);
            dlg.setText("Export blob to file:");
            String open = dlg.open();
            if (open != null) {
              try {
                FileOutputStream fs = new FileOutputStream(open);
                try {
                  Object value = binding.getValue();
                  if (value instanceof Blob) {
                    Blob b = (Blob) value;
                    fs.write(b.getBytes());
                  }
                  if (value instanceof ShortBlob) {
                    ShortBlob b = (ShortBlob) value;
                    fs.write(b.getBytes());
                  }
                } finally {
                  fs.close();
                }
View Full Code Here

        return new Text(value2.substring(0, 100) + "...");
      }
    }
    if (value instanceof Blob) {
      if (!isForStoring) {
        return new Blob(bytes);
      }
    }
    return value;
  }
View Full Code Here

     * @throws Exception
     */
    @Test
    public void blobToBytes() throws Exception {
        byte[] bytes = new byte[] { 1 };
        assertThat(meta.blobToBytes(new Blob(bytes)), is(bytes));
        assertThat(meta.blobToBytes(null), is(nullValue()));
    }
View Full Code Here

TOP

Related Classes of com.google.appengine.api.datastore.Blob

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.