本文整理匯總了Java中com.intellij.openapi.util.Pair.NonNull方法的典型用法代碼示例。如果您正苦於以下問題:Java Pair.NonNull方法的具體用法?Java Pair.NonNull怎麽用?Java Pair.NonNull使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.openapi.util.Pair
的用法示例。
在下文中一共展示了Pair.NonNull方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: write
import com.intellij.openapi.util.Pair; //導入方法依賴的package包/類
/**
* Overwrites file with text and sets modification stamp and time stamp to the specified values.
* <p/>
* Normally you should not use this method.
*
* @param requestor any object to control who called this method. Note that
* it is considered to be an external change if <code>requestor</code> is <code>null</code>.
* See {@link com.intellij.openapi.vfs.VirtualFileEvent#getRequestor}
* @param newModificationStamp new modification stamp or -1 if no special value should be set @return <code>Writer</code>
* @throws java.io.IOException if an I/O error occurs
* @see VirtualFile#getModificationStamp()
*/
public static void write(@Nullable Project project,
@NotNull VirtualFile virtualFile,
@NotNull Object requestor,
@NotNull String text,
long newModificationStamp) throws IOException {
Charset existing = virtualFile.getCharset();
Pair.NonNull<Charset, byte[]> chosen = charsetForWriting(project, virtualFile, text, existing);
Charset charset = chosen.first;
byte[] buffer = chosen.second;
if (!charset.equals(existing)) {
virtualFile.setCharset(charset);
}
setDetectedFromBytesFlagBack(virtualFile, buffer);
OutputStream outputStream = virtualFile.getOutputStream(requestor, newModificationStamp, -1);
try {
outputStream.write(buffer);
}
finally {
outputStream.close();
}
}
示例3: 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;
}
示例4: 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
}
}
示例5: getTextByBinaryPresentation
import com.intellij.openapi.util.Pair; //導入方法依賴的package包/類
@NotNull
public static CharSequence getTextByBinaryPresentation(@NotNull byte[] bytes,
@NotNull VirtualFile virtualFile,
boolean saveDetectedSeparators,
boolean saveBOM,
@NotNull FileType fileType) {
Pair.NonNull<Charset, byte[]> pair = doDetectCharsetAndSetBOM(virtualFile, bytes, saveBOM, fileType);
Charset charset = pair.getFirst();
byte[] bom = pair.getSecond();
int offset = bom.length;
Pair<CharSequence, String> result = convertBytes(bytes, charset, offset);
if (saveDetectedSeparators) {
virtualFile.setDetectedLineSeparator(result.getSecond());
}
return result.getFirst();
}
示例6: doDetectCharsetAndSetBOM
import com.intellij.openapi.util.Pair; //導入方法依賴的package包/類
@NotNull
private static Pair.NonNull<Charset, byte[]> doDetectCharsetAndSetBOM(@NotNull VirtualFile virtualFile, @NotNull byte[] content, boolean saveBOM, @NotNull FileType fileType) {
@NotNull Charset charset = virtualFile.isCharsetSet() ? virtualFile.getCharset() : detectCharset(virtualFile, content,fileType);
Pair.NonNull<Charset, byte[]> bomAndCharset = getCharsetAndBOM(content, charset);
final byte[] bom = bomAndCharset.second;
if (saveBOM && bom.length != 0) {
virtualFile.setBOM(bom);
setCharsetWasDetectedFromBytes(virtualFile, AUTO_DETECTED_FROM_BOM);
}
return bomAndCharset;
}