Search in sources :

Example 6 with XMLResourceEncodingDetector

use of org.eclipse.wst.xml.core.internal.contenttype.XMLResourceEncodingDetector in project webtools.sourceediting by eclipse.

the class XMLEncodingTests method testUTF16BE.

public void testUTF16BE() throws IOException {
    String filename = fileLocation + "utf16be.xml";
    doTestFileStream(filename, "UTF-16BE", new XMLResourceEncodingDetector());
}
Also used : XMLResourceEncodingDetector(org.eclipse.wst.xml.core.internal.contenttype.XMLResourceEncodingDetector)

Example 7 with XMLResourceEncodingDetector

use of org.eclipse.wst.xml.core.internal.contenttype.XMLResourceEncodingDetector in project webtools.sourceediting by eclipse.

the class XMLEncodingTests method testXMLEmptyFile.

public void testXMLEmptyFile() throws IOException {
    String filename = fileLocation + "EmptyFile.xml";
    doTestFileStream(filename, "UTF-8", new XMLResourceEncodingDetector());
}
Also used : XMLResourceEncodingDetector(org.eclipse.wst.xml.core.internal.contenttype.XMLResourceEncodingDetector)

Example 8 with XMLResourceEncodingDetector

use of org.eclipse.wst.xml.core.internal.contenttype.XMLResourceEncodingDetector in project webtools.sourceediting by eclipse.

the class XMLEncodingTests method testUtf16UnicodeStreamWithNoEncodingInHeader.

/**
 * This test shows unicode BOM should take priority over settings/defaults
 */
public void testUtf16UnicodeStreamWithNoEncodingInHeader() throws IOException {
    String filename = fileLocation + "utf16UnicodeStreamWithNoEncodingInHeader2.xml";
    doTestFileStream(filename, "UTF-16", new XMLResourceEncodingDetector());
}
Also used : XMLResourceEncodingDetector(org.eclipse.wst.xml.core.internal.contenttype.XMLResourceEncodingDetector)

Example 9 with XMLResourceEncodingDetector

use of org.eclipse.wst.xml.core.internal.contenttype.XMLResourceEncodingDetector in project webtools.sourceediting by eclipse.

the class XMLEncodingTests method testUTF16BEMalformed.

public void testUTF16BEMalformed() throws IOException {
    String filename = fileLocation + "utf16beMalformed.xml";
    doTestFileStream(filename, "UTF-16BE", new XMLResourceEncodingDetector());
}
Also used : XMLResourceEncodingDetector(org.eclipse.wst.xml.core.internal.contenttype.XMLResourceEncodingDetector)

Example 10 with XMLResourceEncodingDetector

use of org.eclipse.wst.xml.core.internal.contenttype.XMLResourceEncodingDetector in project webtools.sourceediting by eclipse.

the class XMLEncodingTests method doTestFileStream.

private void doTestFileStream(String filename, String expectedIANAEncoding, IResourceCharsetDetector detector) throws IOException {
    File file = TestsPlugin.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 = ((XMLResourceEncodingDetector) detector).getEncodingMemento();
        String foundIANAEncoding = encodingMemento.getJavaCharsetName();
        // 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;
        expectedIANAResult = expectedIANAEncoding.equalsIgnoreCase(foundIANAEncoding);
        assertTrue("encoding test file " + filename + " expected: " + expectedIANAEncoding + " found: " + foundIANAEncoding, expectedIANAResult);
        // a very simple read test ... will cause JUnit error (not fail) if throws exception.
        ensureCanRead(filename, foundIANAEncoding, istream);
    } finally {
        if (istream != null) {
            istream.close();
        }
        if (inputStream != null) {
            inputStream.close();
        }
    }
}
Also used : XMLResourceEncodingDetector(org.eclipse.wst.xml.core.internal.contenttype.XMLResourceEncodingDetector) 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)

Aggregations

XMLResourceEncodingDetector (org.eclipse.wst.xml.core.internal.contenttype.XMLResourceEncodingDetector)15 EncodingMemento (org.eclipse.wst.sse.core.internal.encoding.EncodingMemento)3 BufferedInputStream (java.io.BufferedInputStream)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Charset (java.nio.charset.Charset)1 CharsetDecoder (java.nio.charset.CharsetDecoder)1 MalformedInputException (java.nio.charset.MalformedInputException)1 MalformedInputExceptionWithDetail (org.eclipse.wst.sse.core.internal.exceptions.MalformedInputExceptionWithDetail)1