package art.servers.fleetserver.radio.sepura;
|
|
public class BinaryStreamASCII
|
{
|
private String data = null;
|
private int pointer = 0;
|
|
public BinaryStreamASCII(String data)
|
{
|
this.data = hexStringToBinaryString(data);
|
}
|
|
public long readLong (int length) throws Exception
|
{
|
if ((pointer + length) > data.length()) throw new Exception();
|
String value = data.substring(pointer, pointer + length);
|
pointer = pointer + length;
|
return Long.parseLong(value, 2);
|
}
|
|
|
public void skip (int length) throws Exception
|
{
|
if ((pointer + length) > data.length()) throw new Exception();
|
pointer = pointer + length;
|
}
|
|
|
public void reset ()
|
{
|
pointer = 0;
|
}
|
|
|
|
private static String hexStringToBinaryString(String input)
|
{
|
String result = "";
|
|
for (int i=0; i<input.length(); i++)
|
{
|
String hex = input.substring(i, i+1);
|
int decimal = Integer.valueOf(hex, 16);
|
result = result + leadingZeros(Integer.toBinaryString(decimal), 4);
|
}
|
|
return result;
|
}
|
|
|
|
|
private static String leadingZeros(String input, int length)
|
{
|
return (new String(new char[length - input.length()]).replace("\0", "0") + input);
|
}
|
|
|
}
|