当前位置: 首页>>代码示例>>Java>>正文


Java Pair.NonNull方法代码示例

本文整理汇总了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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:LoadTextUtil.java

示例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();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:35,代码来源:LoadTextUtil.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:LoadTextUtil.java

示例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
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:LoadTextUtil.java

示例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();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:LoadTextUtil.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:LoadTextUtil.java


注:本文中的com.intellij.openapi.util.Pair.NonNull方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。