From 4613fe2ba9f847697f1d2e901dc332361ec04d02 Mon Sep 17 00:00:00 2001 From: Conor MacNeill Date: Fri, 4 Jul 2003 13:22:43 +0000 Subject: [PATCH] Remove double-check pattern. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274767 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/util/FileUtils.java | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/src/main/org/apache/tools/ant/util/FileUtils.java b/src/main/org/apache/tools/ant/util/FileUtils.java index 318ff99e8..c6fd55982 100644 --- a/src/main/org/apache/tools/ant/util/FileUtils.java +++ b/src/main/org/apache/tools/ant/util/FileUtils.java @@ -136,6 +136,8 @@ public class FileUtils { /** * Factory method. + * + * @return a new instance of FileUtils. */ public static FileUtils newFileUtils() { return new FileUtils(); @@ -144,7 +146,8 @@ public class FileUtils { /** * Empty constructor. */ - protected FileUtils() {} + protected FileUtils() { + } /** * Get the URL for a file taking into account # characters @@ -264,7 +267,7 @@ public class FileUtils { public void copyFile(String sourceFile, String destFile, FilterSetCollection filters, Vector filterChains, boolean overwrite, boolean preserveLastModified, - String inputEncoding, String outputEncoding, + String inputEncoding, String outputEncoding, Project project) throws IOException { copyFile(new File(sourceFile), new File(destFile), filters, @@ -456,12 +459,12 @@ public class FileUtils { } } } else if (filterChainsAvailable - || (inputEncoding != null + || (inputEncoding != null && !inputEncoding.equals(outputEncoding)) || (inputEncoding == null && outputEncoding != null)) { BufferedReader in = null; BufferedWriter out = null; - + try { if (inputEncoding == null) { in = new BufferedReader(new FileReader(sourceFile)); @@ -472,7 +475,7 @@ public class FileUtils { new FileInputStream(sourceFile), inputEncoding)); } - + if (outputEncoding == null) { out = new BufferedWriter(new FileWriter(destFile)); } else { @@ -482,7 +485,7 @@ public class FileUtils { new FileOutputStream(destFile), outputEncoding)); } - + if (filterChainsAvailable) { ChainReaderHelper crh = new ChainReaderHelper(); crh.setBufferSize(8192); @@ -544,17 +547,15 @@ public class FileUtils { if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)) { return null; } - if (setLastModified == null) { - synchronized (lockReflection) { - if (setLastModified == null) { - try { - setLastModified = - java.io.File.class.getMethod("setLastModified", - new Class[] {Long.TYPE}); - } catch (NoSuchMethodException nse) { - throw new BuildException("File.setlastModified not in JDK > 1.1?", - nse); - } + synchronized (lockReflection) { + if (setLastModified == null) { + try { + setLastModified = + java.io.File.class.getMethod("setLastModified", + new Class[] {Long.TYPE}); + } catch (NoSuchMethodException nse) { + throw new BuildException("File.setlastModified not in JDK > 1.1?", + nse); } } } @@ -867,12 +868,16 @@ public class FileUtils { if (in1 != null) { try { in1.close(); - } catch (IOException e) {} + } catch (IOException e) { + // ignore + } } if (in2 != null) { try { in2.close(); - } catch (IOException e) {} + } catch (IOException e) { + // ignore + } } } } @@ -1034,7 +1039,7 @@ public class FileUtils { } path = path.replace('\\', '/'); - + CharacterIterator iter = new StringCharacterIterator(path); for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) { @@ -1140,10 +1145,10 @@ public class FileUtils { */ public void rename(File from, File to) throws IOException { if (to.exists() && !to.delete()) { - throw new IOException("Failed to delete " + to + throw new IOException("Failed to delete " + to + " while trying to rename " + from); } - + File parent = getParentFile(to); if (!parent.exists() && !parent.mkdirs()) { throw new IOException("Failed to create directory " + parent @@ -1153,7 +1158,7 @@ public class FileUtils { if (!from.renameTo(to)) { copyFile(from, to); if (!from.delete()) { - throw new IOException("Failed to delete " + from + throw new IOException("Failed to delete " + from + " while trying to rename it."); } }