### Question:
PersistenceUtils { public static void decodeRMContent(RMMessage rmmsg, Message msg) throws IOException { String contentType = rmmsg.getContentType(); final CachedOutputStream cos = rmmsg.getContent(); if ((null != contentType) && contentType.startsWith("multipart/related")) { final InputStream is = cos.getInputStream(); msg.put(Message.CONTENT_TYPE, contentType); msg.setContent(InputStream.class, is); AttachmentDeserializer ad = new AttachmentDeserializer(msg); ad.initializeAttachments(); CachedOutputStream cosSoap = new CachedOutputStream(); IOUtils.copy(msg.getContent(InputStream.class), cosSoap); cosSoap.flush(); msg.put(RMMessageConstants.SAVED_CONTENT, cosSoap); msg.put(RMMessageConstants.ATTACHMENTS_CLOSEABLE, new Closeable() { @Override public void close() throws IOException { try { is.close(); } catch (IOException e) { } try { cos.close(); } catch (IOException e) { } } }); } else { msg.put(RMMessageConstants.SAVED_CONTENT, cos); } } private  PersistenceUtils(); static PersistenceUtils getInstance(); SequenceAcknowledgement deserialiseAcknowledgment(InputStream is); InputStream serialiseAcknowledgment(SequenceAcknowledgement ack); static void encodeRMContent(RMMessage rmmsg, Message msg, InputStream msgContent); static void decodeRMContent(RMMessage rmmsg, Message msg);  }### Answer:
@Test public void testDecodeRMContentWithAttachment() throws Exception { InputStream is = getClass().getResourceAsStream("SerializedRMMessage.txt"); CachedOutputStream cos = new CachedOutputStream(); IOUtils.copyAndCloseInput(is, cos); cos.flush(); RMMessage msg = new RMMessage(); msg.setContent(cos); msg.setContentType(MULTIPART_TYPE); Message messageImpl = new MessageImpl(); PersistenceUtils.decodeRMContent(msg, messageImpl); assertEquals(1, messageImpl.getAttachments().size()); CachedOutputStream cos1 = (CachedOutputStream)messageImpl .get(RMMessageConstants.SAVED_CONTENT); assertStartsWith(cos1.getInputStream(), "<soap:Envelope"); }