ami
Class AMIUtil

java.lang.Object
  |
  +--ami.AMIUtil

public class AMIUtil
extends Object

Convenient methods for AMI engine

Version:
1.0
Author:
Bertrand Florat

Field Summary
(package private) static long MAX
          Get an AMIPacket and return a byte array ready to be sent
 
Constructor Summary
AMIUtil()
           
 
Method Summary
static AMIPublicKey amiping(String sIP)
          Used to get the pu corresponding to an IP, Basicaly, sends an AMIping at given address and wait for answer
(package private) static byte[] bfDecode(byte[] bIn)
          Used to factorise blowfish code utilation in: byte array to decode out: decoded byte array
(package private) static byte[] bfEncode(byte[] bIn)
          Used to factorise blowfish code utilation in: byte array to encode out: encoded byte array We can't work with lines because a encoded string can contain an '\n'.
static boolean check(AMIPublicKey apk, String sIP)
          Used to check if a given pu matchs a given ip, the real check is done only if the RT entry is no more trusted ( DLC too old )
static boolean checkIPAddress(String sIPAddress)
          Check an IP address under format ip:port , no port completion
static boolean checkIPAddress(String sIPAddress, boolean bPortCompletion)
          Check an IP address under format ip:port
static String closeTag(String sTag)
          Add closing brackets for a string
static void commitAIS(String sAIS)
          Write an AIS to in.xml file
static String completeIPAddress(String sIPAddress)
          Returns completed IP address under format ip:port Assumes that given IP is correct ( ip or ip:port )
(package private) static void decodeFile(File fIn)
          Used to decode a file with extention "amis" to a clear file with extention "ami"
static boolean forcedCheck(AMIPublicKey apk, String sIP)
          Used to check if a given pu matchs a given ip, the real check is always done
(package private) static String getRandomID()
          Return a random ID on 32 bits in radix specified as AMILocalParameter.RADIX_REPRESENTATION
static String getRandomID4()
           
static String openTag(String sTag)
          Add opening brackets for a string
(package private) static void parseXML(char[] cRawData, org.xml.sax.helpers.DefaultHandler dh, boolean bValidating, String sSystemID)
          This is a generic method to parse a XML file using SAX and using the given Handler.
(package private) static void parseXML(String sFileName, org.xml.sax.helpers.DefaultHandler dh, boolean bValidating)
          This is a generic method to parse a XML file using SAX and using the given Handler.
(package private) static long secondsSince(long lDate)
          Return nb seconds since the given date ( lDate is in sec )
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

MAX

static final long MAX
Get an AMIPacket and return a byte array ready to be sent
Constructor Detail

AMIUtil

public AMIUtil()
Method Detail

secondsSince

static long secondsSince(long lDate)
Return nb seconds since the given date ( lDate is in sec )

parseXML

static void parseXML(String sFileName,
                     org.xml.sax.helpers.DefaultHandler dh,
                     boolean bValidating)
              throws Exception
This is a generic method to parse a XML file using SAX and using the given Handler. Read a file

parseXML

static void parseXML(char[] cRawData,
                     org.xml.sax.helpers.DefaultHandler dh,
                     boolean bValidating,
                     String sSystemID)
              throws Exception
This is a generic method to parse a XML file using SAX and using the given Handler. Read an character input stream
Parameters:
cRawData - Raw data to process
dh - class used as handler ( tells what to do with incomming data )
bValidating - true if the xml stream is validated by a DTD
sSystemID - used to tell where is the DTD ( the tag in the XML stream is not enough to locate the absolute path ), is ignored if bValidating = false

getRandomID

static String getRandomID()
Return a random ID on 32 bits in radix specified as AMILocalParameter.RADIX_REPRESENTATION

getRandomID4

public static String getRandomID4()

commitAIS

public static void commitAIS(String sAIS)
                      throws AMIException
Write an AIS to in.xml file
Parameters:
String - sAIS the AIS as a string

amiping

public static AMIPublicKey amiping(String sIP)
                            throws AMIException
Used to get the pu corresponding to an IP, Basicaly, sends an AMIping at given address and wait for answer

check

public static boolean check(AMIPublicKey apk,
                            String sIP)
                     throws AMIException
Used to check if a given pu matchs a given ip, the real check is done only if the RT entry is no more trusted ( DLC too old )
Returns:
true if info is right

forcedCheck

public static boolean forcedCheck(AMIPublicKey apk,
                                  String sIP)
Used to check if a given pu matchs a given ip, the real check is always done
Returns:
true if info is right

bfEncode

static byte[] bfEncode(byte[] bIn)
                throws AMIException
Used to factorise blowfish code utilation in: byte array to encode out: encoded byte array We can't work with lines because a encoded string can contain an '\n'.

bfDecode

static byte[] bfDecode(byte[] bIn)
                throws AMIException
Used to factorise blowfish code utilation in: byte array to decode out: decoded byte array

decodeFile

static void decodeFile(File fIn)
                throws AMIException
Used to decode a file with extention "amis" to a clear file with extention "ami"

openTag

public static String openTag(String sTag)
Add opening brackets for a string

closeTag

public static String closeTag(String sTag)
Add closing brackets for a string

checkIPAddress

public static boolean checkIPAddress(String sIPAddress,
                                     boolean bPortCompletion)
Check an IP address under format ip:port
Parameters:
String - sIPAddress the ip address to be checked
boolean - bCheckPort. If true, check also port
Returns:
boolean true if test passed

checkIPAddress

public static boolean checkIPAddress(String sIPAddress)
Check an IP address under format ip:port , no port completion
Parameters:
String - sIPAddress the ip address to be checked
Returns:
boolean true if test passed

completeIPAddress

public static String completeIPAddress(String sIPAddress)
Returns completed IP address under format ip:port

Assumes that given IP is correct ( ip or ip:port )

Parameters:
String - sIPAddress the ip address to be completed
Returns:
String completed ip address