本文整理匯總了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;
}