⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ixmlreader.java

📁 java如何解析xml
💻 JAVA
字号:
import java.io.*;

class XMLReader extends Reader{
	private final static String ASCII="ASCII";
	private final static String UTF16B="UTF-16BE";
	private final static String UTF16L="UTF-16BE";
	private final static String UTF8="UTF-8";
	
	StringReader input;
	String encoding=null;
	
	StringBuffer buffer=new StringBuffer();
	boolean lastWasD=false;
	int bufpos=0;
	
	XMLReader(StringReader is){
		input=is;
	}
	XMLReader(StringReader is,String enc)throws UnsupportedEncodingException{
		input=is;
		setEncoding(enc);//???
	}
	public void setEncoding(String enc)throws UnsupportedEncodingException{
		enc=enc.intern();
		/*Returns a canonical representation for the string object. 
          A pool of strings, initially empty, is maintained privately by the class String. 
          When the intern method is invoked, if the pool already contains a string equal to 
          this String object as determined by the equals(Object) method, then the string 
          from the pool is returned. Otherwise, this String object is added to the pool and
          a reference to this String object is returned. 
          It follows that for any two strings s and t, s.intern() == t.intern() is true 
          if and only if s.equals(t) is true. 
          All literal strings and string-valued constant expressions are interned. 
          String literals are defined in §3.10.5 of the Java Language Specification 
         */
         if(enc==null){
         	throw new UnsupportedEncodingException();
         }
         if (enc == "UTF-16") {
            enc = UTF16B;
        }
        if (enc != ASCII && enc != UTF16B && enc != UTF16L && enc != UTF8) {
            throw new UnsupportedEncodingException();
        }
        encoding = enc;
    }
    public String getEncoding(){
    	return encoding;
    }
    public void push(String s){
    	buffer.insert(bufpos,s);
    }
    public void push(char c){
    	buffer.insert(bufpos,c);
    }
    
    public int read()throws IOException{
    	int i=underlyingRead();
    	
    	
    
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -