From 002b3f7d0abe7ba96601ce712ab1e406d78f7856 Mon Sep 17 00:00:00 2001 From: David McKnight Date: Wed, 7 Nov 2007 17:21:35 +0000 Subject: [PATCH] dstore - deal with \r\n in upload(IInputStream...) same as upload(File...) --- .../dstore/files/DStoreFileService.java | 47 +++++++++++++++++-- 1 file changed, 42 insertions(+), 5 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 c60574a5cf8..e18bc84175a 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 @@ -251,6 +251,19 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer int available = bufInputStream.available(); + + // 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(); + long totalSent = 0; // upload bytes while available @@ -273,12 +286,36 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer if (!isBinary && hostEncoding != null) { String tempStr = new String(buffer, 0, bytesRead); + + // if the line end characters of the local and remote machines are different, we need to replace them + if (!localLineSep.equals(targetLineSep)) { + + 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(); + } + } - // hack for zOS - \r causes problems for compilers -// if (osName != null && (osName.startsWith("z") || osName.equalsIgnoreCase("aix"))) -// { -// tempStr = tempStr.replace('\r', ' '); -// } convBytes = tempStr.getBytes(hostEncoding);