Browse Source

Remove double-check pattern.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274767 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 22 years ago
parent
commit
4613fe2ba9
1 changed files with 28 additions and 23 deletions
  1. +28
    -23
      src/main/org/apache/tools/ant/util/FileUtils.java

+ 28
- 23
src/main/org/apache/tools/ant/util/FileUtils.java View File

@@ -136,6 +136,8 @@ public class FileUtils {


/** /**
* Factory method. * Factory method.
*
* @return a new instance of FileUtils.
*/ */
public static FileUtils newFileUtils() { public static FileUtils newFileUtils() {
return new FileUtils(); return new FileUtils();
@@ -144,7 +146,8 @@ public class FileUtils {
/** /**
* Empty constructor. * Empty constructor.
*/ */
protected FileUtils() {}
protected FileUtils() {
}


/** /**
* Get the URL for a file taking into account # characters * Get the URL for a file taking into account # characters
@@ -264,7 +267,7 @@ public class FileUtils {
public void copyFile(String sourceFile, String destFile, public void copyFile(String sourceFile, String destFile,
FilterSetCollection filters, Vector filterChains, FilterSetCollection filters, Vector filterChains,
boolean overwrite, boolean preserveLastModified, boolean overwrite, boolean preserveLastModified,
String inputEncoding, String outputEncoding,
String inputEncoding, String outputEncoding,
Project project) Project project)
throws IOException { throws IOException {
copyFile(new File(sourceFile), new File(destFile), filters, copyFile(new File(sourceFile), new File(destFile), filters,
@@ -456,12 +459,12 @@ public class FileUtils {
} }
} }
} else if (filterChainsAvailable } else if (filterChainsAvailable
|| (inputEncoding != null
|| (inputEncoding != null
&& !inputEncoding.equals(outputEncoding)) && !inputEncoding.equals(outputEncoding))
|| (inputEncoding == null && outputEncoding != null)) { || (inputEncoding == null && outputEncoding != null)) {
BufferedReader in = null; BufferedReader in = null;
BufferedWriter out = null; BufferedWriter out = null;
try { try {
if (inputEncoding == null) { if (inputEncoding == null) {
in = new BufferedReader(new FileReader(sourceFile)); in = new BufferedReader(new FileReader(sourceFile));
@@ -472,7 +475,7 @@ public class FileUtils {
new FileInputStream(sourceFile), new FileInputStream(sourceFile),
inputEncoding)); inputEncoding));
} }
if (outputEncoding == null) { if (outputEncoding == null) {
out = new BufferedWriter(new FileWriter(destFile)); out = new BufferedWriter(new FileWriter(destFile));
} else { } else {
@@ -482,7 +485,7 @@ public class FileUtils {
new FileOutputStream(destFile), new FileOutputStream(destFile),
outputEncoding)); outputEncoding));
} }
if (filterChainsAvailable) { if (filterChainsAvailable) {
ChainReaderHelper crh = new ChainReaderHelper(); ChainReaderHelper crh = new ChainReaderHelper();
crh.setBufferSize(8192); crh.setBufferSize(8192);
@@ -544,17 +547,15 @@ public class FileUtils {
if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)) { if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)) {
return null; 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) { if (in1 != null) {
try { try {
in1.close(); in1.close();
} catch (IOException e) {}
} catch (IOException e) {
// ignore
}
} }
if (in2 != null) { if (in2 != null) {
try { try {
in2.close(); in2.close();
} catch (IOException e) {}
} catch (IOException e) {
// ignore
}
} }
} }
} }
@@ -1034,7 +1039,7 @@ public class FileUtils {
} }


path = path.replace('\\', '/'); path = path.replace('\\', '/');
CharacterIterator iter = new StringCharacterIterator(path); CharacterIterator iter = new StringCharacterIterator(path);
for (char c = iter.first(); c != CharacterIterator.DONE; for (char c = iter.first(); c != CharacterIterator.DONE;
c = iter.next()) { c = iter.next()) {
@@ -1140,10 +1145,10 @@ public class FileUtils {
*/ */
public void rename(File from, File to) throws IOException { public void rename(File from, File to) throws IOException {
if (to.exists() && !to.delete()) { if (to.exists() && !to.delete()) {
throw new IOException("Failed to delete " + to
throw new IOException("Failed to delete " + to
+ " while trying to rename " + from); + " while trying to rename " + from);
} }
File parent = getParentFile(to); File parent = getParentFile(to);
if (!parent.exists() && !parent.mkdirs()) { if (!parent.exists() && !parent.mkdirs()) {
throw new IOException("Failed to create directory " + parent throw new IOException("Failed to create directory " + parent
@@ -1153,7 +1158,7 @@ public class FileUtils {
if (!from.renameTo(to)) { if (!from.renameTo(to)) {
copyFile(from, to); copyFile(from, to);
if (!from.delete()) { if (!from.delete()) {
throw new IOException("Failed to delete " + from
throw new IOException("Failed to delete " + from
+ " while trying to rename it."); + " while trying to rename it.");
} }
} }


Loading…
Cancel
Save