public static void convertLineEndings()

in src/main/java/org/apache/maven/plugins/assembly/utils/LineEndingsUtils.java [57:92]


    public static void convertLineEndings(
            final File source, File dest, LineEndings lineEndings, final Boolean atEndOfFile, String encoding)
            throws IOException {
        // MASSEMBLY-637, MASSEMBLY-96
        // find characters at the end of the file
        // needed to preserve the last line ending
        // only check for LF (as CRLF also ends in LF)
        String eofChars = "";
        if (atEndOfFile == null) {
            if (source.length() >= 1) {
                try (RandomAccessFile raf = new RandomAccessFile(source, "r")) {
                    raf.seek(source.length() - 1);
                    byte last = raf.readByte();
                    if (last == '\n') {
                        eofChars = lineEndings.getLineEndingCharacters();
                    }
                }
            }
        } else if (atEndOfFile) {
            eofChars = lineEndings.getLineEndingCharacters();
        }

        try (BufferedReader in = getBufferedReader(source, encoding);
                BufferedWriter out = getBufferedWriter(dest, encoding)) {
            String line = in.readLine();
            while (line != null) {
                out.write(line);
                line = in.readLine();
                if (line != null) {
                    out.write(lineEndings.getLineEndingCharacters());
                } else {
                    out.write(eofChars);
                }
            }
        }
    }