All pastes #987311 Raw Edit

Anonymous

public text v1 · immutable
·published 2008-04-16 12:58 UTC
rendered paste body
### Eclipse Workspace Patch 1.0
#P org.eclipse.team.cvs.core
Index: src/org/eclipse/team/internal/ccvs/core/util/SyncFileWriter.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/SyncFileWriter.java,v
retrieving revision 1.69
diff -u -r1.69 SyncFileWriter.java
--- src/org/eclipse/team/internal/ccvs/core/util/SyncFileWriter.java	1 Aug 2007 14:17:40 -0000	1.69
+++ src/org/eclipse/team/internal/ccvs/core/util/SyncFileWriter.java	16 Apr 2008 12:58:32 -0000
@@ -545,7 +545,13 @@
 		try {
 			InputStream in = getInputStream(file);
 			if (in != null) {
-				BufferedReader reader = new BufferedReader(new InputStreamReader(in), 512);
+                InputStreamReader isr;
+                try {
+                   isr = new InputStreamReader(in, file.getCharset());
+                } catch(UnsupportedEncodingException ex) {
+                   isr = new InputStreamReader(in);
+                }
+				BufferedReader reader = new BufferedReader(isr, 512);
 				List fileContentStore = new ArrayList();
 				try {
 					String line;
@@ -584,7 +590,7 @@
 				public void run(IProgressMonitor monitor) throws CoreException {
 					try {
 						ByteArrayOutputStream os = new ByteArrayOutputStream();
-						writeLinesToStreamAndClose(os, contents);
+						writeLinesToStreamAndClose(os, contents, file.getCharset());
 						if(!file.exists()) {
 							file.create(new ByteArrayInputStream(os.toByteArray()), IResource.FORCE /*don't keep history but do force*/, null);
 						} else {
@@ -601,12 +607,16 @@
 		}
 	}
 	
-	private static void writeLinesToStreamAndClose(OutputStream os, String[] contents) throws CVSException {
+	private static void writeLinesToStreamAndClose(OutputStream os, String[] contents, String charset) throws CVSException {
 		byte[] lineEnd = getLineDelimiter();
 		try {
 			try {
 				for (int i = 0; i < contents.length; i++) {
-					os.write(contents[i].getBytes());
+                    try {
+					  os.write(contents[i].getBytes(charset));
+                    } catch(UnsupportedEncodingException ex) {
+                      os.write(contents[i].getBytes());
+                    }
 					os.write(lineEnd);
 				}
 			} finally {