/** * 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); }
public static int length(Blob valueArray, int elementSize) { if(valueArray == null) { return 0; } return valueArray.getBytes().length / elementSize; }
@Override public Object getCellEditorValue() { byte[] bytes = dialog.getBytes(); if (bytes != null) { return new Blob(bytes); } else { return null; } }
@Test public void testBlobType() { String propertyName = "blobProp"; List<Entity> elist = doQuery(kindName, propertyName, null, false); Blob blob = (Blob) elist.get(0).getProperty(propertyName); Blob sameDat = (Blob) elist.get(0).getProperty(propertyName); Blob diffDat = (Blob) elist.get(1).getProperty(propertyName); assertTrue(blob.equals(sameDat)); assertFalse(blob.equals(diffDat)); byte[] blobData = blob.getBytes(); assertTrue(Arrays.equals("blobImage".getBytes(), blobData) || Arrays.equals("blobText".getBytes(), blobData) || Arrays.equals("blobData".getBytes(), blobData)); assertEquals(blob.hashCode(), blob.hashCode()); }
/** * Returns a view of this array as an {@link IntBuffer} */ public static IntBuffer asBuffer(Blob valueArray) { ByteBuffer buffer = ByteBuffer.wrap(valueArray.getBytes()); buffer.order(ByteOrder.LITTLE_ENDIAN); return buffer.asIntBuffer(); }
@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; } }
/** * Returns a view of this array as an {@link DoubleBuffer} */ public static DoubleBuffer asBuffer(Blob valueArray) { ByteBuffer buffer = ByteBuffer.wrap(valueArray.getBytes()); buffer.order(ByteOrder.LITTLE_ENDIAN); return buffer.asDoubleBuffer(); }
private static byte[] ensureCapacity(Blob blob, int index) { int requiredCapacity = byteIndex(index) + 1; if(blob == null) { return new byte[requiredCapacity]; } byte[] bytes = blob.getBytes(); if(requiredCapacity <= bytes.length) { return bytes; } else { return Arrays.copyOf(bytes, requiredCapacity); } }
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); }
oos.writeObject(value); return new Blob(baos.toByteArray());
public static String[] toArray(Blob blob) { if(blob == null) { return EMPTY_STRING_ARRAY; } else { return toArray(blob.getBytes()); } }
blockEntity.setProperty(property, new Blob(newPool(newValue))); return 1; int index = find(strings.getBytes(), newValueBytes); if(index >= 0) { return (char) (index + 1); byte[] updatedPool = appendString(strings.getBytes(), newValueBytes); int newSize = size(updatedPool); blockEntity.setProperty(property, new Blob(updatedPool));
/** * 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 FanoutTaskRecord(Entity entity) { super(entity); Blob payloadBlob = (Blob) entity.getProperty(PAYLOAD_PROPERTY); payload = payloadBlob.getBytes(); }
@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()); }
@Override public Entity toEntity() { Entity entity = toProtoEntity(); entity.setUnindexedProperty(PAYLOAD_PROPERTY, new Blob(payload)); return entity; } }
public static int get(Blob blob, int index) { if(blob == null) { return MISSING; } else { return get(blob.getBytes(), index); } }
public static Blob update(Blob values, int index, double value) { byte[] bytes = ensureCapacity(values, index); set(bytes, index, value); return new Blob(bytes); }