ResourceBundle类的使用

package cn.newtouch.test;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

public class TestStringSplit {

	/** The Constant registry. */
	private static final Map<String, Map<String, String>> REGISTRY = new HashMap<String, Map<String, String>>();

	/** The separator add in mandate-135. */
	private static String separator = "¬¬";

	public static void main(String[] args) {
		String line= "5438¬¬VEH¬¬VF7BU9HD8EZ902714¬¬CITROEN TALLER¬¬CITROEN C4¬¬1CMJSUPBMK04A030M6E59JFX¬¬20131230¬¬E 3872 HVF¬¬15000¬¬20141111¬¬¬¬¬¬¬¬¬¬DMS";
		cutLine(line, registryResource("vehDto"));
	}

	public static Map<String, String> registryResource(String propertyFileName) {
		Map<String, String> properties = REGISTRY.get(propertyFileName);
		if (properties == null) {
			ResourceBundle rb = null;
			try {
				rb = ResourceBundle.getBundle(propertyFileName);
			} catch (MissingResourceException e) {
				rb = ResourceBundle.getBundle(propertyFileName.toLowerCase());
			}
			properties = new HashMap<String, String>();
			Enumeration<String> cles = rb.getKeys();
			while (cles.hasMoreElements()) {
				String cle = cles.nextElement();
				String bornes = rb.getString(cle);
				properties.put(cle, bornes);
			}
			REGISTRY.put(propertyFileName, properties);
		}
		return properties;
	}

	public static Map<String, String> cutLine(String line, Map<String, String> cutlineProperties) {
		Map<String, String> properties = new HashMap<String, String>();
		Iterator<String> cles = cutlineProperties.keySet().iterator();
		String[] lines = line.split(separator);
		int index = -1;
		while (cles.hasNext()) {
			String cle = cles.next();
			index = Integer.valueOf(cutlineProperties.get(cle));
			if (index < lines.length) {
				properties.put(cle, lines[index]);
			} else {
				properties.put(cle, null);
			}
		}
		return properties;
	}
}

 

你可能感兴趣的:(java)