private Object unmarshall(byte[] bytes) { try { return this.ctx.getMarshaller().objectFromByteBuffer(bytes); } catch (IOException | ClassNotFoundException e) { throw new PersistenceException(e); } }
private byte[] marshall(Object key) { try { return (key instanceof WrappedByteArray) ? ((WrappedByteArray) key).getBytes() : this.ctx.getMarshaller().objectToByteBuffer(key); } catch (IOException | InterruptedException e) { throw new PersistenceException(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 testErrorUnmarshallInputStreamAvailable() throws Exception { byte[] bytes = marshaller.objectToByteBuffer("23"); Object o = marshaller.objectFromInputStream(new ByteArrayInputStream(bytes){ @Override public int available() { return 0; } }); assertEquals("23", o); }
private int getCommandSize(ReplicableCommand command) { try { CountingDataOutput dataOutput = new CountingDataOutput(); ObjectOutput byteOutput = marshaller.startObjectOutput(dataOutput, false, 0); marshaller.objectToObjectStream(command, byteOutput); marshaller.finishObjectOutput(byteOutput); return dataOutput.getCount(); } catch (Exception e) { return 0; } }
@Override public Object objectFromInputStream(InputStream is) throws IOException, ClassNotFoundException { return marshaller.objectFromInputStream(is); }
@Override public ByteBuffer objectToBuffer(Object o) throws IOException, InterruptedException { return marshaller.objectToBuffer(o); }
@Override public void finishObjectOutput(ObjectOutput oo) { marshaller.finishObjectOutput(oo); }
@Override public ObjectOutput startObjectOutput(OutputStream os, boolean isReentrant, final int estimatedSize) throws IOException { return marshaller.startObjectOutput(os, isReentrant, estimatedSize); }
@Override public void objectToObjectStream(Object obj, ObjectOutput out) throws IOException { marshaller.objectToObjectStream(obj, out); }
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); }
@SuppressWarnings("unchecked") private KeyValuePair<ByteBuffer, ByteBuffer> unmarshall(InputStream inputStream) throws PersistenceException { try { return (KeyValuePair<ByteBuffer, ByteBuffer>) marshaller.objectFromInputStream(inputStream); } catch (IOException e) { throw new PersistenceException("I/O error while unmarshalling from stream", e); } catch (ClassNotFoundException e) { throw new PersistenceException(e); } } }
@Override protected ByteBuffer objectToBuffer(Object o, int estimatedSize) throws IOException, InterruptedException { return marshaller.objectToBuffer(o); }
@Override public void finishObjectOutput(ObjectOutput oo) { marshaller.finishObjectOutput(oo); }
@Override public ObjectOutput startObjectOutput(OutputStream os, boolean isReentrant, int expectedByteSize) throws IOException { return marshaller.startObjectOutput(os, isReentrant, expectedByteSize); }
@Override public void objectToObjectStream(Object obj, ObjectOutput out) throws IOException { marshaller.objectToObjectStream(obj, out); }
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); }
@Override public Object objectFromByteBuffer(byte[] buf) throws IOException, ClassNotFoundException { return marshaller.objectFromByteBuffer(buf); }
@Override public byte[] objectToByteBuffer(Object obj, int estimatedSize) throws IOException, InterruptedException { return marshaller.objectToByteBuffer(obj, estimatedSize); }
private Map<Object, MarshalledEntry> unmarshallBucketEntries(InputStream inputStream) { try { return (Map<Object, MarshalledEntry>) marshaller.objectFromInputStream(inputStream); } catch (IOException e) { throw new PersistenceException("I/O error while unmarshalling from stream", e); } catch (ClassNotFoundException e) { throw new PersistenceException(e); } } }