本文整理汇总了Java中org.eclipse.core.runtime.content.IContentDescription.getCharset方法的典型用法代码示例。如果您正苦于以下问题:Java IContentDescription.getCharset方法的具体用法?Java IContentDescription.getCharset怎么用?Java IContentDescription.getCharset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.core.runtime.content.IContentDescription
的用法示例。
在下文中一共展示了IContentDescription.getCharset方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCharset
import org.eclipse.core.runtime.content.IContentDescription; //导入方法依赖的package包/类
public static String getCharset(String name, InputStream stream) throws IOException {
IContentDescription description = getContentDescription(name, stream);
return description == null ? null : description.getCharset();
}
示例2: cacheEncodingState
import org.eclipse.core.runtime.content.IContentDescription; //导入方法依赖的package包/类
protected void cacheEncodingState() {
fEncoding = fExplicitEncoding;
fHasBOM = false;
fIsCacheUpdated = true;
InputStream stream = null;
try {
stream = getFileContents(fFileStore);
if (stream == null) return;
QualifiedName[] options =
new QualifiedName[] {IContentDescription.CHARSET, IContentDescription.BYTE_ORDER_MARK};
IContentDescription description =
null; // Platform.getContentTypeManager().getDescriptionFor(stream, fFileStore.getName(),
// options);
if (description != null) {
fHasBOM = description.getProperty(IContentDescription.BYTE_ORDER_MARK) != null;
if (fEncoding == null) fEncoding = description.getCharset();
}
} catch (CoreException e) {
// do nothing
} /*catch (IOException e) {
// do nothing
}*/ finally {
try {
if (stream != null) stream.close();
} catch (IOException ex) {
FileBuffersPlugin.getDefault()
.log(
new Status(
IStatus.ERROR,
FileBuffersPlugin.PLUGIN_ID,
IStatus.OK,
FileBuffersMessages.JavaTextFileBuffer_error_closeStream,
ex));
}
}
// Use global default
if (fEncoding == null) fEncoding = fManager.getDefaultEncoding();
}
示例3: createMemento
import org.eclipse.core.runtime.content.IContentDescription; //导入方法依赖的package包/类
protected EncodingMemento createMemento(
IContentDescription contentDescription) {
EncodingMemento result;
String appropriateDefault = contentDescription.getContentType()
.getDefaultCharset();
String detectedCharset = (String) contentDescription
.getProperty(IContentDescriptionExtended.DETECTED_CHARSET);
String unSupportedCharset = (String) contentDescription
.getProperty(IContentDescriptionExtended.UNSUPPORTED_CHARSET);
String javaCharset = contentDescription.getCharset();
// Set default workbench encoding:
if (detectedCharset == null && appropriateDefault == null) {
detectedCharset = javaCharset = appropriateDefault = ResourcesPlugin
.getEncoding();
}
// integrity checks for debugging
if (javaCharset == null) {
Logger.log(Logger.INFO_DEBUG, "charset equaled null!"); //$NON-NLS-1$
} else if (javaCharset.length() == 0) {
Logger.log(Logger.INFO_DEBUG, "charset equaled emptyString!"); //$NON-NLS-1$
}
byte[] BOM = (byte[]) contentDescription
.getProperty(IContentDescription.BYTE_ORDER_MARK);
// result = (EncodingMemento)
// contentDescription.getProperty(IContentDescriptionExtended.ENCODING_MEMENTO);
result = createEncodingMemento(BOM, javaCharset, detectedCharset,
unSupportedCharset, appropriateDefault, null);
if (!result.isValid()) {
result.setAppropriateDefault(appropriateDefault);
// integrity check for debugging "invalid" cases.
// the apprriate default we have, should equal what's in the
// detected field. (not sure this is always required)
if (DEBUG) {
if (appropriateDefault != null
&& !appropriateDefault.equals(detectedCharset)) {
Logger
.log(Logger.INFO_DEBUG,
"appropriate did not equal detected, as expected for invalid charset case"); //$NON-NLS-1$
}
}
}
return result;
}