Search in sources :

Example 6 with TransformIdentity

use of org.apache.xml.security.stax.impl.transformer.TransformIdentity in project santuario-java by apache.

the class TransformIdentityTest method testInputStreamToInputStreamAPI.

@Test
public void testInputStreamToInputStreamAPI() throws Exception {
    TransformIdentity transformIdentity = new TransformIdentity();
    final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    Transformer transformer = new Transformer() {

        @Override
        public void setOutputStream(OutputStream outputStream) throws XMLSecurityException {
        }

        @Override
        public void setTransformer(Transformer transformer) throws XMLSecurityException {
        }

        @Override
        public void setProperties(Map<String, Object> properties) throws XMLSecurityException {
        }

        @Override
        public XMLSecurityConstants.TransformMethod getPreferredTransformMethod(XMLSecurityConstants.TransformMethod forInput) {
            return XMLSecurityConstants.TransformMethod.InputStream;
        }

        @Override
        public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
            Assert.fail("unexpected call to transform(XMLSecEvent");
        }

        @Override
        public void transform(InputStream inputStream) throws XMLStreamException {
            try {
                XMLSecurityUtils.copy(inputStream, byteArrayOutputStream);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public void doFinal() throws XMLStreamException {
        }
    };
    transformIdentity.setTransformer(transformer);
    transformIdentity.transform(this.getClass().getClassLoader().getResourceAsStream("ie/baltimore/merlin-examples/merlin-xmlenc-five/base64.xml"));
    transformIdentity.doFinal();
    Assert.assertEquals(831, byteArrayOutputStream.size());
}
Also used : XMLSecurityConstants(org.apache.xml.security.stax.ext.XMLSecurityConstants) TransformIdentity(org.apache.xml.security.stax.impl.transformer.TransformIdentity) Transformer(org.apache.xml.security.stax.ext.Transformer) UnixInputStream(org.apache.xml.security.test.stax.utils.UnixInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Map(java.util.Map) XMLSecEvent(org.apache.xml.security.stax.ext.stax.XMLSecEvent) Test(org.junit.Test)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 TransformIdentity (org.apache.xml.security.stax.impl.transformer.TransformIdentity)6 Test (org.junit.Test)6 XMLSecEvent (org.apache.xml.security.stax.ext.stax.XMLSecEvent)5 UnixInputStream (org.apache.xml.security.test.stax.utils.UnixInputStream)5 InputStream (java.io.InputStream)4 OutputStream (java.io.OutputStream)4 Map (java.util.Map)4 Transformer (org.apache.xml.security.stax.ext.Transformer)4 XMLSecurityConstants (org.apache.xml.security.stax.ext.XMLSecurityConstants)4 QName (javax.xml.namespace.QName)3 XMLEventReader (javax.xml.stream.XMLEventReader)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2