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

📄 resourceparser.java

📁 针对moto sdk的经典源代码
💻 JAVA
字号:
/**
 * ResourceParser.java
 *
 * Oct. 15, 2004 
 *
 * (c) Copyright. 2004. Motorola , Inc. ALL RIGHTS RESERVED.
 *  This notice does not imply publication. 
 *
 */ 

import java.util.*;
import java.io.*;

/**
 * Resource file is stored in a properties file. The sytax is qute similiar
 * to java property file. This is Parser for the property file.
 */ 
public class ResourceParser {
	
	private Hashtable props = new Hashtable();
	private InputStream stream;

	public ResourceParser (InputStream stream) {
		this.stream = stream;
	}


    private String loadConvert(String theString) {
        char aChar;
        int len = theString.length();
        StringBuffer outBuffer = new StringBuffer(len);

        for (int x=0; x<len; ) {
            aChar = theString.charAt(x++);
            if (aChar == '\\') {
                aChar = theString.charAt(x++);
                if (aChar == 'u') {
                    // Read the xxxx
                    int value=0;
		    for (int i=0; i<4; i++) {
		        aChar = theString.charAt(x++);
		        switch (aChar) {
		          case '0': case '1': case '2': case '3': case '4':
		          case '5': case '6': case '7': case '8': case '9':
		             value = (value << 4) + aChar - '0';
			     break;
			  case 'a': case 'b': case 'c':
                          case 'd': case 'e': case 'f':
			     value = (value << 4) + 10 + aChar - 'a';
			     break;
			  case 'A': case 'B': case 'C':
                          case 'D': case 'E': case 'F':
			     value = (value << 4) + 10 + aChar - 'A';
			     break;
			  default:
                              throw new IllegalArgumentException(
                                           "Malformed \\uxxxx encoding.");
                        }
                    }
                    outBuffer.append((char)value);
                } else {
                    if (aChar == 't') aChar = '\t';
                    else if (aChar == 'r') aChar = '\r';
                    else if (aChar == 'n') aChar = '\n';
                    else if (aChar == 'f') aChar = '\f';
                    outBuffer.append(aChar);
                }
            } else
                outBuffer.append(aChar);
        }
        return outBuffer.toString();
    }

	private String readLine (InputStreamReader reader) throws IOException {
		StringBuffer buf = new StringBuffer ();

		// skip preceeding space
		int character; 
		try { 
			character = reader.read ();
		} catch (EOFException eof) {
			return null;
		}

		if (character == -1)
			return null;

		while (character != -1) {
			if ((char)character == '\n')
				break;

			buf.append ((char)character);

			try {
				character = reader.read();
			} catch (EOFException eof) {
				return buf.toString ();
			}
		}

		return buf.toString();
	}

    private static final String keyValueSeparators = "=: ";
    private static final String whiteSpaceChars = " \t\r\n\f";

	public Hashtable parse () throws IOException {
		InputStreamReader reader;
                //reader  = new InputStreamReader (stream, "ISO-8859-1");
                //reader  = new InputStreamReader (stream);
                reader  = new InputStreamReader (stream, "ISO8859_1");

		String line;
		int count = 0;
		while ((line = readLine (reader)) != null) {
        	int len = line.length();
        	int keyStart;

        	for (keyStart=0; keyStart<len; keyStart++)
            	if (whiteSpaceChars.indexOf(line.charAt(keyStart)) == -1)
             		break;

        	if (keyStart == len)
            	continue;

            char firstChar = line.charAt(keyStart);
            if ((firstChar != '#') && (firstChar != '!')) {
            	// Find separation between key and value
            	int separatorIndex;
            	for (separatorIndex=keyStart; separatorIndex<len; separatorIndex++) {
            		char currentChar = line.charAt(separatorIndex);
            		if (currentChar == '\\')
            			separatorIndex++;
            		else if (keyValueSeparators.indexOf(currentChar) != -1)
            			break;
            	}

                // Skip over whitespace after key if any
            	int valueIndex;
                for (valueIndex=separatorIndex; valueIndex<len; valueIndex++)
                	if (whiteSpaceChars.indexOf(line.charAt(valueIndex)) == -1)
                		break;

                // Skip over one non whitespace key value separators if any
                if (valueIndex < len)
                	if (keyValueSeparators.indexOf(line.charAt(valueIndex)) != -1)
                		valueIndex++;

                // Skip over white space after other separators if any
                while (valueIndex < len) {
                	if (whiteSpaceChars.indexOf(line.charAt(valueIndex)) == -1)
                		break;
                	valueIndex++;
                }

                String key = line.substring(keyStart, separatorIndex);
                String value = (separatorIndex < len) ? line.substring(valueIndex, len) : "";
            	key = loadConvert(key);
            	value = loadConvert(value);

	   			props.put (key, value);
			}
		}

		stream.close();
		
		return props;
	}
}

⌨️ 快捷键说明

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