Search in sources :

Example 1 with ByteArrayOutputStreamProvider

use of com.helger.commons.io.streamprovider.ByteArrayOutputStreamProvider in project ph-commons by phax.

the class XMLMapHandlerTest method testReadBuildInfo.

@Test
public void testReadBuildInfo() {
    final ICommonsMap<String, String> aMap = new CommonsHashMap<>();
    final IReadableResource aRes = new ClassPathResource("xml/buildinfo.xml");
    assertTrue(XMLMapHandler.readMap(aRes, aMap).isSuccess());
    assertNull(XMLMapHandler.readMap(new ClassPathResource("test1.txt")));
    assertTrue(aMap.containsKey("buildinfo.version"));
    assertEquals("1", aMap.get("buildinfo.version"));
    assertTrue(XMLMapHandler.readMap(aRes).containsKey("buildinfo.version"));
    assertEquals("1", XMLMapHandler.readMap(aRes).get("buildinfo.version"));
    assertTrue(XMLMapHandler.writeMap(aMap, new ByteArrayOutputStreamProvider()).isSuccess());
    assertTrue(XMLMapHandler.writeMap(aMap, new NonBlockingByteArrayOutputStream()).isSuccess());
}
Also used : ByteArrayOutputStreamProvider(com.helger.commons.io.streamprovider.ByteArrayOutputStreamProvider) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) IReadableResource(com.helger.commons.io.resource.IReadableResource) NonBlockingByteArrayOutputStream(com.helger.commons.io.stream.NonBlockingByteArrayOutputStream) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 2 with ByteArrayOutputStreamProvider

use of com.helger.commons.io.streamprovider.ByteArrayOutputStreamProvider in project ph-commons by phax.

the class XMLListHandlerTest method testRead.

@Test
public void testRead() {
    ICommonsList<String> aList = new CommonsArrayList<>();
    final IReadableResource aRes = new ClassPathResource("xml/list.xml");
    XMLListHandler.readList(aRes, aList);
    assertEquals(3, aList.size());
    assertTrue(aList.contains("item1"));
    assertNotNull(XMLListHandler.readList(aRes));
    assertNull(XMLListHandler.readList(new ClassPathResource("test1.txt")));
    assertEquals(3, XMLListHandler.readList(aRes).size());
    assertTrue(XMLListHandler.readList(aRes).contains("item1"));
    assertTrue(XMLListHandler.writeList(aList, new NonBlockingByteArrayOutputStream()).isSuccess());
    final String sXML = "<root><item/><item value='a' /><item value='a' /></root>";
    aList = XMLListHandler.readList(new StringInputStreamProvider(sXML, StandardCharsets.ISO_8859_1));
    assertNotNull(aList);
    assertEquals(2, aList.size());
    assertEquals("a", aList.get(0));
    assertEquals("a", aList.get(1));
    final ICommonsSet<String> aSet = new CommonsHashSet<>();
    XMLListHandler.readList(new StringInputStreamProvider(sXML, StandardCharsets.ISO_8859_1), aSet);
    assertEquals(1, aSet.size());
    assertTrue(aSet.contains("a"));
    assertTrue(XMLListHandler.writeList(aList, new NonBlockingByteArrayOutputStream()).isSuccess());
    assertTrue(XMLListHandler.writeList(aList, new ByteArrayOutputStreamProvider()).isSuccess());
}
Also used : ByteArrayOutputStreamProvider(com.helger.commons.io.streamprovider.ByteArrayOutputStreamProvider) IReadableResource(com.helger.commons.io.resource.IReadableResource) NonBlockingByteArrayOutputStream(com.helger.commons.io.stream.NonBlockingByteArrayOutputStream) StringInputStreamProvider(com.helger.commons.io.streamprovider.StringInputStreamProvider) CommonsHashSet(com.helger.commons.collection.impl.CommonsHashSet) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 3 with ByteArrayOutputStreamProvider

use of com.helger.commons.io.streamprovider.ByteArrayOutputStreamProvider in project ph-commons by phax.

the class XMLMapHandlerTest method testWriteInvalid.

@Test
public void testWriteInvalid() {
    final ICommonsMap<String, String> aMap = new CommonsHashMap<>();
    try {
        XMLMapHandler.writeMap(aMap, (IHasOutputStream) null);
        fail();
    } catch (final NullPointerException ex) {
    }
    try {
        XMLMapHandler.writeMap(null, new ByteArrayOutputStreamProvider());
        fail();
    } catch (final NullPointerException ex) {
    }
    try {
        XMLMapHandler.writeMap(aMap, (OutputStream) null);
        fail();
    } catch (final NullPointerException ex) {
    }
    try {
        XMLMapHandler.writeMap(null, new NonBlockingByteArrayOutputStream());
        fail();
    } catch (final NullPointerException ex) {
    }
}
Also used : ByteArrayOutputStreamProvider(com.helger.commons.io.streamprovider.ByteArrayOutputStreamProvider) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) NonBlockingByteArrayOutputStream(com.helger.commons.io.stream.NonBlockingByteArrayOutputStream) Test(org.junit.Test)

Example 4 with ByteArrayOutputStreamProvider

use of com.helger.commons.io.streamprovider.ByteArrayOutputStreamProvider in project ph-commons by phax.

the class XMLEmitterTest method testMisc.

@Test
public void testMisc() {
    assertEquals("<!DOCTYPE qname PUBLIC \"pubid\" \"sysid\">", XMLEmitter.getDocTypeHTMLRepresentation(EXMLSerializeVersion.XML_10, EXMLIncorrectCharacterHandling.DEFAULT, new MicroDocumentType("qname", "pubid", "sysid")));
    assertEquals("<!DOCTYPE qname PUBLIC \"pubid\" \"sysid\">", XMLEmitter.getDocTypeHTMLRepresentation(EXMLSerializeVersion.XML_11, EXMLIncorrectCharacterHandling.DEFAULT, new MicroDocumentType("qname", "pubid", "sysid")));
    CommonsTestHelper.testToStringImplementation(new XMLEmitter(new ByteArrayOutputStreamProvider().getWriter(StandardCharsets.ISO_8859_1, EAppend.DEFAULT), XMLWriterSettings.DEFAULT_XML_SETTINGS));
}
Also used : ByteArrayOutputStreamProvider(com.helger.commons.io.streamprovider.ByteArrayOutputStreamProvider) MicroDocumentType(com.helger.xml.microdom.MicroDocumentType) Test(org.junit.Test)

Aggregations

ByteArrayOutputStreamProvider (com.helger.commons.io.streamprovider.ByteArrayOutputStreamProvider)4 Test (org.junit.Test)4 NonBlockingByteArrayOutputStream (com.helger.commons.io.stream.NonBlockingByteArrayOutputStream)3 CommonsHashMap (com.helger.commons.collection.impl.CommonsHashMap)2 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)2 IReadableResource (com.helger.commons.io.resource.IReadableResource)2 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)1 CommonsHashSet (com.helger.commons.collection.impl.CommonsHashSet)1 StringInputStreamProvider (com.helger.commons.io.streamprovider.StringInputStreamProvider)1 MicroDocumentType (com.helger.xml.microdom.MicroDocumentType)1