@NotNull
  public static String shiftIndentInside(
      @NotNull String initial, final int i, boolean shiftEmptyLines) {
    StringBuilder result = new StringBuilder(initial.length());
    List<byte[]> lines;
    try {
      LineReader reader =
          new LineReader(new ByteArrayInputStream(initial.getBytes(CharsetToolkit.UTF8_CHARSET)));
      lines = reader.readLines();
    } catch (IOException e) {
      throw new RuntimeException(e);
    }

    boolean first = true;
    for (byte[] line : lines) {
      try {
        if (!first) result.append('\n');
        if (line.length > 0 || shiftEmptyLines) {
          StringUtil.repeatSymbol(result, ' ', i);
        }
        result.append(new String(line));
      } finally {
        first = false;
      }
    }

    return result.toString();
  }
예제 #2
0
  @Nullable
  private static String[] readStringsFromFile(String fileName) {
    String[] result = null;
    try {
      InputStream predefined = CfmlLangInfo.class.getResourceAsStream(fileName);
      if (predefined != null) {
        LineReader lineReader = new LineReader(predefined);

        //noinspection unchecked
        List<byte[]> list = lineReader.readLines();
        result = new String[list.size()];
        for (int i = 0; i < list.size(); i++) {
          byte[] bytes = list.get(i);
          final String s = new String(bytes);
          result[i] = s;
        }
      }
    } catch (Exception e) {
      LOG.error(e);
    }
    return result;
  }