VLab Common 1.2

pl.psnc.vlab.remote.util
Class BytesConversion

java.lang.Object
  extended by pl.psnc.vlab.remote.util.BytesConversion

public class BytesConversion
extends java.lang.Object

BytesConversion class - helper class is used to decode or encode the data which is sent between the application and the VLab System

Author:
Dominik Stoklosa (~osa~)
Email address
osa@man.poznan.pl

Field Summary
protected static int INT_SIZE
          The size (in bytes) of the integer variable
 
Constructor Summary
BytesConversion()
           
 
Method Summary
 SessionValue convertToSessionValue(pl.psnc.vlab.remote.Dgram datagramOut)
          Converts a stream of bytes to the SessionValue object.
 byte[] encodeShortMessage(ShortMessageValue shortMsg)
          Encodes the ShortMessage struct into array of bytes: struct shortMessage { char buffer[256]; int len; };
 ShortMessageValue getShortMessage(byte[] binaryData, java.nio.ByteOrder byteOrder)
          Decodes the ShortMessage struct: struct shortMessage { char buffer[256]; int len; };
 java.lang.String getString(byte[] binaryData)
          Decodes an array of byte to the string.
 boolean isSessionValidAnswer(pl.psnc.vlab.remote.Dgram datagramOut)
          Converts a stream of bytes to boolean type struct isAppSessionValidAnswer { int isValid; //boolean is valid (0/1) };
 byte[] toBytes(java.lang.String value, int size)
          Converts a string value into fixed size byte array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INT_SIZE

protected static int INT_SIZE
The size (in bytes) of the integer variable

Constructor Detail

BytesConversion

public BytesConversion()
Method Detail

convertToSessionValue

public SessionValue convertToSessionValue(pl.psnc.vlab.remote.Dgram datagramOut)
                                   throws VlabException
Converts a stream of bytes to the SessionValue object. The given stream of bytes should represents the following c++ structure : struct getAppSessionByKeyAnswer { unsigned int appsId; //session id (4 bytes) char apps_key[35]; //session key char apps_lang[10]; //session language char apps_country[10]; //session country double apps_timestamp; //session timestamp int apps_timelimit; //session timelimit unsigned int userId; //session owner's id char userCertId[150]; //session owner's id unsigned int labId; //session owner's lab char login[35]; //session owner's login name };

Parameters:
datagramOut -
Returns:
session value object
Throws:
VlabException

isSessionValidAnswer

public boolean isSessionValidAnswer(pl.psnc.vlab.remote.Dgram datagramOut)
                             throws VlabException
Converts a stream of bytes to boolean type struct isAppSessionValidAnswer { int isValid; //boolean is valid (0/1) };

Parameters:
datagramOut -
Returns:
true session is valid false otherwise
Throws:
VlabException

toBytes

public byte[] toBytes(java.lang.String value,
                      int size)
Converts a string value into fixed size byte array. The UTF-8 encoding is used.

Parameters:
value - string value to be converted
size - the length of the result array
Returns:
array of bytes, which represent the given string value

encodeShortMessage

public byte[] encodeShortMessage(ShortMessageValue shortMsg)
Encodes the ShortMessage struct into array of bytes: struct shortMessage { char buffer[256]; int len; };

Parameters:
shortMsg -
Returns:
an object representation of thie shortMessage stucture

getShortMessage

public ShortMessageValue getShortMessage(byte[] binaryData,
                                         java.nio.ByteOrder byteOrder)
Decodes the ShortMessage struct: struct shortMessage { char buffer[256]; int len; };

Parameters:
binaryData - byte array, which represents the VLab shortMessage structure (The structure was presented in the method description)
Returns:
an object representation of thie shortMessage stucture

getString

public java.lang.String getString(byte[] binaryData)
Decodes an array of byte to the string. It reads the byte array until 0 byte is found or the array ends. The UTF-8 encoding is used.

Parameters:
binaryData - encoded string as an byte array
Returns:
the string value represented by this array.

VLab Common 1.2

Copyright 2004 by VLAB Dominik Stoklosa.