mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-11 11:06:25 +00:00
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:
1 parent
e334c7b300
commit
82fe674184
1 file changed
+12
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user