1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-15 04:55:22 +02:00

[246857] Rename problem when a file is opened in the editor

This commit is contained in:
David McKnight 2008-12-05 17:03:45 +00:00
parent edc9dd3c24
commit 1da881df93

View file

@ -11,6 +11,7 @@
* Contributors: * Contributors:
* David McKnight (IBM) -[209704] [api][dstore] Ability to override default encoding conversion needed. * David McKnight (IBM) -[209704] [api][dstore] Ability to override default encoding conversion needed.
* David McKnight (IBM) -[220379] [api] Provide a means for contributing custom BIDI encodings * David McKnight (IBM) -[220379] [api] Provide a means for contributing custom BIDI encodings
* David McKnight (IBM) -[246857] Rename problem when a file is opened in the editor
********************************************************************************/ ********************************************************************************/
package org.eclipse.rse.services.files; package org.eclipse.rse.services.files;
@ -18,6 +19,7 @@ import java.io.BufferedInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
/** /**
* @since 3.0 * @since 3.0
@ -39,27 +41,40 @@ public class DefaultFileServiceCodePageConverter implements
public void convertFileFromRemoteEncoding(String remotePath, File file, String remoteEncoding, public void convertFileFromRemoteEncoding(String remotePath, File file, String remoteEncoding,
String localEncoding, IFileService fs) { String localEncoding, IFileService fs) {
FileInputStream inputStream = null;
FileOutputStream outStream = null;
// read in the file // read in the file
try try
{ {
int fileLength = (int)file.length(); int fileLength = (int)file.length();
FileInputStream inputStream = new FileInputStream(file); if (fileLength > 0){
BufferedInputStream bufInputStream = new BufferedInputStream(inputStream, fileLength); inputStream = new FileInputStream(file);
byte[] buffer = new byte[fileLength]; BufferedInputStream bufInputStream = new BufferedInputStream(inputStream, fileLength);
int bytesRead = bufInputStream.read(buffer, 0, fileLength); byte[] buffer = new byte[fileLength];
bufInputStream.close(); int bytesRead = bufInputStream.read(buffer, 0, fileLength);
inputStream.close(); bufInputStream.close();
inputStream.close();
byte[] localBuffer = new String(buffer, 0, bytesRead, remoteEncoding).getBytes(localEncoding);
byte[] localBuffer = new String(buffer, 0, bytesRead, remoteEncoding).getBytes(localEncoding);
FileOutputStream outStream = new FileOutputStream(file);
outStream.write(localBuffer, 0, localBuffer.length); outStream = new FileOutputStream(file);
outStream.close(); outStream.write(localBuffer, 0, localBuffer.length);
outStream.close();
}
} }
catch (Exception e) catch (Exception e)
{ {
try {
if (inputStream != null){
inputStream.close();
}
if (outStream != null){
outStream.close();
}
}
catch (IOException ioe){
}
} }
} }