本文整理汇总了Java中javax.xml.stream.XMLStreamReader.getCharacterEncodingScheme方法的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamReader.getCharacterEncodingScheme方法的具体用法?Java XMLStreamReader.getCharacterEncodingScheme怎么用?Java XMLStreamReader.getCharacterEncodingScheme使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.stream.XMLStreamReader
的用法示例。
在下文中一共展示了XMLStreamReader.getCharacterEncodingScheme方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getStartEndOffsetFromXML
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
/**
* Returns character offsets from line numbers from JFace Text Document object.
*/
private static int[] getStartEndOffsetFromXML(final XMLStreamReader streamReader,
final IFile file, final EventMemento memento, final EventMemento current) {
final int[] offsetStartEnd = new int[2];
try {
String charsetName = streamReader.getCharacterEncodingScheme();
if (charsetName == null) {
charsetName = "UTF-8";
}
final Scanner scanner = new Scanner(file.getContents(), charsetName);
final IDocument document = new Document(scanner.useDelimiter("\\A").next());
scanner.close();
int start = 0;
int end = 0;
final IRegion startRegion = document.getLineInformation(memento.getLineNumber() - 1);
start = startRegion.getOffset() + memento.getColumnNumber() - 2;
final IRegion endRegion = document.getLineInformation(current.getLineNumber());
end = endRegion.getOffset() - 1;
offsetStartEnd[0] = start;
offsetStartEnd[1] = end;
} catch (final BadLocationException e1) {
// e1.printStackTrace();
System.out
.println(e1.toString() + " --> in MarkerFactory's getStartEndOffsetFromXML function");
} catch (final CoreException e) {
e.printStackTrace();
}
return offsetStartEnd;
}