@Test public void testToByteArray() throws Exception { assertArrayEquals(bytes1, blob1.toByteArray()); assertArrayEquals(bytes2, blob2.toByteArray()); }
@Test public void testCopyFrom() throws Exception { Blob blob = Blob.copyFrom(ByteBuffer.wrap(bytes1)); assertEquals(blob1, blob); assertArrayEquals(bytes1, blob.toByteArray()); blob = Blob.copyFrom(new ByteArrayInputStream(bytes2)); assertEquals(blob2, blob); assertArrayEquals(bytes2, blob.toByteArray()); } }
@Test public void testGetBlob() throws Exception { assertArrayEquals(STRING_INDEX_VALUE.get().getBytes(), ENTITY2.getBlob("a").toByteArray()); assertEquals(BLOB_VALUE.get(), ENTITY2.getBlob("b")); }
@Override protected byte[] toPojo(final Value<Blob> value) { return value.get().toByteArray(); }
@Override protected Object loadValue(final Value<Blob> value, final LoadContext ctx, final Path path) throws SkipException { Exception initialException = null; // Need to be careful here because we don't really know if the data was serialized or not. Start // with whatever the annotation says, and if that doesn't work, try the other option. try { final ByteArrayInputStream bais = new ByteArrayInputStream(value.get().toByteArray()); // Start with the annotation's zip setting final boolean unzip = serializeAnno.zip(); try { return readObject(bais, unzip); } catch (IOException ex) { // will be one of ZipException or StreamCorruptedException initialException = ex; if (log.isInfoEnabled()) log.info("Error trying to deserialize object using unzip=" + unzip + ", retrying with " + !unzip, ex); return readObject(bais, !unzip); // this will pass the exception up } } catch (Exception ex) { if (initialException == null) { initialException = ex; } path.throwIllegalState("Unable to deserialize " + value, initialException); return null; // never gets here } }
@Override public byte[] convert(Blob source) { return source.toByteArray(); } };
@Override public byte[] convert(Blob source) { return source.toByteArray(); } };
@Override public Object toModel(Value<?> input) { if (input instanceof NullValue) { return null; } return ((BlobValue) input).get().toByteArray(); }