本文整理汇总了Java中com.google.appengine.api.datastore.Blob类的典型用法代码示例。如果您正苦于以下问题:Java Blob类的具体用法?Java Blob怎么用?Java Blob使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Blob类属于com.google.appengine.api.datastore包,在下文中一共展示了Blob类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildEntityFromPersistentObject
import com.google.appengine.api.datastore.Blob; //导入依赖的package包/类
public Entity buildEntityFromPersistentObject(final P persistentObject, final DAO<P> dao) {
if (persistentObject == null) {
return null;
}
final Entity anEntity = new Entity(dao.getEntityName(), persistentObject.getId());
final byte[] binaryData = objectHolderSerializer.serialize(persistentObject.getDataObject(), true);
if (binaryData.length > 1000000) {
throw new RuntimeException("BinaryData length for object [" + persistentObject + "] is bigger than permitted: " + binaryData.length);
}
anEntity.setUnindexedProperty(DATA_CONTAINER_PROPERTY, new Blob(binaryData));
for (final PropertyMeta propertyMeta : persistentObject.getPropertiesMetadata().values()) {
if (propertyMeta.isIndexable()) {
anEntity.setProperty(propertyMeta.getPropertyName(), propertyMeta.get());
}
}
return anEntity;
}
示例2: load
import com.google.appengine.api.datastore.Blob; //导入依赖的package包/类
public static Resource load(final String id, final boolean exceptionOnNotFound) {
Resource result = (Resource) CacheStrategy.APPLICATION_CACHE.get().get(ENTITY_NAME + id);
if (result == null) {
final Entity entity = new RetryingHandler().tryDSGet(DAO.buildKey(ENTITY_NAME, id));
if (entity != null) {
result = new Resource();
result.id = id;
result.type = (String) entity.getProperty("type");
final Blob binaryData = (Blob) entity.getProperty("bdata");
result.rawValue = binaryData == null ? null : binaryData.getBytes();
}
}
if (result == null && exceptionOnNotFound) {
throw new RuntimeException("Could not find resource with key [" + id + "]");
}
return result;
}
示例3: save
import com.google.appengine.api.datastore.Blob; //导入依赖的package包/类
public void save(final boolean saveAsync) {
validateSize();
final Entity anEntity = new Entity(ENTITY_NAME, id);
if (type != null) {
anEntity.setProperty("type", type);
}
if (rawValue != null) {
anEntity.setUnindexedProperty("bdata", new Blob(rawValue));
}
final RetryingHandler retryingHandler = new RetryingHandler();
if (saveAsync) {
retryingHandler.tryDSPutAsync(anEntity);
} else {
retryingHandler.tryDSPut(anEntity);
}
CacheStrategy.APPLICATION_CACHE.get().put(ENTITY_NAME + id, this);
}
示例4: GetEventsForAggregate
import com.google.appengine.api.datastore.Blob; //导入依赖的package包/类
public List<Event> GetEventsForAggregate(UUID aggregateId)
{
logger.log(Level.INFO, ComplexLogMessages.eventStoreReadMessage("AggregateId", aggregateId.toString()));
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Key aggregateKey = KeyFactory.createKey("WishListEvents", aggregateId.toString());
Query query = new Query("WishListEvent", aggregateKey);
List<Entity> storedEvents = datastore.prepare(query).asList(FetchOptions.Builder.withDefaults());
ArrayList<Event> eventData = new ArrayList<Event>();
for(Entity e : storedEvents)
{
eventData.add(PropertyConverter.convertBlobToObject(Event.class, (Blob)e.getProperty("EventData")));
}
if(eventData.isEmpty())
{
logger.log(Level.WARNING, ComplexLogMessages.exceptionMessage("AggregateNotFoundException", "Aggregate was not found."));
throw new AggregateNotFoundException("Aggregate was not found.");
}
return eventData;
}
示例5: GetWishLists
import com.google.appengine.api.datastore.Blob; //导入依赖的package包/类
@Override
public List<WishListDto> GetWishLists()
{
logger.log(Level.INFO, ComplexLogMessages.queryFacadeMessage("GetWishLists"));
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Key aggregateKey = KeyFactory.createKey("WishListsView", "WishListsView");
Query query = new Query("WishListDto", aggregateKey);
List<Entity> storedEntities = datastore.prepare(query).asList(FetchOptions.Builder.withDefaults());
List<WishListDto> wishLists = new ArrayList<WishListDto>();
for(Entity e : storedEntities)
{
wishLists.add(PropertyConverter.convertBlobToObject(WishListDto.class, (Blob)e.getProperty("WishListDto")));
}
return wishLists;
}
示例6: handle
import com.google.appengine.api.datastore.Blob; //导入依赖的package包/类
public void handle(NameOfWishListChangedEvent event)
{
logger.log(Level.INFO, ComplexLogMessages.eventHandlerMessage(event.getClass().getSimpleName(), "Id", event.Id.toString(), "NewName", event.NewName, "Version", "" + event.Version));
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Key aggregateKey = KeyFactory.createKey("WishListsView", "WishListsView");
Query query = new Query("WishListDto", aggregateKey);
List<Entity> storedEntities = datastore.prepare(query).asList(FetchOptions.Builder.withDefaults());
for(Entity e : storedEntities)
{
if(UUID.fromString((String)e.getProperty("Id")).equals(event.Id))
{
WishListDto wishListDto = PropertyConverter.convertBlobToObject(WishListDto.class, (Blob)e.getProperty("WishListDto"));
wishListDto.setName(event.NewName);
wishListDto.setVersion(event.Version);
e.setProperty("WishListDto", PropertyConverter.convertObjectToBlob(wishListDto));
datastore.put(e);
break;
}
}
}
示例7: convertObjectToBlob
import com.google.appengine.api.datastore.Blob; //导入依赖的package包/类
public static <T>Blob convertObjectToBlob(T o)
{
try
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(bos);
out.writeObject(o);
return new Blob(bos.toByteArray());
}
catch (IOException e)
{
e.printStackTrace();
return null;
}
}
示例8: convertBlobToObject
import com.google.appengine.api.datastore.Blob; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static <T>T convertBlobToObject(Class<T> clazz, Blob b)
{
try
{
ByteArrayInputStream bos = new ByteArrayInputStream(b.getBytes());
ObjectInputStream is = new ObjectInputStream(bos);
return (T) is.readObject();
}
catch (IOException | ClassNotFoundException e)
{
e.printStackTrace();
return null;
}
}
示例9: testSize
import com.google.appengine.api.datastore.Blob; //导入依赖的package包/类
@Test
public void testSize() {
String kind = kindName + "-size";
int recordSize = (1000 * 1000); // Max. 1000000.
byte[] filledRec = new byte[recordSize];
Arrays.fill(filledRec, (byte) 0x41);
Blob bigBlob = new Blob(filledRec);
assertEquals(recordSize, bigBlob.getBytes().length);
Entity eBlob = new Entity(kind, rootKey);
eBlob.setProperty("blobProp", bigBlob);
service.put(eBlob);
recordSize = 500 ; // Max. 500.
filledRec = new byte[recordSize];
Arrays.fill(filledRec, (byte) 0x41);
ShortBlob shortBlob = new ShortBlob(filledRec);
assertEquals(recordSize, shortBlob.getBytes().length);
Entity eShortBlob = new Entity(kind, rootKey);
eShortBlob.setProperty("byteStrProp", shortBlob);
service.put(eShortBlob);
service.delete(eBlob.getKey(), eShortBlob.getKey());
}
示例10: createEntityForPut
import com.google.appengine.api.datastore.Blob; //导入依赖的package包/类
private Entity createEntityForPut(I_BlobKey keySource, I_Blob blob) throws BlobException
{
Key keyObject = KeyFactory.createKey(blob.getKind(), keySource.createBlobKey(blob));
Entity entity = new Entity(keyObject);
byte[] blobBytes = U_Blob.convertToBytes(blob);
Blob blobData = new Blob(blobBytes);
entity.setUnindexedProperty(S_Blob.DATA_FIELD_NAME, blobData);
Map<String, Object> queryableProperties = blob.getQueryableProperties();
if( queryableProperties != null )
{
for( String key : queryableProperties.keySet() )
{
entity.setProperty(key, queryableProperties.get(key));
}
}
return entity;
}
示例11: getWriteBlobAsBase64Module
import com.google.appengine.api.datastore.Blob; //导入依赖的package包/类
private static SimpleModule getWriteBlobAsBase64Module() {
JsonSerializer<Blob> dateSerializer = new JsonSerializer<Blob>() {
@Override
public void serialize(Blob value, JsonGenerator jgen, SerializerProvider provider)
throws IOException {
byte[] bytes = value.getBytes();
jgen.writeBinary(bytes, 0, bytes.length);
}
};
SimpleModule writeBlobAsBase64Module = new SimpleModule("writeBlobAsBase64Module",
new Version(1, 0, 0, null, null, null));
writeBlobAsBase64Module.addSerializer(Blob.class, dateSerializer);
return writeBlobAsBase64Module;
}
示例12: testReadBlobParameter
import com.google.appengine.api.datastore.Blob; //导入依赖的package包/类
@Test
public void testReadBlobParameter() throws Exception {
Method method =
TestEndpoint.class.getDeclaredMethod("doBlob", Blob.class);
Object[] params = readParameters("{\"blob\":\"AQIDBA==\"}", method);
assertEquals(1, params.length);
assertThat(((Blob) params[0]).getBytes()).isEqualTo(new byte[]{1, 2, 3, 4});
}
示例13: testBlobAsBase64
import com.google.appengine.api.datastore.Blob; //导入依赖的package包/类
@SuppressWarnings("unused")
public void testBlobAsBase64() throws Exception {
Object value = new Object() {
public Blob getBlob() {
return new Blob(new byte[]{1, 2, 3, 4});
}
};
ObjectNode output = ObjectMapperUtil.createStandardObjectMapper()
.readValue(writeToResponse(value), ObjectNode.class);
assertEquals("AQIDBA==", output.path("blob").asText());
}
示例14: toEntity
import com.google.appengine.api.datastore.Blob; //导入依赖的package包/类
@Override
public Entity toEntity() {
Entity entity = toProtoEntity();
entity.setUnindexedProperty(SHARD_ID_PROPERTY, shardId);
entity.setUnindexedProperty(VALUE_PROPERTY, new Blob(value));
return entity;
}
示例15: ExceptionRecord
import com.google.appengine.api.datastore.Blob; //导入依赖的package包/类
public ExceptionRecord(Entity entity) {
super(entity);
Blob serializedExceptionBlob = (Blob) entity.getProperty(EXCEPTION_PROPERTY);
byte[] serializedException = serializedExceptionBlob.getBytes();
try {
exception = (Throwable) SerializationUtils.deserialize(serializedException);
} catch (IOException e) {
throw new RuntimeException("Failed to deserialize exception for " + getKey(), e);
}
}