Search in sources :

Example 1 with CSSResourceEncodingDetector

use of org.eclipse.wst.css.core.internal.contenttype.CSSResourceEncodingDetector in project webtools.sourceediting by eclipse.

the class CSSEncodingTester method testJIS.

public void testJIS() throws IOException {
    String filename = fileLocation + "encoding_test_jis.css";
    doTestFileStream(filename, "ISO-2022-JP", new CSSResourceEncodingDetector());
}
Also used : CSSResourceEncodingDetector(org.eclipse.wst.css.core.internal.contenttype.CSSResourceEncodingDetector)

Example 2 with CSSResourceEncodingDetector

use of org.eclipse.wst.css.core.internal.contenttype.CSSResourceEncodingDetector in project webtools.sourceediting by eclipse.

the class CSSEncodingTester method testUTF16leMalformed.

public void testUTF16leMalformed() throws IOException {
    String filename = fileLocation + "utf16leMalformed.css";
    doTestFileStream(filename, "UTF-16LE", new CSSResourceEncodingDetector());
}
Also used : CSSResourceEncodingDetector(org.eclipse.wst.css.core.internal.contenttype.CSSResourceEncodingDetector)

Example 3 with CSSResourceEncodingDetector

use of org.eclipse.wst.css.core.internal.contenttype.CSSResourceEncodingDetector in project webtools.sourceediting by eclipse.

the class CSSEncodingTester method testEUCJP.

public void testEUCJP() throws IOException {
    String filename = fileLocation + "encoding_test_eucjp.css";
    doTestFileStream(filename, "EUC-JP", new CSSResourceEncodingDetector());
}
Also used : CSSResourceEncodingDetector(org.eclipse.wst.css.core.internal.contenttype.CSSResourceEncodingDetector)

Example 4 with CSSResourceEncodingDetector

use of org.eclipse.wst.css.core.internal.contenttype.CSSResourceEncodingDetector in project webtools.sourceediting by eclipse.

the class CSSEncodingTester method doTestFileStream.

private void doTestFileStream(String filename, String expectedIANAEncoding, IResourceCharsetDetector detector) throws IOException {
    File file = CSSEncodingTestsPlugin.getTestFile(filename);
    if (!file.exists())
        throw new IllegalArgumentException(filename + " was not found");
    InputStream inputStream = new FileInputStream(file);
    // InputStream inStream = getClass().getResourceAsStream(filename);
    InputStream istream = getMarkSupportedStream(inputStream);
    try {
        detector.set(istream);
        EncodingMemento encodingMemento = ((CSSResourceEncodingDetector) detector).getEncodingMemento();
        String foundIANAEncoding = null;
        if (encodingMemento != null) {
            foundIANAEncoding = encodingMemento.getDetectedCharsetName();
        }
        // I changed many "equals" to "equalsIgnoreCase" on 11/4/2002,
        // since
        // some issues with SHIFT_JIS vs. Shift_JIS were causing failures.
        // We do want to be tolerant on input, and accept either, but I
        // think
        // that SupportedJavaEncodings needs to be changed to "recommend"
        // Shift_JIS.
        boolean expectedIANAResult = false;
        if (expectedIANAEncoding == null) {
            expectedIANAResult = expectedIANAEncoding == foundIANAEncoding;
        } else {
            expectedIANAResult = expectedIANAEncoding.equalsIgnoreCase(foundIANAEncoding);
        }
        assertTrue("encoding test file " + filename + " expected: " + expectedIANAEncoding + " found: " + foundIANAEncoding, expectedIANAResult);
        // throws exception.
        if (foundIANAEncoding != null) {
            ensureCanRead(filename, foundIANAEncoding, istream);
        }
    } finally {
        if (istream != null) {
            istream.close();
        }
        if (inputStream != null) {
            inputStream.close();
        }
    }
}
Also used : CSSResourceEncodingDetector(org.eclipse.wst.css.core.internal.contenttype.CSSResourceEncodingDetector) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) EncodingMemento(org.eclipse.wst.sse.core.internal.encoding.EncodingMemento) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 5 with CSSResourceEncodingDetector

use of org.eclipse.wst.css.core.internal.contenttype.CSSResourceEncodingDetector in project webtools.sourceediting by eclipse.

the class CSSEncodingTester method testnonStandardIllFormed2.

public void testnonStandardIllFormed2() throws IOException {
    String filename = fileLocation + "nonStandardIllFormed2.css";
    doTestFileStream(filename, "ISO-8859-6", new CSSResourceEncodingDetector());
}
Also used : CSSResourceEncodingDetector(org.eclipse.wst.css.core.internal.contenttype.CSSResourceEncodingDetector)

Aggregations

CSSResourceEncodingDetector (org.eclipse.wst.css.core.internal.contenttype.CSSResourceEncodingDetector)14 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 EncodingMemento (org.eclipse.wst.sse.core.internal.encoding.EncodingMemento)1