public File getPreprocessedTextFile(File originalTextFile, IWriterFactory writerFactory) throws IOException { final File preprocessedTextFile = FileUtil.createTempFile(TEMP_FILE_PREFIX, null); final BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(originalTextFile)); Collection lines; try { lines = new LineReader(inputStream).readLines(); } finally { inputStream.close(); } FileOutputStream output = new FileOutputStream(preprocessedTextFile); try { for (Iterator each = lines.iterator(); each.hasNext();) { output.write((byte[]) each.next()); if (each.hasNext()){ output.write('\n'); } } } finally { output.close(); } return preprocessedTextFile; }
@NotNull public static String shiftIndentInside(@NotNull String initial, final int i, boolean shiftEmptyLines) throws IOException { StringBuilder result = new StringBuilder(initial.length()); LineReader reader = new LineReader(new ByteArrayInputStream(initial.getBytes())); boolean first = true; for (byte[] line : reader.readLines()) { 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(); }
@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(); }