本文整理匯總了Java中java.nio.charset.Charset.displayName方法的典型用法代碼示例。如果您正苦於以下問題:Java Charset.displayName方法的具體用法?Java Charset.displayName怎麽用?Java Charset.displayName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.nio.charset.Charset
的用法示例。
在下文中一共展示了Charset.displayName方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleDecodingError
import java.nio.charset.Charset; //導入方法依賴的package包/類
/**
* Handle an error thrown while file decoding. Inform search listener and
* append detailed info into the IDE Log.
*/
protected final void handleDecodingError(SearchListener listener,
FileObject file, CharsetDecoder decoder,
CharacterCodingException e) {
String charsetName;
try {
if (decoder.isAutoDetecting() && decoder.isCharsetDetected()) {
Charset c = decoder.detectedCharset();
if (c != null) {
charsetName = c.displayName();
} else {
charsetName = decoder.charset().displayName();
}
} else {
charsetName = decoder.charset().displayName();
}
} catch (Exception ex) {
LOG.log(Level.INFO, "Failed to obtain actual charset", ex); //NOI18N
charsetName = decoder == null ? "null" : decoder.toString();//NOI18N
}
String msg = NbBundle.getMessage(ResultView.class,
"TEXT_INFO_ERROR_ENCODING", charsetName); //NOI18N
listener.fileContentMatchingError(file.getPath(),
new Exception(msg, e));
LOG.log(Level.INFO, "{0}; UnmappableCharacterException: {1}", //NOI18N
new Object[]{file.getPath(), e.getMessage()});
}
示例2: availableCharsets
import java.nio.charset.Charset; //導入方法依賴的package包/類
@Override
public String[] availableCharsets() {
List<String> charsets = new Collection<String>();
for(Charset charset : Charset.availableCharsets().values()) {
final String name = charset.displayName();
if(!(name.startsWith("IBM") || ((name.startsWith("x-") && !name.startsWith("x-Mac"))))) {
charsets.add(name);
}
}
return charsets.toArray(new String[charsets.size()]);
}
示例3: load
import java.nio.charset.Charset; //導入方法依賴的package包/類
/**
* load the content of this page from a fetched HttpEntity.
* @param entity HttpEntity
* @param maxBytes The maximum number of bytes to read
* @throws Exception when load fails
*/
public void load(HttpEntity entity, int maxBytes) throws Exception {
contentType = null;
Header type = entity.getContentType();
if (type != null) {
contentType = type.getValue();
}
contentEncoding = null;
Header encoding = entity.getContentEncoding();
if (encoding != null) {
contentEncoding = encoding.getValue();
}
Charset charset = ContentType.getOrDefault(entity).getCharset();
if (charset != null) {
contentCharset = charset.displayName();
}else {
contentCharset = Charset.defaultCharset().displayName();
}
contentData = toByteArray(entity, maxBytes);
}