Package com.google.appengine.api.datastore

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


    try
    {
      Property property = properties.iterator().next();
      if (property.getValue() instanceof Blob)
      {
        Blob blob = (Blob) property.getValue();
        return blobToSerializable.convert(blob);
      }
      else
      {
        return null;
View Full Code Here


  {
    try
    {
      if (object instanceof Serializable)
      {
        Blob blob = serializableToBlob.convert((Serializable) object);
        return Collections.singleton((Property) new SimpleProperty(path, blob, indexed));
      }
      else
      {
        return null;
View Full Code Here

  @Test
  public void testEmbeddedPrimitives()
  {
    ClassWithEmbeddedPrimitives testType = new ClassWithEmbeddedPrimitives();
    testType.number = 8;
    testType.blob = new Blob(new byte[] { 3, 4 });
    boolean threw = false;
    try
    {
      datastore.store(testType);
    }
View Full Code Here

  public static class ByteArrayToBlob implements SpecificTypeConverter<byte[], Blob>
  {
    public Blob convert(byte[] source)
    {
      return new Blob(source);
    }
View Full Code Here

      try
      {
        ByteArrayOutputStream baos = new ByteArrayOutputStream(256);
        ObjectOutputStream stream = createObjectOutputStream(baos);
        stream.writeObject(source);
        return new Blob(baos.toByteArray());
      }
      catch (Exception e)
      {
        throw new IllegalStateException(e);
      }
View Full Code Here

 
  private Integer index;
 
  public DataChunk(String photoEntryId, int index, byte[] bytes) {
    this.photoEntryId = photoEntryId;
    this.data = new Blob(bytes);
    this.index = new Integer(index);
   
    this.created = new Date();
  }
View Full Code Here

    }

    @Override
    public Blob deserialize(JsonElement json, Type type, JsonDeserializationContext context) {
      try {
        return new Blob(Base64.decode(json.getAsString()));
      } catch (JsonParseException e) {
        // TODO: This is kind of a hacky way of reporting back a parse exception.
        return new Blob(e.toString().getBytes());
      } catch (Base64DecoderException e) {
        // TODO: This is kind of a hacky way of reporting back a parse exception.
        return new Blob(e.toString().getBytes());
      }
    }
View Full Code Here

                     ((ShortBlob) e.getProperty("byteSet")).getBytes())));
    assertEquals(new ShortBlob("byte collection".getBytes()), e.getProperty("byteCollection"));
    assertEquals(1L, e.getProperty("onePrimByte"));
    assertEquals(2L, e.getProperty("oneByte"));
    assertEquals(new ShortBlob("short blob".getBytes()), e.getProperty("shortBlob"));
    assertEquals(new Blob("serialized prim bytes".getBytes()), e.getProperty("serializedPrimBytes"));
    assertEquals(new Blob("serialized bytes".getBytes()), e.getProperty("serializedBytes"));
    assertEquals(SS.serialize(PrimitiveArrays.asList("serialized byte list".getBytes())),
                 e.getProperty("serializedByteList"));
    assertEquals(SS.serialize(new HashSet<Byte>(PrimitiveArrays.asList(
        "serialized byte set".getBytes()))), e.getProperty("serializedByteSet"));
  }
View Full Code Here

    e.setProperty("byteSet", new ShortBlob("byte set".getBytes()));
    e.setProperty("byteCollection", new ShortBlob("byte collection".getBytes()));
    e.setProperty("onePrimByte", 1L);
    e.setProperty("oneByte", 2L);
    e.setProperty("shortBlob", new ShortBlob("short blob".getBytes()));
    e.setProperty("serializedPrimBytes", new Blob("serialized prim bytes".getBytes()));
    e.setProperty("serializedBytes", new Blob("serialized bytes".getBytes()));
    e.setProperty("serializedByteList", SS.serialize(PrimitiveArrays.asList("serialized byte list".getBytes())));
    e.setProperty("serializedByteSet", SS.serialize(new HashSet<Byte>(PrimitiveArrays.asList("serialized byte set".getBytes()))));

    ds.put(e);

    beginTxn();
    HasBytesJDO pojo = pm.getObjectById(HasBytesJDO.class, e.getKey());
    assertTrue(Arrays.equals("prim bytes".getBytes(), pojo.getPrimBytes()));
    assertEquals(PrimitiveArrays.asList("bytes".getBytes()), Arrays.asList(pojo.getBytes()));
    assertEquals(PrimitiveArrays.asList("byte list".getBytes()), pojo.getByteList());
    assertEquals(new HashSet<Byte>(PrimitiveArrays.asList("byte set".getBytes())), pojo.getByteSet());
    assertEquals(PrimitiveArrays.asList("byte collection".getBytes()), pojo.getByteCollection());
    assertEquals(Integer.valueOf(1).byteValue(), pojo.getOnePrimByte());
    assertEquals(Integer.valueOf(2).byteValue(), pojo.getOneByte().byteValue());
    assertEquals(new ShortBlob("short blob".getBytes()), pojo.getShortBlob());
    assertEquals(new Blob("serialized prim bytes".getBytes()), new Blob(pojo.getSerializedPrimBytes()));
    assertEquals(new Blob("serialized bytes".getBytes()),
                 new Blob(PrimitiveArrays.toByteArray(Arrays.asList(pojo.getSerializedBytes()))));
    assertEquals(PrimitiveArrays.asList("serialized byte list".getBytes()),
                 pojo.getSerializedByteList());
    assertEquals(new HashSet<Byte>(PrimitiveArrays.asList("serialized byte set".getBytes())),
                 pojo.getSerializedByteSet());
    commitTxn();
View Full Code Here

    em.persist(pojo);
    commitTxn();

    Entity e = ds.get(KeyFactory.createKey(HasLob.class.getSimpleName(), pojo.getId()));
    assertEquals(new Text("a really big string"), e.getProperty("bigString"));
    assertEquals(new Blob("a really big byte array".getBytes()), e.getProperty("bigByteArray"));
    assertEquals(new Blob(SerializationManager.DEFAULT_SERIALIZATION_STRATEGY.serialize(
        Utils.newArrayList(now)).getBytes()), e.getProperty("dateList"));
  }
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.