ASF Bugzilla – Attachment 17385 Details for
Bug 30094
Performance enhancements using java.nio & lazy calls
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
[faulty] java.nio changes against Ant 1.6.5, in unified diff format
ant-nio.diff (text/plain), 11.46 KB, created by
Robin Verduijn
on 2006-01-11 18:52:33 UTC
(
hide
)
Description:
[faulty] java.nio changes against Ant 1.6.5, in unified diff format
Filename:
MIME Type:
Creator:
Robin Verduijn
Created:
2006-01-11 18:52:33 UTC
Size:
11.46 KB
patch
obsolete
>diff -ur apache-ant-1.6.5.orig/src/main/org/apache/tools/ant/util/FileUtils.java apache-ant-1.6.5/src/main/org/apache/tools/ant/util/FileUtils.java >--- apache-ant-1.6.5.orig/src/main/org/apache/tools/ant/util/FileUtils.java 2006-01-11 12:38:30.732749100 -0500 >+++ apache-ant-1.6.5/src/main/org/apache/tools/ant/util/FileUtils.java 2006-01-11 11:49:05.057847600 -0500 >@@ -67,7 +67,7 @@ > private static boolean onNetWare = Os.isFamily("netware"); > private static boolean onDos = Os.isFamily("dos"); > >- private static final int BUF_SIZE = 8192; >+ protected static final int BUF_SIZE = 8192; > > // for toURI > private static boolean[] isSpecial = new boolean[256]; >@@ -113,6 +113,28 @@ > * @return a new instance of FileUtils. > */ > public static FileUtils newFileUtils() { >+ String version = System.getProperty("java.version"); >+ StringTokenizer st = new StringTokenizer(version, "."); >+ boolean supportsNio = false; >+ try { >+ if (st.countTokens() > 2) { >+ int major = Integer.parseInt(st.nextToken()); >+ int minor = Integer.parseInt(st.nextToken()); >+ >+ if (major > 1 || (major == 1 && minor >= 4)) { >+ supportsNio = true; >+ try { >+ Class.forName("org.apache.tools.ant.util.NioFileUtils"); >+ return new NioFileUtils(); >+ } catch (ClassNotFoundException e1) { >+ // class not included >+ // fall back >+ } >+ } >+ } >+ } catch (NumberFormatException e) { >+ // ignore >+ } > return new FileUtils(); > } > >diff -ur apache-ant-1.6.5.orig/src/main/org/apache/tools/ant/util/NioFileUtils.java apache-ant-1.6.5/src/main/org/apache/tools/ant/util/NioFileUtils.java >--- apache-ant-1.6.5.orig/src/main/org/apache/tools/ant/util/NioFileUtils.java 2006-01-11 12:38:30.748374300 -0500 >+++ apache-ant-1.6.5/src/main/org/apache/tools/ant/util/NioFileUtils.java 2006-01-11 11:49:05.073471500 -0500 >@@ -0,0 +1,222 @@ >+/* >+ * Created on Jul 12, 2004 >+ * >+ * TODO To change the template for this generated file go to >+ * Window - Preferences - Java - Code Style - Code Templates >+ */ >+package org.apache.tools.ant.util; >+ >+import java.io.BufferedReader; >+import java.io.BufferedWriter; >+import java.io.File; >+import java.io.FileInputStream; >+import java.io.FileOutputStream; >+import java.io.FileReader; >+import java.io.FileWriter; >+import java.io.IOException; >+import java.io.InputStreamReader; >+import java.io.OutputStreamWriter; >+import java.io.Reader; >+import java.nio.channels.FileChannel; >+import java.util.Vector; >+import org.apache.tools.ant.Project; >+import org.apache.tools.ant.filters.util.ChainReaderHelper; >+import org.apache.tools.ant.types.FilterSetCollection; >+ >+/** >+ * @author jbleijen >+ * >+ * TODO To change the template for this generated type comment go to Window - >+ * Preferences - Java - Code Style - Code Templates >+ */ >+public class NioFileUtils extends FileUtils { >+ >+ /** >+ * Empty constructor. >+ */ >+ protected NioFileUtils() { >+ super(); >+ } >+ >+ /** >+ * Convenience method to copy a file from a source to a >+ * destination specifying if token filtering must be used, if >+ * filter chains must be used, if source files may overwrite >+ * newer destination files and the last modified time of >+ * <code>destFile</code> file should be made equal >+ * to the last modified time of <code>sourceFile</code>. >+ * >+ * @param sourceFile the file to copy from. >+ * Must not be <code>null</code>. >+ * @param destFile the file to copy to. >+ * Must not be <code>null</code>. >+ * @param filters the collection of filters to apply to this copy. >+ * @param filterChains filterChains to apply during the copy. >+ * @param overwrite Whether or not the destination file should be >+ * overwritten if it already exists. >+ * @param preserveLastModified Whether or not the last modified time of >+ * the resulting file should be set to that >+ * of the source file. >+ * @param inputEncoding the encoding used to read the files. >+ * @param outputEncoding the encoding used to write the files. >+ * @param project the project instance. >+ * >+ * >+ * @throws IOException if the copying fails. >+ * >+ * @since Ant 1.6 >+ */ >+ public void copyFile(File sourceFile, File destFile, >+ FilterSetCollection filters, Vector filterChains, >+ boolean overwrite, boolean preserveLastModified, >+ String inputEncoding, String outputEncoding, >+ Project project) >+ throws IOException { >+ >+ if (overwrite || !destFile.exists() >+ || destFile.lastModified() < sourceFile.lastModified()) { >+ >+ if (destFile.exists() && destFile.isFile()) { >+ destFile.delete(); >+ } >+ // ensure that parent dir of dest file exists! >+ // not using getParentFile method to stay 1.1 compat >+ File parent = destFile.getParentFile(); >+ if (parent != null && !parent.exists()) { >+ parent.mkdirs(); >+ } >+ final boolean filterSetsAvailable = (filters != null >+ && filters.hasFilters()); >+ final boolean filterChainsAvailable = (filterChains != null >+ && filterChains.size() > 0); >+ if (filterSetsAvailable) { >+ BufferedReader in = null; >+ BufferedWriter out = null; >+ try { >+ if (inputEncoding == null) { >+ in = new BufferedReader(new FileReader(sourceFile)); >+ } else { >+ InputStreamReader isr >+ = new InputStreamReader(new FileInputStream(sourceFile), >+ inputEncoding); >+ in = new BufferedReader(isr); >+ } >+ if (outputEncoding == null) { >+ out = new BufferedWriter(new FileWriter(destFile)); >+ } else { >+ OutputStreamWriter osw >+ = new OutputStreamWriter(new FileOutputStream(destFile), >+ outputEncoding); >+ out = new BufferedWriter(osw); >+ } >+ if (filterChainsAvailable) { >+ ChainReaderHelper crh = new ChainReaderHelper(); >+ crh.setBufferSize(BUF_SIZE); >+ crh.setPrimaryReader(in); >+ crh.setFilterChains(filterChains); >+ crh.setProject(project); >+ Reader rdr = crh.getAssembledReader(); >+ in = new BufferedReader(rdr); >+ } >+ LineTokenizer lineTokenizer = new LineTokenizer(); >+ lineTokenizer.setIncludeDelims(true); >+ String newline = null; >+ String line = lineTokenizer.getToken(in); >+ while (line != null) { >+ if (line.length() == 0) { >+ // this should not happen, because the lines are >+ // returned with the end of line delimiter >+ out.newLine(); >+ } else { >+ newline = filters.replaceTokens(line); >+ out.write(newline); >+ } >+ line = lineTokenizer.getToken(in); >+ } >+ } finally { >+ close(out); >+ close(in); >+ } >+ } else if (filterChainsAvailable >+ || (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)); >+ } else { >+ in = >+ new BufferedReader( >+ new InputStreamReader( >+ new FileInputStream(sourceFile), >+ inputEncoding)); >+ } >+ if (outputEncoding == null) { >+ out = new BufferedWriter(new FileWriter(destFile)); >+ } else { >+ out = >+ new BufferedWriter( >+ new OutputStreamWriter( >+ new FileOutputStream(destFile), >+ outputEncoding)); >+ } >+ if (filterChainsAvailable) { >+ ChainReaderHelper crh = new ChainReaderHelper(); >+ crh.setBufferSize(BUF_SIZE); >+ crh.setPrimaryReader(in); >+ crh.setFilterChains(filterChains); >+ crh.setProject(project); >+ Reader rdr = crh.getAssembledReader(); >+ in = new BufferedReader(rdr); >+ } >+ char[] buffer = new char[BUF_SIZE]; >+ while (true) { >+ int nRead = in.read(buffer, 0, buffer.length); >+ if (nRead == -1) { >+ break; >+ } >+ out.write(buffer, 0, nRead); >+ } >+ } finally { >+ close(out); >+ close(in); >+ } >+ } else { >+ FileInputStream in = null; >+ FileOutputStream out = null; >+ FileChannel srcChannel = null; >+ FileChannel destChannel = null; >+ >+ try { >+ // we can use direct copy with nio >+ in = new FileInputStream(sourceFile); >+ out = new FileOutputStream(destFile); >+ >+ srcChannel = in.getChannel(); >+ destChannel = out.getChannel(); >+ >+ long position = 0; >+ long count = srcChannel.size(); >+ while( position < count ) { >+ position += srcChannel.transferTo(position, count, destChannel); >+ } >+ } finally { >+ if (srcChannel != null) >+ srcChannel.close(); >+ if (destChannel != null) >+ destChannel.close(); >+ if (out != null) >+ out.close(); >+ if (in != null) >+ in.close(); >+ } >+ >+ } >+ if (preserveLastModified) { >+ setFileLastModified(destFile, sourceFile.lastModified()); >+ } >+ } >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 30094
:
12110
|
17385
|
17386
|
17388
|
17389
|
21368
|
21369