package thundernet.afp;

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*  AFP.java                           Copyright (c) ThunderNet Productions  */
/*                                     2001.  All rights reserved.           */
/*                                                                           */
/*  The AFP "header" file.  Defines the AFP execution environment and        */
/*      configuration.  Provides static constants, etc.                      */
/*                                                                           */
/*  Public Methods:                                                          */
/*      -- none --                                                           */
/*                                                                           */
/*  Date      Who  Comment                                                   */
/*  -----------------------------------------------------------------------  */
/*  24mar01   acp  initial creation                                          */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */



public class AFP
{

    //
    // configuration properties
    //
    public static final String  PROP_AFP_SERVER_HOST    = "afp.server.host";
    public static final String  PROP_AFP_SERVER_PORT    = "afp.server.port";
    public static final String  PROP_AFP_LISTENER_PORT  = "afp.listener.port";
    public static final String  PROP_SENDER_ID          = "afp.sender.id";



/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*  AFP()                                                                    */
/*                                                                           */
/*  Description:  default constructor.  This method is made privete so that  */
/*      this class cannot be instantiated.  This class contains only static  */
/*      methods and has no reason ever to be instantiated.                   */
/*                                                                           */
/*  Parameters:                                                              */
/*      none                                                                 */
/*                                                                           */
/*  Return:                                                                  */
/*      n/a                                                                  */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
private void AFP()
{


}   /* end of method AFP() */



/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*  byteArray2Int()                                                          */
/*                                                                           */
/*  Description:  simple utility routine for converting a 4-byte array into  */
/*      a corresponding integer.  Uses whichever -endian format directed     */
/*      by the caller.                                                       */
/*                                                                           */
/*  Parameters:                                                              */
/*      argBytes            the array to convert                             */
/*      argOffset           point in the array where the Int starts          */
/*      argEndian           0 = little endian 78 56 34 12 -> 305,419,896     */
/*                          1 = big endian    12 34 56 78 -> 305,419,896     */
/*                                                                           */
/*  Return:                                                                  */
/*      int                 converted integer                                */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
public static int byteArray2Int(byte[] argBytes, int argOffset, int argEndian)
{

    int result = 0;

    if (argEndian == 1)
    {
        //
        // big-endian conversion
        //
        for (int i = 0, j = 0; i < 4; i++, j++)
        {
            result = result + (((int)argBytes[i + argOffset] << 24) >>> (j * 8));
        }
    }
    else
    {
        //
        // little-endian conversion
        //
        for (int i = 3, j = 0; i >= 0; i--, j++)
        {
            result = result + (((int)argBytes[i + argOffset] << 24) >>> (j * 8));
        }
    }

    return result;

}   /* end of method byteArray2Int() */



/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*  int2ByteArray()                                                          */
/*                                                                           */
/*  Description:  simple utility routine for converting an integer value to  */
/*      a corresponding 4-byte array.  Uses whichever -endian format directed*/
/*      by the caller.                                                       */
/*                                                                           */
/*  Parameters:                                                              */
/*      argInt              the number to convert                            */
/*      argEndian           0 = little endian 305,419,896 -> 78 56 34 12     */
/*                          1 = big endian    305,419,896 -> 12 34 56 78     */
/*                                                                           */
/*  Return:                                                                  */
/*      byte[]              converted 4-byte array                           */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
public static byte[] int2ByteArray(int argInt, int argEndian)
{

    byte[]  result = new byte[4];

    if (argEndian == 1)
    {
        //
        // big-endian conversion
        //
        for (int i = 0, j = 3; i < 4; i++, j--)
        {
            result[i] = (byte)((argInt >>> (j * 8)) & (byte)0xFF);
        }
    }
    else
    {
        //
        // little-endian conversion
        //
        for (int i = 3, j = 3; i >= 0; i--, j--)
        {
            result[i] = (byte)((argInt >>> (j * 8)) & (byte)0xFF);
        }
    }

    return result;

}   /* end of method int2ByteArray() */



}   /* end of class AFP */


  Copyright © Thundernet Development Group Inc., 2003.
All rights reserved.