Repository: jenkinsci/jenkins
File: core/src/main/java/hudson/util/StreamTaskListener.java (Java)

Code before:
    public StreamTaskListener(@NonNull PrintStream out) {
        this(out, null);
    }

    /**
     * @deprecated as of 2.328
     *      The caller should use {@link #StreamTaskListener(OutputStream, Charset)} to pass in
     *      the charset and output stream separately, so that this class can handle encoding correctly,
     *      or use {@link #fromStdout()} or {@link #fromStderr()}.
     */
    @Deprecated
    public StreamTaskListener(@NonNull OutputStream out) {
        this(out, null);
    }

    public StreamTaskListener(@NonNull OutputStream out, @CheckForNull Charset charset) {
        if (charset == null) {
            this.out = out instanceof PrintStream ? (PrintStream) out : new PrintStream(out, false, Charset.defaultCharset());
        } else {
            this.out = new PrintStream(out, false, charset);
        }
        this.charset = charset;
    }

    /**
     * @deprecated as of 2.328
     *      The caller should use {@link #StreamTaskListener(File, Charset)} to pass in
     *      the charset and file separately, so that this class can handle encoding correctly.
     */
    @Deprecated
    public StreamTaskListener(@NonNull File out) throws IOException {
        this(out, null);
    }

    public StreamTaskListener(@NonNull File out, @CheckForNull Charset charset) throws IOException {
        // don't do buffering so that what's written to the listener
        // gets reflected to the file immediately, which can then be
        // served to the browser immediately
        this(Files.newOutputStream(asPath(out)), charset);
    }

    private static Path asPath(@NonNull File out) throws IOException {
        try {
            return out.toPath();
        } catch (InvalidPathException e) {
            throw new IOException(e);
        }
    }

    /**
     * Constructs a {@link StreamTaskListener} that sends the output to a specified file.

Review comment (suggestion):
The deprecation was inserted in commit 3b29e9d4603 as part of 2.329

```suggestion
     * @deprecated as of 2.329
```

Code after:
    public StreamTaskListener(@NonNull PrintStream out) {
        this(out, null);
    }

    /**
     * @deprecated as of 2.328
     *      The caller should use {@link #StreamTaskListener(OutputStream, Charset)} to pass in
     *      the charset and output stream separately, so that this class can handle encoding correctly,
     *      or use {@link #fromStdout()} or {@link #fromStderr()}.
     */
    @Deprecated
    public StreamTaskListener(@NonNull OutputStream out) {
        this(out, null);
    }

    public StreamTaskListener(@NonNull OutputStream out, @CheckForNull Charset charset) {
        if (charset == null) {
            this.out = out instanceof PrintStream ? (PrintStream) out : new PrintStream(out, false, Charset.defaultCharset());
        } else {
            this.out = new PrintStream(out, false, charset);
        }
        this.charset = charset;
    }

    /**
     * @deprecated as of 2.329
     *      The caller should use {@link #StreamTaskListener(File, Charset)} to pass in
     *      the charset and file separately, so that this class can handle encoding correctly.
     */
    @Deprecated
    public StreamTaskListener(@NonNull File out) throws IOException {
        this(out, null);
    }

    public StreamTaskListener(@NonNull File out, @CheckForNull Charset charset) throws IOException {
        // don't do buffering so that what's written to the listener
        // gets reflected to the file immediately, which can then be
        // served to the browser immediately
        this(Files.newOutputStream(asPath(out)), charset);
    }

    private static Path asPath(@NonNull File out) throws IOException {
        try {
            return out.toPath();
        } catch (InvalidPathException e) {
            throw new IOException(e);
        }
    }

    /**
     * Constructs a {@link StreamTaskListener} that sends the output to a specified file.