@Override public Object getCellEditorValue() { byte[] bytes = dialog.getBytes(); if (bytes != null) { return new Blob(bytes); } else { return null; } }
/** * Zeros out the value at the given index. Unallocated values are assumed to be zero, * so if the array is only updated if it is already long enough to include the given index. * * @param values the value blob * @param index the index within the blob */ public static Blob updateToZero(Blob values, int index) { if(values == null) { return null; } byte[] bytes = values.getBytes(); int pos = index * BYTES; if(pos < bytes.length) { bytes[pos] = 0; bytes[pos + 1] = 0; } return new Blob(bytes); }
@Override public Object forDatastore(Object value, ConverterSaveContext ctx) { if (!value.getClass().isArray()) return null; if (ctx.inEmbeddedCollection()) throw new IllegalStateException("You cannot have arrays within @Embedded arrays or collections"); if (value.getClass().getComponentType() == Byte.TYPE) { // Special case! byte[] gets turned into Blob. return new Blob((byte[])value); } else { // The datastore cannot persist arrays, but it can persist ArrayList int length = Array.getLength(value); ArrayList<Object> list = new ArrayList<Object>(length); for (int i=0; i<length; i++) list.add(this.conversions.forDatastore(Array.get(value, i), ctx)); return list; } }
oos.writeObject(value); return new Blob(baos.toByteArray());
@Override public Entity toEntity() { Entity entity = toProtoEntity(); entity.setUnindexedProperty(PAYLOAD_PROPERTY, new Blob(payload)); return entity; } }
/** * Updates the value at the given {@code index} in the array, allocating a new, larger * array only if necessary. * * @return */ public static Blob update(Blob values, int index, int value) { byte[] bytes = ensureCapacity(values, index); set(bytes, index, value); return new Blob(bytes); }
public static Blob update(Blob values, int index, double value) { byte[] bytes = ensureCapacity(values, index); set(bytes, index, value); return new Blob(bytes); }
public static Blob instantiate(SerializationStreamReader streamReader) throws SerializationException { byte[] bytes; int len = streamReader.readInt(); if (len == -1) { bytes = null; } else { bytes = new byte[len]; for (int i = 0; i < len; i++) { bytes[i] = streamReader.readByte(); } } return new Blob(bytes); }
return new Blob(label.getBytes());
@Override public Entity toEntity() { try { Entity entity = toProtoEntity(); byte[] serializedException = SerializationUtils.serialize(exception); entity.setUnindexedProperty(EXCEPTION_PROPERTY, new Blob(serializedException)); return entity; } catch (IOException e) { throw new RuntimeException("Failed to serialize exception for " + getKey(), e); } } }
public static Blob update(Blob values, int index, char offset) { if(offset == 0) { return updateToZero(values, index); } else { byte[] bytes = ValueArrays.ensureCapacity(values, index, BYTES); ValueArrays.setChar(bytes, index, offset); return new Blob(bytes); } }
@Override public Entity toEntity() { Entity entity = toProtoEntity(); entity.setUnindexedProperty(SHARD_ID_PROPERTY, shardId); entity.setUnindexedProperty(VALUE_PROPERTY, new Blob(value)); return entity; }
public static Blob update(Blob values, int index, double value1, double value2) { byte[] bytes = ensureCapacity(values, index + 1); set(bytes, index, value1); set(bytes, index, value2); return new Blob(bytes); }
public static Blob update(Blob blob, int index, boolean value) { if(blob == null && !value) { return null; } int capacity = 0; if(blob != null) { capacity = blob.getBytes().length * 8; } // Unallocated bits at the end of the blob are assumed to be false if(index >= capacity && !value) { return blob; } byte[] bytes = ensureCapacity(blob, index); set(bytes, index, value); return new Blob(bytes); }
@Override public AppEngineDataStore<V> set(String key, V value) throws IOException { Preconditions.checkNotNull(key); Preconditions.checkNotNull(value); lock.lock(); try { Entity entity = new Entity(getId(), key); entity.setUnindexedProperty(FIELD_VALUE, new Blob(IOUtils.serialize(value))); dataStoreService.put(entity); if (memcache != null) { memcache.put(key, value, memcacheExpiration); } } finally { lock.unlock(); } return this; }
EntityProto proto = EntityTranslator.convertToPb(e); byte[] bytes = proto.toByteArray(); blobs.add(new Blob(bytes));
@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()); }
@Test public void testUnindexedProperties() throws Exception { Entity entity = new Entity(UNINDEXED_ENTITY); entity.setUnindexedProperty("unindexedString", "unindexedString"); entity.setUnindexedProperty("unindexedList", new ArrayList<String>(Arrays.asList("listElement1", "listElement2", "listElement3"))); entity.setUnindexedProperty("unindexedText", new Text("unindexedText")); entity.setUnindexedProperty("unindexedBlob", new Blob("unindexedBlob".getBytes())); entity.setProperty("text", new Text("text")); entity.setProperty("blob", new Blob("blob".getBytes())); Key key = service.put(entity); sync(3000); // Not using ancestor queries, so pause before doing queries below. Entity entity2 = service.get(key); assertTrue(isUnindexed(getRawProperty(entity2, "unindexedString"))); assertTrue(isUnindexed(getRawProperty(entity2, "unindexedList"))); assertTrue(isUnindexed(getRawProperty(entity2, "unindexedText"))); assertTrue(isUnindexed(getRawProperty(entity2, "unindexedBlob"))); assertTrue(isUnindexed(getRawProperty(entity2, "text"))); assertTrue(isUnindexed(getRawProperty(entity2, "blob"))); assertNull(getResult(new Query(UNINDEXED_ENTITY).setFilter(new FilterPredicate("unindexedString", EQUAL, "unindexedString")))); assertNull(getResult(new Query(UNINDEXED_ENTITY).setFilter(new FilterPredicate("unindexedList", EQUAL, "listElement1")))); assertNull(getResult(new Query(UNINDEXED_ENTITY).setFilter(new FilterPredicate("unindexedText", EQUAL, "unindexedText")))); assertNull(getResult(new Query(UNINDEXED_ENTITY).setFilter(new FilterPredicate("text", EQUAL, "text")))); service.delete(key); }