本文整理匯總了Java中com.intellij.openapi.util.Pair.createNonNull方法的典型用法代碼示例。如果您正苦於以下問題:Java Pair.createNonNull方法的具體用法?Java Pair.createNonNull怎麽用?Java Pair.createNonNull使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.openapi.util.Pair
的用法示例。
在下文中一共展示了Pair.createNonNull方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getCharsetAndBOM
import com.intellij.openapi.util.Pair; //導入方法依賴的package包/類
@NotNull
private static Pair.NonNull<Charset,byte[]> getCharsetAndBOM(@NotNull byte[] content, @NotNull Charset charset) {
if (charset.name().contains(CharsetToolkit.UTF8) && CharsetToolkit.hasUTF8Bom(content)) {
return Pair.createNonNull(charset, CharsetToolkit.UTF8_BOM);
}
try {
Charset fromBOM = CharsetToolkit.guessFromBOM(content);
if (fromBOM != null) {
return Pair.createNonNull(fromBOM, ObjectUtils.notNull(CharsetToolkit.getMandatoryBom(fromBOM), ArrayUtil.EMPTY_BYTE_ARRAY));
}
}
catch (UnsupportedCharsetException ignore) {
}
return Pair.createNonNull(charset, ArrayUtil.EMPTY_BYTE_ARRAY);
}
示例2: charsetForWriting
import com.intellij.openapi.util.Pair; //導入方法依賴的package包/類
@NotNull
private static Pair.NonNull<Charset, byte[]> charsetForWriting(@Nullable Project project,
@NotNull VirtualFile virtualFile,
@NotNull String text,
@NotNull Charset existing) {
Charset specified = extractCharsetFromFileContent(project, virtualFile, text);
Pair.NonNull<Charset, byte[]> chosen = chooseMostlyHarmlessCharset(existing, specified, text);
Charset charset = chosen.first;
// in case of "UTF-16", OutputStreamWriter sometimes adds BOM on it's own.
// see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6800103
byte[] bom = virtualFile.getBOM();
Charset fromBom = bom == null ? null : CharsetToolkit.guessFromBOM(bom);
if (fromBom != null && !fromBom.equals(charset)) {
chosen = Pair.createNonNull(fromBom, toBytes(text, fromBom));
}
return chosen;
}
示例3: chooseMostlyHarmlessCharset
import com.intellij.openapi.util.Pair; //導入方法依賴的package包/類
@NotNull
public static Pair.NonNull<Charset, byte[]> chooseMostlyHarmlessCharset(@NotNull Charset existing, @NotNull Charset specified, @NotNull String text) {
try {
if (specified.equals(existing)) {
return Pair.createNonNull(specified, toBytes(text, existing));
}
byte[] out = isSupported(specified, text);
if (out != null) {
return Pair.createNonNull(specified, out); //if explicitly specified encoding is safe, return it
}
out = isSupported(existing, text);
if (out != null) {
return Pair.createNonNull(existing, out); //otherwise stick to the old encoding if it's ok
}
return Pair.createNonNull(specified, toBytes(text, specified)); //if both are bad there is no difference
}
catch (RuntimeException e) {
return Pair.createNonNull(Charset.defaultCharset(), toBytes(text, null)); //if both are bad and there is no hope, use the default charset
}
}