use of com.helger.commons.io.stream.StringInputStream in project as2-lib by phax.
the class HTTPHelperTest method testReadChunkLenEOS.
@Test(expected = EOFException.class)
public void testReadChunkLenEOS() throws Exception {
final InputStream noNewLine = new StringInputStream("1", StandardCharsets.UTF_8);
HTTPHelper.readChunkLen(noNewLine);
fail("An EOFException should have been thrown");
}
use of com.helger.commons.io.stream.StringInputStream in project ph-commons by phax.
the class MicroHelperTest method testConvertToMicroNode.
@Test
public void testConvertToMicroNode() throws SAXException, IOException, ParserConfigurationException {
final String sXML = "<?xml version='1.0'?>" + "<!DOCTYPE root [ <!ENTITY sc \"sc.exe\"> <!ELEMENT root (child, child2)> <!ELEMENT child (#PCDATA)> <!ELEMENT child2 (#PCDATA)> ]>" + "<root attr='value'>" + "<![CDATA[hihi]]>" + "text" + "≻" + "<child xmlns='http://myns' a='b' />" + "<child2 />" + "<!-- comment -->" + "<?stylesheet x y z?>" + "</root>";
final DocumentBuilderFactory aDBF = XMLFactory.createDefaultDocumentBuilderFactory();
aDBF.setCoalescing(false);
aDBF.setIgnoringComments(false);
final Document doc = aDBF.newDocumentBuilder().parse(new StringInputStream(sXML, StandardCharsets.ISO_8859_1));
assertNotNull(doc);
final IMicroNode aNode = MicroHelper.convertToMicroNode(doc);
assertNotNull(aNode);
try {
MicroHelper.convertToMicroNode(null);
fail();
} catch (final NullPointerException ex) {
}
}
use of com.helger.commons.io.stream.StringInputStream in project ph-commons by phax.
the class DOMReaderTest method testReadXMLDOMInputStream.
/**
* Test method readXMLDOM @ never
*/
@Test
public void testReadXMLDOMInputStream() {
Document doc = DOMReader.readXMLDOM(new StringInputStream("<root/>", StandardCharsets.ISO_8859_1));
assertNotNull(doc);
doc = DOMReader.readXMLDOM(new StringInputStream("<?xml version=\"1.0\"?>\n<root/>", StandardCharsets.ISO_8859_1));
assertNotNull(doc);
try {
// null reader not allowed
DOMReader.readXMLDOM((InputStream) null);
fail();
} catch (final NullPointerException ex) {
}
// non-XML
assertNull(DOMReader.readXMLDOM(new NonBlockingByteArrayInputStream(new byte[0])));
doc = DOMReader.readXMLDOM(new StringInputStream("<?xml version=\"1.0\"?>\n<root/>", StandardCharsets.ISO_8859_1));
assertNotNull(doc);
}
use of com.helger.commons.io.stream.StringInputStream in project ph-schematron by phax.
the class SchematronResourcePureTest method testFromByteArray.
@Test
public void testFromByteArray() {
final String sTest = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n" + "<iso:schema xmlns=\"http://purl.oclc.org/dsdl/schematron\" \n" + " xmlns:iso=\"http://purl.oclc.org/dsdl/schematron\" \n" + " xmlns:sch=\"http://www.ascc.net/xml/schematron\"\n" + " queryBinding='xpath2'\n" + " schemaVersion=\"ISO19757-3\">\n" + " <iso:title>Test ISO schematron file. Introduction mode</iso:title>\n" + " <iso:ns prefix=\"dp\" uri=\"http://www.dpawson.co.uk/ns#\" />\n" + " <iso:pattern >\n" + " <iso:title>A very simple pattern with a title</iso:title>\n" + " <iso:rule context=\"chapter\">\n" + " <iso:assert test=\"title\">Chapter should have a title</iso:assert>\n" + " <iso:report test=\"count(para)\">\n" + " <iso:value-of select=\"count(para)\"/> paragraphs</iso:report>\n" + " </iso:rule>\n" + " </iso:pattern>\n" + "\n" + "</iso:schema>";
assertTrue(SchematronResourcePure.fromByteArray(sTest.getBytes(StandardCharsets.UTF_8)).isValidSchematron());
assertTrue(SchematronResourcePure.fromInputStream("ba-from-string", new StringInputStream(sTest, StandardCharsets.UTF_8)).isValidSchematron());
}
use of com.helger.commons.io.stream.StringInputStream in project as2-lib by phax.
the class MimeBodyPartFuncTest method testReadContentTransferEncodingBase64.
@Test
public void testReadContentTransferEncodingBase64() throws MessagingException, IOException {
final String sHTTP = "Content-Type: text/plain" + CHttp.EOL + "Content-Transfer-Encoding: base64" + CHttp.EOL + "x-custom: junit" + CHttp.EOL + "Content-Length: 44" + CHttp.EOL + CHttp.EOL + "VGVzdCBtZXNzYWdlCkxpbmUgMgoKTGluZSA0CkVPRg==" + CHttp.EOL;
InputStream aIS = new StringInputStream(sHTTP, StandardCharsets.ISO_8859_1);
// Parse all HTTP headers from stream
final InternetHeaders aHeaders = new InternetHeaders(aIS);
final String sCTE = aHeaders.getHeader(CHttpHeader.CONTENT_TRANSFER_ENCODING)[0];
if (StringHelper.hasText(sCTE))
aIS = AS2IOHelper.getContentTransferEncodingAwareInputStream(aIS, sCTE);
// Read the payload
final byte[] aData = StreamHelper.getAllBytes(aIS);
// Extract content type
final String sReceivedContentType = AS2HttpHelper.getCleanContentType(aHeaders.getHeader(CHttpHeader.CONTENT_TYPE)[0]);
final MimeBodyPart aReceivedPart = new MimeBodyPart();
aReceivedPart.setDataHandler(new ByteArrayDataSource(aData, sReceivedContentType, null).getAsDataHandler());
aReceivedPart.setHeader("x-received", "true");
final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream();
aReceivedPart.writeTo(aBAOS);
StreamHelper.close(aBAOS);
final String sMsgPart = aBAOS.getAsString(StandardCharsets.ISO_8859_1);
if (true)
LOGGER.info(sMsgPart);
}
Aggregations