added a method to read XML in the proper encoding.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@3902 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
kohsuke committed 2007-07-29 17:20:15 +00:00
1 parent e334c7b300
commit 82fe674184
1 file changed
+12
+12
View File
@@ -18,6 +18,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.FileReader;
import java.util.logging.Logger;
import org.xml.sax.helpers.DefaultHandler;
@@ -154,11 +155,22 @@ public final class XmlFile {
return file.toString();
}
/**
* Opens a {@link Reader} that loads XML.
* This method uses {@link #sniffEncoding() the right encoding},
* not just the system default encoding.
*/
public Reader readRaw() throws IOException {
return new InputStreamReader(new FileInputStream(file),sniffEncoding());
}
/**
* Parses the beginning of the file and determines the encoding.
*
* @throws IOException
* if failed to detect encoding.
* @return
* always non-null.
*/
public String sniffEncoding() throws IOException {
class Eureka extends SAXException {