Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDejan Gloszic2006-01-30 23:14:39 +0000
committerDejan Gloszic2006-01-30 23:14:39 +0000
commit8a8a8fcc9d036d0e69d179cdb1849549ba9d7457 (patch)
tree9860fe78a5fc2a04aa621365a47997e4cd8b68fc /org.eclipse.ua.tests/base/org/eclipse/ua/tests/util
parent75567553c1ad70fdb0420cf1bbbae3341d825ccf (diff)
downloadeclipse.platform.ua-8a8a8fcc9d036d0e69d179cdb1849549ba9d7457.tar.gz
eclipse.platform.ua-8a8a8fcc9d036d0e69d179cdb1849549ba9d7457.tar.xz
eclipse.platform.ua-8a8a8fcc9d036d0e69d179cdb1849549ba9d7457.zip
*** empty log message ***v20060130
Diffstat (limited to 'org.eclipse.ua.tests/base/org/eclipse/ua/tests/util')
-rw-r--r--org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/FileUtil.java44
1 files changed, 33 insertions, 11 deletions
diff --git a/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/FileUtil.java b/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/FileUtil.java
index f0cf48862..1d3867aa4 100644
--- a/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/FileUtil.java
+++ b/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/FileUtil.java
@@ -10,24 +10,46 @@
*******************************************************************************/
package org.eclipse.ua.tests.util;
-import java.io.BufferedReader;
-import java.io.FileReader;
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStream;
+
+import org.osgi.framework.Bundle;
/*
* Utility methods for working with files.
*/
public class FileUtil {
- public static String getContents(String path) throws IOException {
- BufferedReader in = new BufferedReader(new FileReader(path));
- StringBuffer buf = new StringBuffer();
- String line = null;
- while ((line = in.readLine()) != null) {
- buf.append(line);
- buf.append("\n");
+ /**
+ * Gets the contents of the file with the given relative path in the given bundle,
+ * as a String (file must
+ * be encoded as UTF-8).
+ */
+ public static String getContents(Bundle bundle, String relativePath) throws IOException {
+ return readString(bundle.getEntry(relativePath).openStream());
+ }
+
+ /**
+ * Gets the contents of the file with the given absolute path as a String (file must
+ * be encoded as UTF-8).
+ */
+ public static String getContents(String absolutePath) throws IOException {
+ return readString(new FileInputStream(absolutePath));
+ }
+
+ /**
+ * Reads the contents of the input stream as UTF-8 and constructs and returns
+ * as a String.
+ */
+ private static String readString(InputStream in) throws IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ byte[] buffer = new byte[4096];
+ int num;
+ while ((num = in.read(buffer)) > 0) {
+ out.write(buffer, 0, num);
}
- in.close();
- return buf.toString();
+ return new String(out.toByteArray(), "UTF-8");
}
}

Back to the top