All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bitbucket.openisoj.HashtableMessage Maven / Gradle / Ivy

Go to download

An extensible framework for creating ISO 8583 messages. Ported from OpenIso.Net http://code.google.com/p/openiso8583net/

There is a newer version: 1.1.4
Show newest version
package org.bitbucket.openisoj;

import java.util.LinkedHashMap;
import java.util.Map.Entry;

public class HashtableMessage extends LinkedHashMap {
	private static final long serialVersionUID = -6291908065706959931L;

	/**
	 * Parses the string into the hashtable
	 * 
	 * @param message
	 */
	public void fromMessageString(String message) {
		int offset = 0;

		if (message == null)
			return;

		while (offset < message.length()) {
			int keyLengthIndicator = Integer.parseInt(message.substring(offset, offset + 1));
			offset++;
			int keyLength = Integer.parseInt(message.substring(offset, offset + keyLengthIndicator));
			offset += keyLengthIndicator;
			String key = message.substring(offset, offset + keyLength);
			offset += keyLength;

			int valueLengthIndicator = Integer.parseInt(message.substring(offset, offset + 1));
			offset++;
			int valueLength = Integer.parseInt(message.substring(offset, offset + valueLengthIndicator));
			offset += valueLengthIndicator;
			String value = message.substring(offset, offset + valueLength);
			offset += valueLength;

			put(key, value);
		}
	}

	public String toMessageString() {
		StringBuilder sb = new StringBuilder();
		for (Entry entry : this.entrySet()) {
			String value = entry.getValue();
			int keyLength = entry.getKey().length();
			int keyLengthIndicator = ("" + keyLength).length();
			sb.append(keyLengthIndicator);
			sb.append(keyLength);
			sb.append(entry.getKey());

			int valueLength = value.length();
			int valueLengthIndicator = ("" + valueLength).length();
			sb.append(valueLengthIndicator);
			sb.append(valueLength);
			sb.append(value);

		}
		return sb.toString();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy