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());
}
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());
}
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());
}
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());
}
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();
}
}
}
Aggregations