Skip to content

Add explicit Charset to Apache FileUtils methods #36

@yeikel

Description

@yeikel

Examples :

    /**
     * Writes a String to a file creating the file if it does not exist using the default encoding for the VM.
     *
     * @deprecated 2.5 use {@link #writeStringToFile(File, String, Charset, boolean)} instead (and specify the appropriate encoding)
     */
    @Deprecated
    public static void writeStringToFile(final File file, final String data, final boolean append) throws IOException {
        writeStringToFile(file, data, Charset.defaultCharset(), append);
    }

 @Deprecated
    public static void writeStringToFile(final File file, final String data) throws IOException {
        writeStringToFile(file, data, Charset.defaultCharset(), false);
    }

 @Deprecated
    public static String readFileToString(final File file) throws IOException {
        return readFileToString(file, Charset.defaultCharset());
    }

    @Deprecated
    public static List<String> readLines(final File file) 

And many others : https://github.com/apache/commons-io/blob/master/src/main/java/org/apache/commons/io/FileUtils.java

Charset should be configurable. Ideally, it should accept :

  • Use StandardCharsets whenever possible
  • Charsets by name such as Windows-1252

Similar issue : openrewrite/rewrite-migrate-java#99

See also : openrewrite/rewrite#1724

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Recipes Wanted

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions