Author: scabanovich
Date: 2011-04-20 16:20:40 -0400 (Wed, 20 Apr 2011)
New Revision: 30683
Modified:
branches/jbosstools-3.2.x/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/FileUtil.java
Log:
JBIDE-8639
https://issues.jboss.org/browse/JBIDE-8639
Modified:
branches/jbosstools-3.2.x/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/FileUtil.java
===================================================================
---
branches/jbosstools-3.2.x/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/FileUtil.java 2011-04-20
20:17:31 UTC (rev 30682)
+++
branches/jbosstools-3.2.x/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/FileUtil.java 2011-04-20
20:20:40 UTC (rev 30683)
@@ -195,8 +195,12 @@
String content = null;
InputStream in = null;
try {
+ String charset = file.getCharset();
+ if(charset != null) {
+ charset = validateEncoding(charset, null);
+ }
in = file.getContents();
- content = FileUtil.readStream(in);
+ content = (charset == null) ? readStream(in) : readStream(in, charset);
} finally {
if(in!=null) {
try {
@@ -209,6 +213,22 @@
return content;
}
+ public static String readStream(InputStream is, String charset) {
+ StringBuffer sb = new StringBuffer(""); //$NON-NLS-1$
+ try {
+ byte[] b = new byte[4096];
+ while(true) {
+ int l = is.read(b, 0, b.length);
+ if(l < 0) break;
+ sb.append(new String(b, 0, l, charset));
+ }
+ is.close();
+ } catch (IOException e) {
+ CommonPlugin.getPluginLog().logError(e);
+ }
+ return sb.toString();
+ }
+
public static void copyContent(IFile from, IFile to, boolean force, boolean
keepHistory, IProgressMonitor monitor) throws CoreException {
InputStream is = null;
try {