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();
}
}
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());
}
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());
}
Aggregations