Java Code Examples for org.eclipse.core.runtime.content.IContentDescription#BOM_UTF_8

The following examples show how to use org.eclipse.core.runtime.content.IContentDescription#BOM_UTF_8 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExternalFileDocument.java    From eclipse-encoding-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected byte[] resolveBOM() {
	InputStream inputStream = getInputStream();
	if (inputStream == null) {
		return null;
	}
	try {
		int first = inputStream.read();
		if (first == 0xEF) {
			int second = inputStream.read();
			int third = inputStream.read();
			if (second == 0xBB && third == 0xBF)
				return IContentDescription.BOM_UTF_8;
		} else if (first == 0xFE) {
			if (inputStream.read() == 0xFF)
				return IContentDescription.BOM_UTF_16BE;
		} else if (first == 0xFF) {
			if (inputStream.read() == 0xFE)
				return IContentDescription.BOM_UTF_16LE;
		}
	} catch (Exception e) {
		throw new IllegalStateException(e);
	} finally {
		IOUtils.closeQuietly(inputStream);
	}
	return null;
}
 
Example 2
Source File: JavaProject.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean hasUTF8BOM(byte[] bytes) {
	if (bytes.length > IContentDescription.BOM_UTF_8.length) {
		for (int i = 0, length = IContentDescription.BOM_UTF_8.length; i < length; i++) {
			if (IContentDescription.BOM_UTF_8[i] != bytes[i])
				return false;
		}
		return true;
	}
	return false;
}
 
Example 3
Source File: JavaClasspathParser.java    From sarl with Apache License 2.0 5 votes vote down vote up
private static boolean hasUTF8BOM(byte[] bytes) {
    if (bytes.length > IContentDescription.BOM_UTF_8.length) {
        for (int i = 0, length = IContentDescription.BOM_UTF_8.length; i < length; i++) {
            if (IContentDescription.BOM_UTF_8[i] != bytes[i]) {
                return false;
            }
        }
        return true;
    }
    return false;
}