use of com.helger.commons.io.stream.NonBlockingByteArrayOutputStream in project ph-commons by phax.
the class XMLListHandlerTest method testWriteInvalid.
@Test
public void testWriteInvalid() {
final ICommonsList<String> aList = new CommonsArrayList<>();
try {
XMLListHandler.writeList(aList, (IHasOutputStream) null);
fail();
} catch (final NullPointerException ex) {
}
try {
XMLListHandler.writeList(aList, (OutputStream) null);
fail();
} catch (final NullPointerException ex) {
}
try {
XMLListHandler.writeList(null, new NonBlockingByteArrayOutputStream());
fail();
} catch (final NullPointerException ex) {
}
}
use of com.helger.commons.io.stream.NonBlockingByteArrayOutputStream 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());
}
use of com.helger.commons.io.stream.NonBlockingByteArrayOutputStream in project ph-commons by phax.
the class ClassPathHelperTest method testPrintClassPathEntries.
/**
* Test for method printClassPathEntries
*
* @throws UnsupportedEncodingException
* never
*/
@Test
public void testPrintClassPathEntries() throws UnsupportedEncodingException {
// Use default separator
NonBlockingByteArrayOutputStream baos = new NonBlockingByteArrayOutputStream();
ClassPathHelper.printClassPathEntries(new PrintStream(baos, false, StandardCharsets.ISO_8859_1.name()));
assertTrue(baos.getAsString(StandardCharsets.ISO_8859_1).length() > 0);
assertTrue(baos.getAsString(StandardCharsets.ISO_8859_1).indexOf("\n") > 0);
StreamHelper.close(baos);
// Use special separator
baos = new NonBlockingByteArrayOutputStream();
ClassPathHelper.printClassPathEntries(new PrintStream(baos, false, StandardCharsets.ISO_8859_1.name()), "$$$");
assertTrue(baos.getAsString(StandardCharsets.ISO_8859_1).length() > 0);
assertTrue(baos.getAsString(StandardCharsets.ISO_8859_1).indexOf("$$$") > 0);
assertTrue(baos.getAsString(StandardCharsets.UTF_8).indexOf("$$$") > 0);
StreamHelper.close(baos);
}
use of com.helger.commons.io.stream.NonBlockingByteArrayOutputStream in project ph-commons by phax.
the class JAXBMarshallerHelperTest method testCloseInternalOnWriteToOutputStream.
@Test
public void testCloseInternalOnWriteToOutputStream() {
final MockMarshallerExternal m = new MockMarshallerExternal();
final MutableBoolean aClosed = new MutableBoolean(false);
final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream() {
@Override
public void close() {
super.close();
aClosed.set(true);
}
};
{
final MockJAXBArchive aArc = new MockJAXBArchive();
aArc.setVersion("1.24");
m.write(aArc, aBAOS);
}
LOGGER.info(aBAOS.getAsString(StandardCharsets.UTF_8));
// Must be closed!
assertTrue("Not closed!", aClosed.booleanValue());
}
use of com.helger.commons.io.stream.NonBlockingByteArrayOutputStream in project as2-lib by phax.
the class ByteCoder method decode.
@Nonnull
public static String decode(@Nonnull final String inStr) {
try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream(inStr.length() / 3)) {
final Matcher aMatcher = RegExHelper.getMatcher(".[0-9]+.", inStr);
while (aMatcher.find()) {
final String sMatch = aMatcher.group();
// Ensure unsigned int
final byte me = (byte) (Integer.parseInt(sMatch.substring(1, sMatch.length() - 1)) & 0xff);
aBAOS.write(me);
}
return aBAOS.getAsString(StandardCharsets.ISO_8859_1);
}
}
Aggregations