private Object unmarshall(byte[] bytes) { try { return this.ctx.getMarshaller().objectFromByteBuffer(bytes); } catch (IOException | ClassNotFoundException e) { throw new PersistenceException(e); } }
@SuppressWarnings(value = "unchecked") private <T> T unmarshall(byte[] bytes) { try { return (T) marshaller.objectFromByteBuffer(bytes); } catch (Exception e) { throw new PersistenceException(e); } } }
private Object unmarshall(byte[] bytes) throws IOException, ClassNotFoundException { if (bytes == null) return null; return ctx.getMarshaller().objectFromByteBuffer(bytes); }
@Override public Object fromStorage(Object stored) { try { if (isTypeExcluded(stored.getClass())) { return stored; } return stored instanceof byte[] ? marshaller.objectFromByteBuffer((byte[]) stored) : stored; } catch (IOException | ClassNotFoundException e) { throw new CacheException(e); } }
private Object unmarshall(byte[] bytes) { try { return this.ctx.getMarshaller().objectFromByteBuffer(bytes); } catch (IOException | ClassNotFoundException e) { throw new PersistenceException(e); } }
@Override public Publisher publishKeys(Predicate filter) { return handleFilePublisher(filePublisher(), false, true, (file, offset, size, serializedKey, serializedMetadata, serializedValue, seqId, expiration) -> { final Object key = marshaller.objectFromByteBuffer(serializedKey); if (serializedValue != null && (filter == null || filter.test(key)) && !isSeqIdOld(seqId, key, serializedKey)) { return key; } return null; }); }
protected void marshallAndAssertArrayEquality(Object[] writeObj) throws Exception { byte[] bytes = marshaller.objectToByteBuffer(writeObj); log.debugf("Payload size for %s[]=%s : %s", writeObj.getClass().getComponentType().getName(), Arrays.toString(writeObj), bytes.length); Object[] readObj = (Object[]) marshaller.objectFromByteBuffer(bytes); assertArrayEquals("Writen[" + Arrays.toString(writeObj) + "] and read[" + Arrays.toString(readObj) + "] objects should be the same", writeObj, readObj); }
public void testMIMECacheEntryMarshalling() throws Exception { MIMECacheEntry entry = new MIMECacheEntry("rm", new byte[] {1, 2, 3}); byte[] bytes = marshaller.objectToByteBuffer(entry); MIMECacheEntry rEntry = (MIMECacheEntry) marshaller.objectFromByteBuffer(bytes); assert Arrays.equals(rEntry.data, entry.data); assert rEntry.contentType.equals(entry.contentType); }
private InternalMetadata getMetadata(EntityManager em, Object key) { MetadataEntity m = findMetadata(em, getMetadataKey(key)); if (m == null) return null; try { return (InternalMetadata) marshaller.objectFromByteBuffer(m.getMetadata()); } catch (Exception e) { throw new JpaStoreException("Failed to unmarshall metadata", e); } }
protected void marshallAndAssertEquality(Object writeObj) throws Exception { byte[] bytes = marshaller.objectToByteBuffer(writeObj); log.debugf("Payload size for object=%s : %s", writeObj, bytes.length); Object readObj = marshaller.objectFromByteBuffer(bytes); assert readObj.equals(writeObj) : "Writen[" + writeObj + "] and read[" + readObj + "] objects should be the same"; }
public void testMarshallingBigByteArrayValue() throws IOException, InterruptedException, ClassNotFoundException { byte[] cacheValue = getBigByteArray(); byte[] bytes = marshaller.objectToByteBuffer(cacheValue); byte[] readValue = (byte[]) marshaller.objectFromByteBuffer(bytes); AssertJUnit.assertTrue(Arrays.equals(readValue, cacheValue)); } }
public void testErrorUnmarshalling() throws Exception { Pojo pojo = new PojoWhichFailsOnUnmarshalling(); byte[] bytes = marshaller.objectToByteBuffer(pojo); try { marshaller.objectFromByteBuffer(bytes); } catch (IOException e) { log.info("Log exception for output format verification", e); TraceInformation inf = (TraceInformation) e.getCause(); if (inf != null) assert inf.toString().contains("in object of type org.infinispan.marshall.VersionAwareMarshallerTest$PojoWhichFailsOnUnmarshalling"); } }
public void testExceptionResponse() throws Exception { ExceptionResponse er = new ExceptionResponse(new TimeoutException()); byte[] bytes = marshaller.objectToByteBuffer(er); ExceptionResponse rer = (ExceptionResponse) marshaller.objectFromByteBuffer(bytes); assert rer.getException().getClass().equals(er.getException().getClass()) : "Writen[" + er.getException().getClass() + "] and read[" + rer.getException().getClass() + "] objects should be the same"; }
public void testMarshallingBigByteArrayKey() throws Exception { byte[] cacheKey = getBigByteArray(); byte[] bytes = marshaller.objectToByteBuffer(cacheKey); byte[] readKey = (byte[]) marshaller.objectFromByteBuffer(bytes); assertEquals(readKey, cacheKey); }
protected void marshallAndAssertEquality(ReplicableCommand writeObj) throws Exception { byte[] bytes = marshaller.objectToByteBuffer(writeObj); log.debugf("Payload size for object=%s : %s", writeObj, bytes.length); ReplicableCommand readObj = (ReplicableCommand) marshaller.objectFromByteBuffer(bytes); assert readObj.getCommandId() == writeObj.getCommandId() : "Writen[" + writeObj.getCommandId() + "] and read[" + readObj.getCommandId() + "] objects should be the same"; assert readObj.equals(writeObj) : "Writen[" + writeObj + "] and read[" + readObj + "] objects should be the same"; }
public void testMarshallingSerializableSubclass() throws Exception { Child1 child1Obj = new Child1(1234, "1234"); byte[] bytes = marshaller.objectToByteBuffer(child1Obj); Child1 readChild1 = (Child1) marshaller.objectFromByteBuffer(bytes); assertEquals(1234, readChild1.someInt); assertEquals("1234", readChild1.getId()); }
protected void marshallAndAssertByteArrayEquality(byte[] writeObj) throws Exception { byte[] bytes = marshaller.objectToByteBuffer(writeObj); log.debugf("Payload size for byte[]=%s : %s", Util.toHexString(writeObj), bytes.length); byte[] readObj = (byte[]) marshaller.objectFromByteBuffer(bytes); assertArrayEquals("Writen[" + Util.toHexString(writeObj)+ "] and read[" + Util.toHexString(readObj)+ "] objects should be the same", writeObj, readObj); }
public void testExternalAndInternalWithOffset() throws Exception { PojoWithExternalAndInternal obj = new PojoWithExternalAndInternal(new Human().age(23), "value"); byte[] bytes = marshaller.objectToByteBuffer(obj); bytes = prependBytes(new byte[]{1, 2, 3}, bytes); Object readObj = marshaller.objectFromByteBuffer(bytes, 3, bytes.length); assertEquals(obj, readObj); }
public void testMarshallingCommandWithBigByteArrayKey() throws Exception { byte[] cacheKey = getBigByteArray(); ClusteredGetCommand command = new ClusteredGetCommand(new WrappedByteArray(cacheKey), ByteString.fromString("c"), 0, EnumUtil.EMPTY_BIT_SET); byte[] bytes = marshaller.objectToByteBuffer(command); ClusteredGetCommand readCommand = (ClusteredGetCommand) marshaller.objectFromByteBuffer(bytes); assertEquals(readCommand, command); }
public void testMarshallingNestedSerializableSubclass() throws Exception { Child1 child1Obj = new Child1(1234, "1234"); Child2 child2Obj = new Child2(2345, "2345", child1Obj); byte[] bytes = marshaller.objectToByteBuffer(child2Obj); Child2 readChild2 = (Child2) marshaller.objectFromByteBuffer(bytes); assertEquals(2345, readChild2.someInt); assertEquals("2345", readChild2.getId()); assertEquals(1234, readChild2.getChild1Obj().someInt); assertEquals("1234", readChild2.getChild1Obj().getId()); }