public static int length(Blob valueArray, int elementSize) { if(valueArray == null) { return 0; } return valueArray.getBytes().length / elementSize; }
/** * 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(); }
/** * 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(); }
public FanoutTaskRecord(Entity entity) { super(entity); Blob payloadBlob = (Blob) entity.getProperty(PAYLOAD_PROPERTY); payload = payloadBlob.getBytes(); }
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 String[] toArray(Blob blob) { if(blob == null) { return EMPTY_STRING_ARRAY; } else { return toArray(blob.getBytes()); } }
public static int get(Blob blob, int index) { if(blob == null) { return MISSING; } else { return get(blob.getBytes(), index); } }
public static int length(Blob values) { if(values == null) { return 0; } else { return length(values.getBytes()); } }
public static byte[] read(PropertyContainer entity, String propertyName) { Blob blob = (Blob) entity.getProperty(propertyName); if(blob == null) { return EMPTY; } else { return blob.getBytes(); } }
public static void toArray(Blob blob, String[] array, int offset) { if(blob != null) { toArray(blob.getBytes(), array, offset); } }
public static int size(Blob pool) { if(pool == null) { return 0; } return size(pool.getBytes()); }
/** * Retrieves the one-based offset from the blob. Zero if the offset is missing. */ public static int get(Blob blob, int index) { if(blob == null) { return 0; } else { return get(blob.getBytes(), index); } }
public static ByteBuffer asBuffer(Blob valueArray) { return asBuffer(valueArray.getBytes()); }
/** Deserializes the specified object from a Blob using an {@link ObjectInputStream}. */ private V deserialize(Entity entity) throws IOException { Blob blob = (Blob) entity.getProperty(FIELD_VALUE); return IOUtils.deserialize(blob.getBytes()); }
public ShardedValue(Entity entity) { super(entity); this.shardId = (Long) entity.getProperty(SHARD_ID_PROPERTY); this.value = ((Blob) entity.getProperty(VALUE_PROPERTY)).getBytes(); }
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); } }
@Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { columnName = table.getColumnName(column); if (value != null) { Blob blob = (Blob) value; dialog.setBytes(blob.getBytes()); button.setText(dialog.getContentDescription()); } else { button.setText(null); } return button; }
public static Blob appendString(Blob stringPool, String string) { if(stringPool == null) { return new Blob(newPool(string)); } else { return new Blob(appendString(stringPool.getBytes(), string.getBytes(Charsets.UTF_8))); } }
public static void serialize(SerializationStreamWriter streamWriter, Blob instance) throws SerializationException { byte[] bytes = instance.getBytes(); if (bytes == null) { streamWriter.writeInt(-1); } else { streamWriter.writeInt(bytes.length); for (byte b : bytes) { streamWriter.writeByte(b); } } } }
@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()); }