javax.xml.crypto.NodeSetData Java Examples
The following examples show how to use
javax.xml.crypto.NodeSetData.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseOpenApiGeneratorExampleTest.java From syndesis with Apache License 2.0 | 5 votes |
private static String c14Xml(final String xml) { if (xml == null) { return null; } try { final DocumentBuilder documentBuilder = DOCUMENT_BUILDER_FACTORY.newDocumentBuilder(); final Document document = documentBuilder.parse(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))); final TransformService transformation = TransformService.getInstance(CanonicalizationMethod.EXCLUSIVE_WITH_COMMENTS, "DOM"); transformation.init(null); final NodeList allElements = document.getElementsByTagName("*"); final List<Node> elements = new ArrayList<>(); for (int i = 0; i < allElements.getLength(); i++) { elements.add(allElements.item(i)); } final OctetStreamData data = (OctetStreamData) transformation.transform((NodeSetData) elements::iterator, null); try (final InputStream stream = data.getOctetStream()) { final byte[] buffy = new byte[stream.available()]; stream.read(buffy); return new String(buffy, StandardCharsets.UTF_8); } } catch (GeneralSecurityException | TransformException | SAXException | IOException | ParserConfigurationException e) { throw new AssertionError(e); } }