Пример #1
0
  /**
   * @return pair.first - file contents (null if file does not exist), pair.second - file line
   *     separators
   */
  @NotNull
  public static Pair<byte[], String> loadFile(@Nullable final VirtualFile file) throws IOException {
    if (file == null || !file.exists()) {
      return NON_EXISTENT_FILE_DATA;
    }

    byte[] bytes = file.contentsToByteArray();
    String lineSeparator = file.getDetectedLineSeparator();
    if (lineSeparator == null) {
      lineSeparator =
          detectLineSeparators(CharsetToolkit.UTF8_CHARSET.decode(ByteBuffer.wrap(bytes)), null)
              .getSeparatorString();
    }
    return Pair.create(bytes, lineSeparator);
  }
Пример #2
0
 static String getDetectedLineSeparator(@NotNull VirtualFile file) {
   return file.getDetectedLineSeparator();
 }