1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-15 13:05: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,12 +41,14 @@ 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){
inputStream = new FileInputStream(file);
BufferedInputStream bufInputStream = new BufferedInputStream(inputStream, fileLength); BufferedInputStream bufInputStream = new BufferedInputStream(inputStream, fileLength);
byte[] buffer = new byte[fileLength]; byte[] buffer = new byte[fileLength];
int bytesRead = bufInputStream.read(buffer, 0, fileLength); int bytesRead = bufInputStream.read(buffer, 0, fileLength);
@ -53,12 +57,23 @@ public class DefaultFileServiceCodePageConverter implements
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 = new FileOutputStream(file);
outStream.write(localBuffer, 0, localBuffer.length); outStream.write(localBuffer, 0, localBuffer.length);
outStream.close(); outStream.close();
} }
}
catch (Exception e) catch (Exception e)
{ {
try {
if (inputStream != null){
inputStream.close();
}
if (outStream != null){
outStream.close();
}
}
catch (IOException ioe){
}
} }
} }