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

com.altova.HexBinary Maven / Gradle / Ivy

There is a newer version: 2.0.4
Show newest version
/**
 * HexBinary.java
 *
 * This file was generated by MapForce 2017sp2.
 *
 * YOU SHOULD NOT MODIFY THIS FILE, BECAUSE IT WILL BE
 * OVERWRITTEN WHEN YOU RE-RUN CODE GENERATION.
 *
 * Refer to the MapForce Documentation for further details.
 * http://www.altova.com/mapforce
 */

package com.altova;

public class HexBinary 
{
	private static String sEncodingTable = "0123456789ABCDEF";
	private static byte[] aDecodingTable =
	{
		-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,
		-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,
		-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,
		 0,	 1,	 2,	 3,	 4,	 5,	 6,	 7,	 8,	 9,	-1,	-1,	-1,	-1,	-1,	-1,
		-1,	10,	11,	12,	13,	14,	15,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,
		-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,
		-1,	10,	11,	12,	13,	14,	15,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,
		-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,
		-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,
		-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,
		-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,
		-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,
		-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,
		-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,
		-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,
		-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1
	};
	
	public static String encode( byte[] v) 
	{
		String result = "";	
		for(int i=0; i> 4) & 15);
			result += sEncodingTable.charAt(v[i] & 15);
		}
		return result;
	}

	public static byte[] decode( String s)
	{
		if( s == null ) return null;
		String newvalue = s.trim();
		if( newvalue.length() == 0 ) return new byte[0];

		char[] cSrc = newvalue.toCharArray();
		byte[] value = new byte[ cSrc.length >> 1 ];
		int nSrcIndex = 0;
		int nTarIndex = 0;
		while( nSrcIndex < cSrc.length )
		{
			byte c = aDecodingTable[ cSrc[ nSrcIndex++ ] ];
			if( c != -1 )
			{
				value[ nTarIndex >> 1 ] |= (byte)( (nTarIndex & 1) == 1 ? c : (c << 4) );
				nTarIndex++;
			}
			else
				throw new IllegalArgumentException("'" + newvalue + "' could not be parsed as hexBinary.");
		}
		return value;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy