mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-03 23:25:52 +00:00
Clean up usages of IOUtils.closeQuietly and related calls (#2830)
* Clean up usages of IOUtils.closeQuietly and related calls predating Java 7. * Review comments from @oleg-nenashev. * Noticed another place where try-with-resources would protect against a potential leak.
This commit is contained in:
1 parent
77804c1451
commit
23cb13aad0
25 files changed
+131
-207
No files matched your search
@@ -25,7 +25,6 @@ package hudson;
|
||||
|
||||
import jenkins.util.SystemProperties;
|
||||
import com.sun.jna.Native;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import hudson.Proc.LocalProc;
|
||||
@@ -645,6 +644,10 @@ public class Util {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link IOUtils#copy(InputStream, OutputStream)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static void copyStream(@Nonnull InputStream in,@Nonnull OutputStream out) throws IOException {
|
||||
byte[] buf = new byte[8192];
|
||||
int len;
|
||||
@@ -652,6 +655,10 @@ public class Util {
|
||||
out.write(buf,0,len);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link IOUtils#copy(Reader, Writer)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static void copyStream(@Nonnull Reader in, @Nonnull Writer out) throws IOException {
|
||||
char[] buf = new char[8192];
|
||||
int len;
|
||||
@@ -659,21 +666,23 @@ public class Util {
|
||||
out.write(buf,0,len);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link IOUtils#copy(InputStream, OutputStream)} in a {@code try}-with-resources block
|
||||
*/
|
||||
@Deprecated
|
||||
public static void copyStreamAndClose(@Nonnull InputStream in, @Nonnull OutputStream out) throws IOException {
|
||||
try {
|
||||
try (InputStream _in = in; OutputStream _out = out) { // make sure both are closed, and use Throwable.addSuppressed
|
||||
copyStream(in,out);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(in);
|
||||
IOUtils.closeQuietly(out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link IOUtils#copy(Reader, Writer)} in a {@code try}-with-resources block
|
||||
*/
|
||||
@Deprecated
|
||||
public static void copyStreamAndClose(@Nonnull Reader in, @Nonnull Writer out) throws IOException {
|
||||
try {
|
||||
try (Reader _in = in; Writer _out = out) {
|
||||
copyStream(in,out);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(in);
|
||||
IOUtils.closeQuietly(out);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user