From fb3d2aed9fded1e62820077f08cb44700c9e33a5 Mon Sep 17 00:00:00 2001 From: Kushal Munir < kmunir@ca.ibm.com> Date: Tue, 5 Jun 2007 14:06:19 +0000 Subject: [PATCH] [189352] [dnd] Copy & Paste transfers binary although text mode specified --- .../dstore/files/DStoreFileService.java | 60 ++++++++++++++++--- .../DStoreFileSubSystemConfiguration.java | 2 + 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/internal/services/dstore/files/DStoreFileService.java b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/internal/services/dstore/files/DStoreFileService.java index 91d3307a426..a10087002e9 100644 --- a/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/internal/services/dstore/files/DStoreFileService.java +++ b/rse/plugins/org.eclipse.rse.services.dstore/src/org/eclipse/rse/internal/services/dstore/files/DStoreFileService.java @@ -14,6 +14,7 @@ * Kevin Doyle (IBM) - Fix 183870 - Display File Exists Error * Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API * Xuan Chen (IBM) - [189681] [dstore][linux] Refresh Folder in My Home messes up Refresh in Root + * Kushal Munir (IBM) - [189352] Replace with appropriate line end character on upload ********************************************************************************/ package org.eclipse.rse.internal.services.dstore.files; @@ -71,6 +72,8 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer protected ISystemFileTypes _fileTypeRegistry; private String remoteEncoding; + protected boolean unixStyle = false; + private static String _percentMsg = SystemMessage.sub(SystemMessage.sub(SystemMessage.sub(ServiceResources.DStore_Service_Percent_Complete_Message, "&0", "{0}"), "&1", "{1}"), "&2", "{2}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ private static String[] _filterAttributes = { @@ -391,6 +394,18 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer int available = bufInputStream.available(); long totalSent = 0; + + // line separator of local machine + String localLineSep = System.getProperty("line.separator"); //$NON-NLS-1$ + + // line separator of remote machine + String targetLineSep = "\n"; //$NON-NLS-1$ + + if (!unixStyle) { + targetLineSep = "\r\n"; //$NON-NLS-1$ + } + + int localLineSepLength = localLineSep.length(); // upload bytes while available while (available > 0 && !isCancelled) @@ -411,12 +426,35 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer if (!isBinary && srcEncoding != null && hostEncoding != null) { String tempStr = new String(buffer, 0, bytesRead, srcEncoding); + + // if the line end characters of the local and remote machines are different, we need to replace them + if (!localLineSep.equals(targetLineSep)) { - // hack for zOS - \r causes problems for compilers -// if (osName != null && (osName.startsWith("z") || osName.equalsIgnoreCase("aix"))) -// { -// tempStr = tempStr.replace('\r', ' '); -// } + int index = tempStr.indexOf(localLineSep); + + StringBuffer buf = new StringBuffer(); + + boolean lineEndFound = false; + int lastIndex = 0; + + while (index != -1) { + buf = buf.append(tempStr.substring(lastIndex, index)); + buf = buf.append(targetLineSep); + + if (!lineEndFound) { + lineEndFound = true; + } + + lastIndex = index+localLineSepLength; + + index = tempStr.indexOf(localLineSep, lastIndex); + } + + if (lineEndFound) { + buf = buf.append(tempStr.substring(lastIndex)); + tempStr = buf.toString(); + } + } convBytes = tempStr.getBytes(hostEncoding); @@ -465,9 +503,6 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer String str = MessageFormat.format(_percentMsg, new Object[] {totalSentBuf, totalBuf, percentBuf}); monitor.subTask(str); - - - isCancelled = monitor.isCanceled(); } @@ -1347,4 +1382,13 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer DStoreOutputStream outputStream = new DStoreOutputStream(getDataStore(), remotePath, getEncoding(monitor), mode); return outputStream; } + + /** + * Sets whether this is a Unix-style file system or a Windows-style file system. The + * default is Windows if this is not called. The creator of this class should call this to set the type of the file system. + * @param isUnixStyle true if this is a Unix-style file system, false otherwise. + */ + public void setIsUnixStyle(boolean isUnixStyle) { + this.unixStyle = isUnixStyle; + } } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/DStoreFileSubSystemConfiguration.java b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/DStoreFileSubSystemConfiguration.java index 68a120b7e71..5671c6d4774 100644 --- a/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/DStoreFileSubSystemConfiguration.java +++ b/rse/plugins/org.eclipse.rse.subsystems.files.dstore/src/org/eclipse/rse/subsystems/files/dstore/DStoreFileSubSystemConfiguration.java @@ -13,6 +13,7 @@ * * Contributors: * Martin Oberhuber (Wind River) - [177523] Unify singleton getter methods + * Kushal Munir (IBM) - [189352] Set whether file service is Unix-style system or not *******************************************************************************/ package org.eclipse.rse.subsystems.files.dstore; @@ -134,6 +135,7 @@ public class DStoreFileSubSystemConfiguration extends FileServiceSubSystemConfig { DStoreConnectorService connectorService = (DStoreConnectorService)getConnectorService(host); DStoreFileService service = new DStoreFileService(connectorService, SystemFileTransferModeRegistry.getInstance(), RSEUIPlugin.getDefault()); + service.setIsUnixStyle(isUnixStyle()); IPreferenceStore store= RSEUIPlugin.getDefault().getPreferenceStore(); int downloadBufferSize = store.getInt(ISystemFilePreferencesConstants.DOWNLOAD_BUFFER_SIZE);