![JAR search and dependency download from the Maven repository](/logo.png)
com.mockrunner.example.connector.Marshaller Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockrunner-jdk1.3-j2ee1.3 Show documentation
Show all versions of mockrunner-jdk1.3-j2ee1.3 Show documentation
Mockrunner is a lightweight framework for unit testing applications
in the J2EE environment. It supports servlets, filters, tag classes
and Struts actions. It includes a JDBC a JMS and a JCA test
framework and can be used to test EJB based applications.
The newest version!
package com.mockrunner.example.connector;
import java.io.UnsupportedEncodingException;
/**
* Helper class to convert Java types to commarea bytes and back.
*/
public class Marshaller
{
public static byte[] marshalString(String data, int size)
{
if(null == data) data = "";
if(data.length() > size) data = data.substring(0, size);
StringBuffer buffer = new StringBuffer(data);
for(int ii = buffer.length(); ii < size; ii++)
{
buffer.append(" ");
}
try
{
return buffer.toString().getBytes("Cp273");
}
catch (UnsupportedEncodingException exc)
{
exc.printStackTrace();
}
return new byte[size];
}
public static String unmarshalString(byte[] data)
{
try
{
return new String(data, "Cp273");
}
catch (UnsupportedEncodingException exc)
{
exc.printStackTrace();
}
return "";
}
public static byte[] marshalNumber(int number)
{
return new byte[] {(byte)((number >> 24) & 0xFF), (byte)((number >> 16) & 0xFF),
(byte)((number >> 8) & 0xFF), (byte)(number & 0xFF)};
}
public static int unmarshalNumber(byte[] data)
{
int shiftBits = (data.length - 1) * 8;
int result = 0;
for(int ii = 0; ii < data.length; ii++)
{
result |= ((0xFF & (int)data[ii]) << (shiftBits - (ii * 8)));
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy