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 33513 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), 8.56 KB, created by
John Arthorne
on 2006-01-24 10:19:01 EST
(
hide
)
Description:
Latest Channel copy patch
Filename:
MIME Type:
Creator:
John Arthorne
Created:
2006-01-24 10:19:01 EST
Size:
8.56 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 24 Jan 2006 15:19:57 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005 IBM Corporation and others. >+ * Copyright (c) 2005, 2006 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -12,6 +12,7 @@ > > import java.io.*; > import java.net.URI; >+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 +30,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 +56,22 @@ > this.filePath = file.getAbsolutePath(); > } > >+ private void channelCopy(File source, File destination) throws IOException { >+ FileInputStream in = null; >+ FileOutputStream out = null; >+ try { >+ in = new FileInputStream(source); >+ out = new FileOutputStream(destination); >+ FileChannel channel= in.getChannel(); >+ // do the file copy >+ channel.transferTo(0, channel.size(), out.getChannel()); >+ } finally { >+ //closing the streams will automatically close the channels >+ Policy.safeClose(in); >+ Policy.safeClose(out); >+ } >+ } >+ > /** > * 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/internal/filesystem/Policy.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/Policy.java,v >retrieving revision 1.2 >diff -u -r1.2 Policy.java >--- src/org/eclipse/core/internal/filesystem/Policy.java 3 Oct 2005 21:28:02 -0000 1.2 >+++ src/org/eclipse/core/internal/filesystem/Policy.java 24 Jan 2006 15:19:57 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2005 IBM Corporation and others. >+ * Copyright (c) 2000, 2006 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -10,6 +10,7 @@ > *******************************************************************************/ > package org.eclipse.core.internal.filesystem; > >+import java.io.*; > import java.util.Date; > import org.eclipse.core.runtime.*; > import org.osgi.framework.Bundle; >@@ -74,6 +75,30 @@ > return monitor == null ? new NullProgressMonitor() : monitor; > } > >+ /** >+ * Closes a stream and ignores any resulting exception. >+ */ >+ public static void safeClose(InputStream in) { >+ try { >+ if (in != null) >+ in.close(); >+ } catch (IOException e) { >+ //ignore >+ } >+ } >+ >+ /** >+ * Closes a stream and ignores any resulting exception. >+ */ >+ public static void safeClose(OutputStream out) { >+ try { >+ if (out != null) >+ out.close(); >+ } catch (IOException e) { >+ //ignore >+ } >+ } >+ > public static IProgressMonitor subMonitorFor(IProgressMonitor monitor, int ticks) { > if (monitor == null) > return new NullProgressMonitor(); >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 24 Jan 2006 15:19:57 -0000 >@@ -47,30 +47,6 @@ > protected static final String[] EMPTY_STRING_ARRAY = new String[0]; > > /** >- * Closes a stream and ignores any resulting exception. >- */ >- private static void safeClose(InputStream in) { >- try { >- if (in != null) >- in.close(); >- } catch (IOException e) { >- //ignore >- } >- } >- >- /** >- * Closes a stream and ignores any resulting exception. >- */ >- private static void safeClose(OutputStream out) { >- try { >- if (out != null) >- out.close(); >- } catch (IOException e) { >- //ignore >- } >- } >- >- /** > * Transfers the contents of an input stream to an output stream, using a large > * buffer. > * >@@ -112,8 +88,8 @@ > } > } > } finally { >- safeClose(source); >- safeClose(destination); >+ Policy.safeClose(source); >+ Policy.safeClose(destination); > } > } > >@@ -241,8 +217,8 @@ > transferStreams(in, out, sourcePath, monitor); > transferAttributes(sourceInfo, destination); > } catch (CoreException e) { >- safeClose(in); >- safeClose(out); >+ Policy.safeClose(in); >+ Policy.safeClose(out); > //if we failed to write, try to cleanup the half written file > if (!destination.fetchInfo(0, null).exists()) > destination.delete(EFS.NONE, null);
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