Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 33512 Details for
Bug 124209
Implement file copy with FileChannel#transferTo
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Latest Channel copy patch
nio-test.txt (text/plain), 5.53 KB, created by
John Arthorne
on 2006-01-24 10:16:25 EST
(
hide
)
Description:
Latest Channel copy patch
Filename:
MIME Type:
Creator:
John Arthorne
Created:
2006-01-24 10:16:25 EST
Size:
5.53 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.core.filesystem >Index: src/org/eclipse/core/internal/filesystem/local/LocalFile.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/LocalFile.java,v >retrieving revision 1.17 >diff -u -r1.17 LocalFile.java >--- src/org/eclipse/core/internal/filesystem/local/LocalFile.java 10 Jan 2006 15:04:25 -0000 1.17 >+++ src/org/eclipse/core/internal/filesystem/local/LocalFile.java 17 Jan 2006 21:57:04 -0000 >@@ -12,6 +12,8 @@ > > import java.io.*; > import java.net.URI; >+import java.nio.MappedByteBuffer; >+import java.nio.channels.FileChannel; > import org.eclipse.core.filesystem.*; > import org.eclipse.core.filesystem.provider.FileInfo; > import org.eclipse.core.filesystem.provider.FileStore; >@@ -29,7 +31,7 @@ > * Cached constant indicating if the current OS is Mac OSX > */ > private static final boolean MACOSX = Platform.getOS().equals(Platform.OS_MACOSX); >- >+ > /** > * The java.io.File that this store represents. > */ >@@ -55,6 +57,21 @@ > this.filePath = file.getAbsolutePath(); > } > >+ private void channelCopy(File source, File destination) throws IOException { >+ FileInputStream fin = null; >+ FileOutputStream fout = null; >+ try { >+ fin = new FileInputStream(source); >+ fout = new FileOutputStream(destination); >+ FileChannel channel = fin.getChannel(); >+ // do the file copy >+ channel.transferTo(0, channel.size(), fout.getChannel()); >+ } finally { >+ safeClose(fin); >+ safeClose(fout); >+ } >+ } >+ > /** > * This method is called after a failure to modify a file or directory. > * Check to see if the parent is read-only and if so then >@@ -78,24 +95,32 @@ > } > > public void copy(IFileStore destFile, int options, IProgressMonitor monitor) throws CoreException { >- if (destFile instanceof LocalFile) { >- File source = file; >- File destination = ((LocalFile) destFile).file; >- //handle case variants on a case-insensitive OS, or copying between >- //two equivalent files in an environment that supports symbolic links. >- //in these nothing needs to be copied (and doing so would likely lose data) >- try { >- if (source.getCanonicalFile().equals(destination.getCanonicalFile())) { >- //nothing to do >- return; >- } >- } catch (IOException e) { >- String message = NLS.bind(Messages.couldNotRead, source.getAbsolutePath()); >- Policy.error(EFS.ERROR_READ, message, e); >+ if (!(destFile instanceof LocalFile)) { >+ //fall through to super implementation >+ super.copy(destFile, options, monitor); >+ return; >+ } >+ File source = file; >+ File destination = ((LocalFile) destFile).file; >+ //handle case variants on a case-insensitive OS, or copying between >+ //two equivalent files in an environment that supports symbolic links. >+ //in these nothing needs to be copied (and doing so would likely lose data) >+ try { >+ if (source.getCanonicalFile().equals(destination.getCanonicalFile())) { >+ //nothing to do >+ return; > } >+ IFileInfo sourceInfo = fetchInfo(); >+ if (sourceInfo.isDirectory()) { >+ copyDirectory(sourceInfo, destFile, options, Policy.monitorFor(monitor)); >+ } else { >+ channelCopy(source, destination); >+ destFile.putInfo(sourceInfo, EFS.SET_ATTRIBUTES | EFS.SET_LAST_MODIFIED, null); >+ } >+ } catch (IOException e) { >+ String message = NLS.bind(Messages.couldNotRead, source.getAbsolutePath()); >+ Policy.error(EFS.ERROR_READ, message, e); > } >- //fall through to super implementation >- super.copy(destFile, options, monitor); > } > > public void delete(int options, IProgressMonitor monitor) throws CoreException { >@@ -113,7 +138,7 @@ > return false; > //Mac oddity: file.equals returns false when case is different even when > //file system is not case sensitive (Radar bug 3190672) >- LocalFile otherFile = (LocalFile)obj; >+ LocalFile otherFile = (LocalFile) obj; > if (MACOSX) > return filePath.toLowerCase().equals(otherFile.filePath.toLowerCase()); > return file.equals(otherFile.file); >@@ -143,7 +168,7 @@ > info.setAttribute(EFS.ATTRIBUTE_HIDDEN, file.isHidden()); > return info; > } >- >+ > public IFileStore getChild(IPath path) { > return new LocalFile(new File(file, path.toOSString())); > } >@@ -370,7 +395,7 @@ > if ((options & EFS.SET_LAST_MODIFIED) != 0) > file.setLastModified(info.getLastModified()); > } >- >+ > /* (non-Javadoc) > * @see org.eclipse.core.filesystem.provider.FileStore#toLocalFile(int, org.eclipse.core.runtime.IProgressMonitor) > */ >Index: src/org/eclipse/core/filesystem/provider/FileStore.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.filesystem/src/org/eclipse/core/filesystem/provider/FileStore.java,v >retrieving revision 1.19 >diff -u -r1.19 FileStore.java >--- src/org/eclipse/core/filesystem/provider/FileStore.java 5 Jan 2006 22:09:11 -0000 1.19 >+++ src/org/eclipse/core/filesystem/provider/FileStore.java 17 Jan 2006 21:57:04 -0000 >@@ -49,7 +49,7 @@ > /** > * Closes a stream and ignores any resulting exception. > */ >- private static void safeClose(InputStream in) { >+ protected static void safeClose(InputStream in) { > try { > if (in != null) > in.close(); >@@ -61,7 +61,7 @@ > /** > * Closes a stream and ignores any resulting exception. > */ >- private static void safeClose(OutputStream out) { >+ protected static void safeClose(OutputStream out) { > try { > if (out != null) > out.close();
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 124209
:
33174
|
33512
|
33513