@@ -490,19 +490,13 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener { | |||||
+ pathComponent.lastModified() + "-" + pathComponent.length(); | + pathComponent.lastModified() + "-" + pathComponent.length(); | ||||
String classpath = pathMap.get(absPathPlusTimeAndLength); | String classpath = pathMap.get(absPathPlusTimeAndLength); | ||||
if (classpath == null) { | if (classpath == null) { | ||||
JarFile jarFile = null; | |||||
try { | |||||
jarFile = new JarFile(pathComponent); | |||||
try (JarFile jarFile = new JarFile(pathComponent)) { | |||||
final Manifest manifest = jarFile.getManifest(); | final Manifest manifest = jarFile.getManifest(); | ||||
if (manifest == null) { | if (manifest == null) { | ||||
return; | return; | ||||
} | } | ||||
classpath = manifest.getMainAttributes() | classpath = manifest.getMainAttributes() | ||||
.getValue(Attributes.Name.CLASS_PATH); | .getValue(Attributes.Name.CLASS_PATH); | ||||
} finally { | |||||
if (jarFile != null) { | |||||
jarFile.close(); | |||||
} | |||||
} | } | ||||
if (classpath == null) { | if (classpath == null) { | ||||
classpath = ""; | classpath = ""; | ||||
@@ -1602,8 +1596,7 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener { | |||||
} | } | ||||
private static boolean readFully(final File f, final byte[] b) throws IOException { | private static boolean readFully(final File f, final byte[] b) throws IOException { | ||||
final FileInputStream fis = new FileInputStream(f); | |||||
try { | |||||
try (FileInputStream fis = new FileInputStream(f)) { | |||||
final int len = b.length; | final int len = b.length; | ||||
int count = 0, x = 0; | int count = 0, x = 0; | ||||
while (count != len) { | while (count != len) { | ||||
@@ -1614,8 +1607,6 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener { | |||||
count += x; | count += x; | ||||
} | } | ||||
return count == len; | return count == len; | ||||
} finally { | |||||
fis.close(); | |||||
} | } | ||||
} | } | ||||
@@ -349,13 +349,7 @@ public class Jar extends Zip { | |||||
} | } | ||||
return null; | return null; | ||||
} finally { | } finally { | ||||
if (zf != null) { | |||||
try { | |||||
zf.close(); | |||||
} catch (IOException e) { | |||||
// TODO - log an error? throw an exception? | |||||
} | |||||
} | |||||
FileUtils.close(zf); | |||||
} | } | ||||
} | } | ||||
@@ -388,13 +382,7 @@ public class Jar extends Zip { | |||||
} | } | ||||
return false; | return false; | ||||
} finally { | } finally { | ||||
if (zf != null) { | |||||
try { | |||||
zf.close(); | |||||
} catch (IOException e) { | |||||
// TODO - log an error? throw an exception? | |||||
} | |||||
} | |||||
FileUtils.close(zf); | |||||
} | } | ||||
} | } | ||||
@@ -1144,9 +1132,7 @@ public class Jar extends Zip { | |||||
protected static void grabFilesAndDirs(String file, List<String> dirs, | protected static void grabFilesAndDirs(String file, List<String> dirs, | ||||
List<String> files) | List<String> files) | ||||
throws IOException { | throws IOException { | ||||
org.apache.tools.zip.ZipFile zf = null; | |||||
try { | |||||
zf = new org.apache.tools.zip.ZipFile(file, "utf-8"); | |||||
try (org.apache.tools.zip.ZipFile zf = new org.apache.tools.zip.ZipFile(file, "utf-8")) { | |||||
Enumeration<org.apache.tools.zip.ZipEntry> entries = zf.getEntries(); | Enumeration<org.apache.tools.zip.ZipEntry> entries = zf.getEntries(); | ||||
HashSet<String> dirSet = new HashSet<String>(); | HashSet<String> dirSet = new HashSet<String>(); | ||||
while (entries.hasMoreElements()) { | while (entries.hasMoreElements()) { | ||||
@@ -1166,10 +1152,6 @@ public class Jar extends Zip { | |||||
} | } | ||||
} | } | ||||
dirs.addAll(dirSet); | dirs.addAll(dirSet); | ||||
} finally { | |||||
if (zf != null) { | |||||
zf.close(); | |||||
} | |||||
} | } | ||||
} | } | ||||
@@ -1420,8 +1420,7 @@ public class Javac extends MatchingTask { | |||||
continue; | continue; | ||||
} | } | ||||
log("Creating empty " + pkgInfoClass); | log("Creating empty " + pkgInfoClass); | ||||
final OutputStream os = new FileOutputStream(pkgInfoClass); | |||||
try { | |||||
try (OutputStream os = new FileOutputStream(pkgInfoClass)) { | |||||
os.write(PACKAGE_INFO_CLASS_HEADER); | os.write(PACKAGE_INFO_CLASS_HEADER); | ||||
final byte[] name = pkg.getBytes("UTF-8"); | final byte[] name = pkg.getBytes("UTF-8"); | ||||
final int length = name.length + /* "/package-info" */ 13; | final int length = name.length + /* "/package-info" */ 13; | ||||
@@ -1429,8 +1428,6 @@ public class Javac extends MatchingTask { | |||||
os.write((byte) length % 256); | os.write((byte) length % 256); | ||||
os.write(name); | os.write(name); | ||||
os.write(PACKAGE_INFO_CLASS_FOOTER); | os.write(PACKAGE_INFO_CLASS_FOOTER); | ||||
} finally { | |||||
os.close(); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -177,11 +177,8 @@ public abstract class Pack extends Task { | |||||
*/ | */ | ||||
protected void zipResource(Resource resource, OutputStream zOut) | protected void zipResource(Resource resource, OutputStream zOut) | ||||
throws IOException { | throws IOException { | ||||
InputStream rIn = resource.getInputStream(); | |||||
try { | |||||
try (InputStream rIn = resource.getInputStream()) { | |||||
zipFile(rIn, zOut); | zipFile(rIn, zOut); | ||||
} finally { | |||||
rIn.close(); | |||||
} | } | ||||
} | } | ||||
@@ -533,13 +533,8 @@ public class Property extends Task { | |||||
Properties props = new Properties(); | Properties props = new Properties(); | ||||
log("Loading " + url, Project.MSG_VERBOSE); | log("Loading " + url, Project.MSG_VERBOSE); | ||||
try { | try { | ||||
InputStream is = url.openStream(); | |||||
try { | |||||
try (InputStream is = url.openStream()) { | |||||
loadProperties(props, is, url.getFile().endsWith(".xml")); | loadProperties(props, is, url.getFile().endsWith(".xml")); | ||||
} finally { | |||||
if (is != null) { | |||||
is.close(); | |||||
} | |||||
} | } | ||||
addProperties(props); | addProperties(props); | ||||
} catch (IOException ex) { | } catch (IOException ex) { | ||||
@@ -354,7 +354,7 @@ public class Replace extends MatchingTask { | |||||
* a StringBuffer. Compatible with the Replacefilter. | * a StringBuffer. Compatible with the Replacefilter. | ||||
* @since 1.7 | * @since 1.7 | ||||
*/ | */ | ||||
private class FileInput /* JDK 5: implements Closeable */ { | |||||
private class FileInput implements AutoCloseable { | |||||
private StringBuffer outputBuffer; | private StringBuffer outputBuffer; | ||||
private final InputStream is; | private final InputStream is; | ||||
private Reader reader; | private Reader reader; | ||||
@@ -418,7 +418,7 @@ public class Replace extends MatchingTask { | |||||
* Replacefilter. | * Replacefilter. | ||||
* @since 1.7 | * @since 1.7 | ||||
*/ | */ | ||||
private class FileOutput /* JDK 5: implements Closeable */ { | |||||
private class FileOutput implements AutoCloseable { | |||||
private StringBuffer inputBuffer; | private StringBuffer inputBuffer; | ||||
private final OutputStream os; | private final OutputStream os; | ||||
private Writer writer; | private Writer writer; | ||||
@@ -667,10 +667,8 @@ public class Replace extends MatchingTask { | |||||
File temp = FILE_UTILS.createTempFile("rep", ".tmp", | File temp = FILE_UTILS.createTempFile("rep", ".tmp", | ||||
src.getParentFile(), false, true); | src.getParentFile(), false, true); | ||||
try { | try { | ||||
FileInput in = new FileInput(src); | |||||
try { | |||||
FileOutput out = new FileOutput(temp); | |||||
try { | |||||
try (FileInput in = new FileInput(src); | |||||
FileOutput out = new FileOutput(temp)) { | |||||
out.setInputBuffer(buildFilterChain(in.getOutputBuffer())); | out.setInputBuffer(buildFilterChain(in.getOutputBuffer())); | ||||
while (in.readChunk()) { | while (in.readChunk()) { | ||||
@@ -682,11 +680,6 @@ public class Replace extends MatchingTask { | |||||
flushFilterChain(); | flushFilterChain(); | ||||
out.flush(); | out.flush(); | ||||
} finally { | |||||
out.close(); | |||||
} | |||||
} finally { | |||||
in.close(); | |||||
} | } | ||||
boolean changes = (replaceCount != repCountStart); | boolean changes = (replaceCount != repCountStart); | ||||
if (changes) { | if (changes) { | ||||
@@ -834,13 +834,7 @@ public class SQLExec extends JDBCTask { | |||||
throw e; | throw e; | ||||
} | } | ||||
} finally { | } finally { | ||||
if (resultSet != null) { | |||||
try { | |||||
resultSet.close(); | |||||
} catch (SQLException e) { | |||||
//ignore | |||||
} | |||||
} | |||||
FileUtils.close(resultSet); | |||||
} | } | ||||
} | } | ||||
@@ -854,13 +848,8 @@ public class SQLExec extends JDBCTask { | |||||
*/ | */ | ||||
@Deprecated | @Deprecated | ||||
protected void printResults(PrintStream out) throws SQLException { | protected void printResults(PrintStream out) throws SQLException { | ||||
ResultSet rs = getStatement().getResultSet(); | |||||
try { | |||||
try (ResultSet rs = getStatement().getResultSet()) { | |||||
printResults(rs, out); | printResults(rs, out); | ||||
} finally { | |||||
if (rs != null) { | |||||
rs.close(); | |||||
} | |||||
} | } | ||||
} | } | ||||
@@ -1911,14 +1911,11 @@ public class Zip extends MatchingTask { | |||||
getLocation()); | getLocation()); | ||||
} | } | ||||
final FileInputStream fIn = new FileInputStream(file); | |||||
try { | |||||
try (FileInputStream fIn = new FileInputStream(file)) { | |||||
// ZIPs store time with a granularity of 2 seconds, round up | // ZIPs store time with a granularity of 2 seconds, round up | ||||
zipFile(fIn, zOut, vPath, | zipFile(fIn, zOut, vPath, | ||||
file.lastModified() + (roundUp ? ROUNDUP_MILLIS : 0), | file.lastModified() + (roundUp ? ROUNDUP_MILLIS : 0), | ||||
null, mode); | null, mode); | ||||
} finally { | |||||
fIn.close(); | |||||
} | } | ||||
} | } | ||||
@@ -126,17 +126,13 @@ public class Message extends ProjectComponent { | |||||
: new BufferedWriter(new OutputStreamWriter(ps)); | : new BufferedWriter(new OutputStreamWriter(ps)); | ||||
if (messageSource != null) { | if (messageSource != null) { | ||||
// Read message from a file | // Read message from a file | ||||
Reader freader = getReader(messageSource); | |||||
try { | |||||
BufferedReader in = new BufferedReader(freader); | |||||
try (Reader freader = getReader(messageSource); | |||||
BufferedReader in = new BufferedReader(freader)) { | |||||
String line = null; | String line = null; | ||||
while ((line = in.readLine()) != null) { | while ((line = in.readLine()) != null) { | ||||
out.write(getProject().replaceProperties(line)); | out.write(getProject().replaceProperties(line)); | ||||
out.newLine(); | out.newLine(); | ||||
} | } | ||||
} finally { | |||||
freader.close(); | |||||
} | } | ||||
} else { | } else { | ||||
out.write(getProject().replaceProperties(buffer.substring(0))); | out.write(getProject().replaceProperties(buffer.substring(0))); | ||||
@@ -147,16 +147,13 @@ class PlainMailer extends Mailer { | |||||
int length; | int length; | ||||
final int maxBuf = 1024; | final int maxBuf = 1024; | ||||
byte[] buf = new byte[maxBuf]; | byte[] buf = new byte[maxBuf]; | ||||
FileInputStream finstr = new FileInputStream(file); | |||||
try { | |||||
BufferedInputStream in = new BufferedInputStream(finstr, buf.length); | |||||
try (FileInputStream finstr = new FileInputStream(file); | |||||
BufferedInputStream in = new BufferedInputStream(finstr, buf.length)) { | |||||
while ((length = in.read(buf)) != -1) { | while ((length = in.read(buf)) != -1) { | ||||
out.write(buf, 0, length); | out.write(buf, 0, length); | ||||
} | } | ||||
} finally { | |||||
finstr.close(); | |||||
} | } | ||||
} | } | ||||
@@ -40,16 +40,11 @@ class UUMailer extends PlainMailer { | |||||
+ "readable."); | + "readable."); | ||||
} | } | ||||
FileInputStream finstr = new FileInputStream(file); | |||||
try { | |||||
BufferedInputStream in = new BufferedInputStream(finstr); | |||||
try (FileInputStream finstr = new FileInputStream(file); | |||||
BufferedInputStream in = new BufferedInputStream(finstr)) { | |||||
UUEncoder encoder = new UUEncoder(file.getName()); | UUEncoder encoder = new UUEncoder(file.getName()); | ||||
encoder.encode(in, out); | encoder.encode(in, out); | ||||
} finally { | |||||
finstr.close(); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -192,27 +192,16 @@ public class PropertyFile extends Task { | |||||
if (propertyfile.exists()) { | if (propertyfile.exists()) { | ||||
log("Updating property file: " | log("Updating property file: " | ||||
+ propertyfile.getAbsolutePath()); | + propertyfile.getAbsolutePath()); | ||||
FileInputStream fis = null; | |||||
try { | |||||
fis = new FileInputStream(propertyfile); | |||||
BufferedInputStream bis = new BufferedInputStream(fis); | |||||
try (FileInputStream fis = new FileInputStream(propertyfile); | |||||
BufferedInputStream bis = new BufferedInputStream(fis)) { | |||||
properties.load(bis); | properties.load(bis); | ||||
} finally { | |||||
if (fis != null) { | |||||
fis.close(); | |||||
} | |||||
} | } | ||||
} else { | } else { | ||||
log("Creating new property file: " | log("Creating new property file: " | ||||
+ propertyfile.getAbsolutePath()); | + propertyfile.getAbsolutePath()); | ||||
FileOutputStream out = null; | |||||
try { | |||||
out = new FileOutputStream(propertyfile.getAbsolutePath()); | |||||
try (FileOutputStream out = | |||||
new FileOutputStream(propertyfile.getAbsolutePath())) { | |||||
out.flush(); | out.flush(); | ||||
} finally { | |||||
if (out != null) { | |||||
out.close(); | |||||
} | |||||
} | } | ||||
} | } | ||||
} catch (IOException ioe) { | } catch (IOException ioe) { | ||||
@@ -356,13 +356,13 @@ public class ReplaceRegExp extends Task { | |||||
try { | try { | ||||
boolean changes = false; | boolean changes = false; | ||||
InputStream is = new FileInputStream(f); | |||||
try { | |||||
Reader r = encoding != null ? new InputStreamReader(is, encoding) : new InputStreamReader(is); | |||||
OutputStream os = new FileOutputStream(temp); | |||||
try (InputStream is = new FileInputStream(f); | |||||
OutputStream os = new FileOutputStream(temp)) { | |||||
Reader r = null; | |||||
Writer w = null; | |||||
try { | try { | ||||
Writer w = encoding != null ? new OutputStreamWriter(os, encoding) : new OutputStreamWriter(os); | |||||
r = encoding != null ? new InputStreamReader(is, encoding) : new InputStreamReader(is); | |||||
w = encoding != null ? new OutputStreamWriter(os, encoding) : new OutputStreamWriter(os); | |||||
log("Replacing pattern '" + regex.getPattern(getProject()) | log("Replacing pattern '" + regex.getPattern(getProject()) | ||||
+ "' with '" + subs.getExpression(getProject()) | + "' with '" + subs.getExpression(getProject()) | ||||
+ "' in '" + f.getPath() + "'" + (byline ? " by line" : "") | + "' in '" + f.getPath() + "'" + (byline ? " by line" : "") | ||||
@@ -426,15 +426,10 @@ public class ReplaceRegExp extends Task { | |||||
} else { | } else { | ||||
changes = multilineReplace(r, w, options); | changes = multilineReplace(r, w, options); | ||||
} | } | ||||
r.close(); | |||||
w.close(); | |||||
} finally { | } finally { | ||||
os.close(); | |||||
FileUtils.close(r); | |||||
FileUtils.close(w); | |||||
} | } | ||||
} finally { | |||||
is.close(); | |||||
} | } | ||||
if (changes) { | if (changes) { | ||||
log("File has changed; saving the updated file", Project.MSG_VERBOSE); | log("File has changed; saving the updated file", Project.MSG_VERBOSE); | ||||
@@ -293,17 +293,11 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware | |||||
// and avoid keeping the handle until the object is garbaged. | // and avoid keeping the handle until the object is garbaged. | ||||
// (always keep control), otherwise you won't be able to delete | // (always keep control), otherwise you won't be able to delete | ||||
// the file quickly on windows. | // the file quickly on windows. | ||||
InputStream xslStream = null; | |||||
try { | |||||
xslStream | |||||
= new BufferedInputStream(stylesheet.getInputStream()); | |||||
try (InputStream xslStream = | |||||
new BufferedInputStream(stylesheet.getInputStream())) { | |||||
templatesModTime = stylesheet.getLastModified(); | templatesModTime = stylesheet.getLastModified(); | ||||
final Source src = getSource(xslStream, stylesheet); | final Source src = getSource(xslStream, stylesheet); | ||||
templates = getFactory().newTemplates(src); | templates = getFactory().newTemplates(src); | ||||
} finally { | |||||
if (xslStream != null) { | |||||
xslStream.close(); | |||||
} | |||||
} | } | ||||
} | } | ||||
@@ -96,9 +96,7 @@ public class AntAnalyzer extends AbstractAnalyzer { | |||||
} | } | ||||
} finally { | } finally { | ||||
FileUtils.close(inStream); | FileUtils.close(inStream); | ||||
if (zipFile != null) { | |||||
zipFile.close(); | |||||
} | |||||
FileUtils.close(zipFile); | |||||
} | } | ||||
} catch (IOException ioe) { | } catch (IOException ioe) { | ||||
// ignore | // ignore | ||||
@@ -866,30 +866,11 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { | |||||
throw new BuildException(msg, ioe); | throw new BuildException(msg, ioe); | ||||
} finally { | } finally { | ||||
// need to close files and perhaps rename output | |||||
if (genericJar != null) { | |||||
try { | |||||
genericJar.close(); | |||||
} catch (IOException closeException) { | |||||
// empty | |||||
} | |||||
} | |||||
if (wlJar != null) { | |||||
try { | |||||
wlJar.close(); | |||||
} catch (IOException closeException) { | |||||
// empty | |||||
} | |||||
} | |||||
FileUtils.close(genericJar); | |||||
FileUtils.close(wlJar); | |||||
FileUtils.close(newJarStream); | |||||
if (newJarStream != null) { | if (newJarStream != null) { | ||||
try { | |||||
newJarStream.close(); | |||||
} catch (IOException closeException) { | |||||
// empty | |||||
} | |||||
try { | try { | ||||
FILE_UTILS.rename(newWLJarFile, weblogicJarFile); | FILE_UTILS.rename(newWLJarFile, weblogicJarFile); | ||||
} catch (IOException renameException) { | } catch (IOException renameException) { | ||||
@@ -832,29 +832,11 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { | |||||
throw new BuildException(msg, ioe); | throw new BuildException(msg, ioe); | ||||
} finally { | } finally { | ||||
// need to close files and perhaps rename output | // need to close files and perhaps rename output | ||||
if (genericJar != null) { | |||||
try { | |||||
genericJar.close(); | |||||
} catch (IOException closeException) { | |||||
// Ignore | |||||
} | |||||
} | |||||
if (wasJar != null) { | |||||
try { | |||||
wasJar.close(); | |||||
} catch (IOException closeException) { | |||||
// Ignore | |||||
} | |||||
} | |||||
FileUtils.close(genericJar); | |||||
FileUtils.close(wasJar); | |||||
FileUtils.close(newJarStream); | |||||
if (newJarStream != null) { | if (newJarStream != null) { | ||||
try { | |||||
newJarStream.close(); | |||||
} catch (IOException closeException) { | |||||
// Ignore | |||||
} | |||||
try { | try { | ||||
FILE_UTILS.rename(newwasJarFile, websphereJarFile); | FILE_UTILS.rename(newwasJarFile, websphereJarFile); | ||||
} catch (IOException renameException) { | } catch (IOException renameException) { | ||||
@@ -168,12 +168,9 @@ public class AggregateTransformer { | |||||
protected void setXmlfile(File xmlfile) throws BuildException { | protected void setXmlfile(File xmlfile) throws BuildException { | ||||
try { | try { | ||||
DocumentBuilder builder = privateDBFactory.newDocumentBuilder(); | DocumentBuilder builder = privateDBFactory.newDocumentBuilder(); | ||||
InputStream in = new FileInputStream(xmlfile); | |||||
try { | |||||
try (InputStream in = new FileInputStream(xmlfile)) { | |||||
Document doc = builder.parse(in); | Document doc = builder.parse(in); | ||||
setXmlDocument(doc); | setXmlDocument(doc); | ||||
} finally { | |||||
in.close(); | |||||
} | } | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
throw new BuildException("Error while parsing document: " + xmlfile, e); | throw new BuildException("Error while parsing document: " + xmlfile, e); | ||||
@@ -213,9 +213,8 @@ public class XMLResultAggregator extends Task implements XMLConstants { | |||||
* @throws IOException thrown if there is an error while writing the content. | * @throws IOException thrown if there is an error while writing the content. | ||||
*/ | */ | ||||
protected void writeDOMTree(Document doc, File file) throws IOException { | protected void writeDOMTree(Document doc, File file) throws IOException { | ||||
OutputStream os = new FileOutputStream(file); | |||||
try { | |||||
PrintWriter wri = new PrintWriter(new OutputStreamWriter(new BufferedOutputStream(os), "UTF8")); | |||||
try (OutputStream os = new FileOutputStream(file); | |||||
PrintWriter wri = new PrintWriter(new OutputStreamWriter(new BufferedOutputStream(os), "UTF8"))) { | |||||
wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); | wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); | ||||
(new DOMElementWriter()).write(doc.getDocumentElement(), wri, 0, " "); | (new DOMElementWriter()).write(doc.getDocumentElement(), wri, 0, " "); | ||||
wri.flush(); | wri.flush(); | ||||
@@ -223,8 +222,6 @@ public class XMLResultAggregator extends Task implements XMLConstants { | |||||
if (wri.checkError()) { | if (wri.checkError()) { | ||||
throw new IOException("Error while writing DOM content"); | throw new IOException("Error while writing DOM content"); | ||||
} | } | ||||
} finally { | |||||
os.close(); | |||||
} | } | ||||
} | } | ||||
@@ -495,9 +495,7 @@ public class SSHExec extends SSHBase { | |||||
*/ | */ | ||||
private void writeToFile(final String from, final boolean append, final File to) | private void writeToFile(final String from, final boolean append, final File to) | ||||
throws IOException { | throws IOException { | ||||
FileWriter out = null; | |||||
try { | |||||
out = new FileWriter(to.getAbsolutePath(), append); | |||||
try (FileWriter out = new FileWriter(to.getAbsolutePath(), append)) { | |||||
final StringReader in = new StringReader(from); | final StringReader in = new StringReader(from); | ||||
final char[] buffer = new char[BUFFER_SIZE]; | final char[] buffer = new char[BUFFER_SIZE]; | ||||
int bytesRead; | int bytesRead; | ||||
@@ -509,10 +507,6 @@ public class SSHExec extends SSHBase { | |||||
out.write(buffer, 0, bytesRead); | out.write(buffer, 0, bytesRead); | ||||
} | } | ||||
out.flush(); | out.flush(); | ||||
} finally { | |||||
if (out != null) { | |||||
out.close(); | |||||
} | |||||
} | } | ||||
} | } | ||||
@@ -1445,13 +1445,7 @@ public class FileUtils { | |||||
* @param device output writer, can be null. | * @param device output writer, can be null. | ||||
*/ | */ | ||||
public static void close(Writer device) { | public static void close(Writer device) { | ||||
if (null != device) { | |||||
try { | |||||
device.close(); | |||||
} catch (IOException e) { | |||||
//ignore | |||||
} | |||||
} | |||||
close((AutoCloseable) device); | |||||
} | } | ||||
/** | /** | ||||
@@ -1461,13 +1455,7 @@ public class FileUtils { | |||||
* @param device Reader, can be null. | * @param device Reader, can be null. | ||||
*/ | */ | ||||
public static void close(Reader device) { | public static void close(Reader device) { | ||||
if (null != device) { | |||||
try { | |||||
device.close(); | |||||
} catch (IOException e) { | |||||
//ignore | |||||
} | |||||
} | |||||
close((AutoCloseable) device); | |||||
} | } | ||||
/** | /** | ||||
@@ -1477,13 +1465,7 @@ public class FileUtils { | |||||
* @param device stream, can be null. | * @param device stream, can be null. | ||||
*/ | */ | ||||
public static void close(OutputStream device) { | public static void close(OutputStream device) { | ||||
if (null != device) { | |||||
try { | |||||
device.close(); | |||||
} catch (IOException e) { | |||||
//ignore | |||||
} | |||||
} | |||||
close((AutoCloseable) device); | |||||
} | } | ||||
/** | /** | ||||
@@ -1493,13 +1475,7 @@ public class FileUtils { | |||||
* @param device stream, can be null. | * @param device stream, can be null. | ||||
*/ | */ | ||||
public static void close(InputStream device) { | public static void close(InputStream device) { | ||||
if (null != device) { | |||||
try { | |||||
device.close(); | |||||
} catch (IOException e) { | |||||
//ignore | |||||
} | |||||
} | |||||
close((AutoCloseable) device); | |||||
} | } | ||||
/** | /** | ||||
@@ -1510,13 +1486,7 @@ public class FileUtils { | |||||
* @since Ant 1.8.0 | * @since Ant 1.8.0 | ||||
*/ | */ | ||||
public static void close(Channel device) { | public static void close(Channel device) { | ||||
if (null != device) { | |||||
try { | |||||
device.close(); | |||||
} catch (IOException e) { | |||||
//ignore | |||||
} | |||||
} | |||||
close((AutoCloseable) device); | |||||
} | } | ||||
/** | /** | ||||
@@ -1543,6 +1513,24 @@ public class FileUtils { | |||||
} | } | ||||
} | } | ||||
/** | |||||
* Close an {@link AutoCloseable} without throwing any exception | |||||
* if something went wrong. Do not attempt to close it if the | |||||
* argument is null. | |||||
* | |||||
* @param ac AutoCloseable, can be null. | |||||
* @since Ant 1.10.0 | |||||
*/ | |||||
public static void close(AutoCloseable ac) { | |||||
if (null != ac) { | |||||
try { | |||||
ac.close(); | |||||
} catch (Exception e) { | |||||
//ignore | |||||
} | |||||
} | |||||
} | |||||
/** | /** | ||||
* Delete the file with {@link File#delete()} if the argument is not null. | * Delete the file with {@link File#delete()} if the argument is not null. | ||||
* Do nothing on a null argument. | * Do nothing on a null argument. | ||||
@@ -72,7 +72,7 @@ import java.util.zip.ZipException; | |||||
* </ul> | * </ul> | ||||
* | * | ||||
*/ | */ | ||||
public class ZipFile { | |||||
public class ZipFile implements AutoCloseable { | |||||
private static final int HASH_SIZE = 509; | private static final int HASH_SIZE = 509; | ||||
static final int NIBLET_MASK = 0x0f; | static final int NIBLET_MASK = 0x0f; | ||||
static final int BYTE_SHIFT = 8; | static final int BYTE_SHIFT = 8; | ||||