SbdhWrapper { public byte[] wrap(InputStream inputStream, Header headers) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (SbdWriter sbdWriter = SbdWriter.newInstance(baos, headers)) { XMLStreamUtils.copy(inputStream, sbdWriter.xmlWriter()); } catch (Exception ex) { throw new IllegalStateException("Unable to wrap document inside SBD (SBDH). " + ex.getMessage(), ex); } return baos.toByteArray(); }  byte[] wrap(InputStream inputStream, Header headers);  }
@Test public void testWrapWithHeaders() throws Exception { URL resource = ParseSbdhTest.class.getClassLoader().getResource("peppol-bis-invoice-sbdh.xml"); assertNotNull(resource); File file = new File(resource.toURI()); assertTrue(file.isFile() && file.canRead()); Header header = PARSER.parse(new FileInputStream(file)); InputStream resourceAsStream = SbdhWrapperTest.class.getClassLoader().getResourceAsStream("ehf-invoice-no-sbdh.xml"); assertNotNull(resourceAsStream); SbdhWrapper sbdhWrapper = new SbdhWrapper(); byte[] wrap = sbdhWrapper.wrap(resourceAsStream, header); Header resultHeaders = PARSER.parse(new ByteArrayInputStream(wrap)); assertEquals(resultHeaders.getSender(), header.getSender()); assertEquals(resultHeaders.getReceiver(), header.getReceiver()); assertEquals(resultHeaders.getDocumentType(), header.getDocumentType()); assertEquals(resultHeaders.getProcess(), header.getProcess()); }