Search in sources :

Example 1 with ByteArrayInputStreamProvider

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

the class CSSReader30SpecialFuncTest method testReadWithBOM.

@Test
public void testReadWithBOM() {
    final String sCSSBase = "/* comment */.class{color:red}.class{color:blue}";
    for (final EUnicodeBOM eBOM : EUnicodeBOM.values()) {
        final Charset aDeterminedCharset = eBOM.getCharset();
        if (aDeterminedCharset != null) {
            final CascadingStyleSheet aCSS = CSSReader.readFromStream(new ByteArrayInputStreamProvider(ArrayHelper.getConcatenated(eBOM.getAllBytes(), sCSSBase.getBytes(aDeterminedCharset))), aDeterminedCharset, ECSSVersion.CSS30, new DoNothingCSSParseErrorHandler());
            assertNotNull("Failed to read with BOM " + eBOM, aCSS);
            assertEquals(".class{color:red}.class{color:blue}", new CSSWriter(ECSSVersion.CSS30, true).getCSSAsString(aCSS));
        }
    }
}
Also used : CascadingStyleSheet(com.helger.css.decl.CascadingStyleSheet) ByteArrayInputStreamProvider(com.helger.commons.io.streamprovider.ByteArrayInputStreamProvider) EUnicodeBOM(com.helger.commons.charset.EUnicodeBOM) DoNothingCSSParseErrorHandler(com.helger.css.reader.errorhandler.DoNothingCSSParseErrorHandler) Charset(java.nio.charset.Charset) CSSWriter(com.helger.css.writer.CSSWriter) Test(org.junit.Test)

Aggregations

EUnicodeBOM (com.helger.commons.charset.EUnicodeBOM)1 ByteArrayInputStreamProvider (com.helger.commons.io.streamprovider.ByteArrayInputStreamProvider)1 CascadingStyleSheet (com.helger.css.decl.CascadingStyleSheet)1 DoNothingCSSParseErrorHandler (com.helger.css.reader.errorhandler.DoNothingCSSParseErrorHandler)1 CSSWriter (com.helger.css.writer.CSSWriter)1 Charset (java.nio.charset.Charset)1 Test (org.junit.Test)1