Search in sources :

Example 1 with UnixInputStream

use of org.apache.xml.security.test.stax.utils.UnixInputStream in project santuario-java by apache.

the class Canonicalizer20010315Test method getBytesFromResource.

public static byte[] getBytesFromResource(URL resource, boolean unix) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    InputStream inputStream = resource.openStream();
    if (unix) {
        inputStream = new UnixInputStream(inputStream);
    }
    try {
        byte[] buf = new byte[1024];
        int len;
        while ((len = inputStream.read(buf)) > 0) {
            baos.write(buf, 0, len);
        }
        return baos.toByteArray();
    } finally {
        inputStream.close();
    }
}
Also used : UnixInputStream(org.apache.xml.security.test.stax.utils.UnixInputStream) UnixInputStream(org.apache.xml.security.test.stax.utils.UnixInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 2 with UnixInputStream

use of org.apache.xml.security.test.stax.utils.UnixInputStream in project santuario-java by apache.

the class TransformIdentityTest method testInputStreamToOutputStreamStreamAPI.

@Test
public void testInputStreamToOutputStreamStreamAPI() throws Exception {
    TransformIdentity transformIdentity = new TransformIdentity();
    final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    transformIdentity.setOutputStream(byteArrayOutputStream);
    transformIdentity.transform(new UnixInputStream(this.getClass().getClassLoader().getResourceAsStream("ie/baltimore/merlin-examples/merlin-xmldsig-twenty-three/xml-stylesheet.b64")));
    Assert.assertEquals(17786, byteArrayOutputStream.size());
}
Also used : TransformIdentity(org.apache.xml.security.stax.impl.transformer.TransformIdentity) UnixInputStream(org.apache.xml.security.test.stax.utils.UnixInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 3 with UnixInputStream

use of org.apache.xml.security.test.stax.utils.UnixInputStream in project santuario-java by apache.

the class TransformIdentityTest method testInputStreamToXMLSecEventAPI.

@Test
public void testInputStreamToXMLSecEventAPI() throws Exception {
    TransformIdentity transformIdentity = new TransformIdentity();
    final List<XMLSecEvent> xmlSecEvents = new ArrayList<>();
    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.XMLSecEvent;
        }

        @Override
        public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
            xmlSecEvents.add(xmlSecEvent);
        }

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

        @Override
        public void doFinal() throws XMLStreamException {
        }
    };
    transformIdentity.setTransformer(transformer);
    transformIdentity.transform(new UnixInputStream(this.getClass().getClassLoader().getResourceAsStream("ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml")));
    transformIdentity.doFinal();
    Assert.assertEquals(25, xmlSecEvents.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) UnixInputStream(org.apache.xml.security.test.stax.utils.UnixInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ArrayList(java.util.ArrayList) Map(java.util.Map) XMLSecEvent(org.apache.xml.security.stax.ext.stax.XMLSecEvent) Test(org.junit.Test)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 UnixInputStream (org.apache.xml.security.test.stax.utils.UnixInputStream)3 InputStream (java.io.InputStream)2 TransformIdentity (org.apache.xml.security.stax.impl.transformer.TransformIdentity)2 Test (org.junit.Test)2 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Transformer (org.apache.xml.security.stax.ext.Transformer)1 XMLSecurityConstants (org.apache.xml.security.stax.ext.XMLSecurityConstants)1 XMLSecEvent (org.apache.xml.security.stax.ext.stax.XMLSecEvent)1