org.tranche.server.logs
Class LogUtil

java.lang.Object
  extended by org.tranche.server.logs.LogUtil

public class LogUtil
extends java.lang.Object

Utility class for server logging mechanisms.

Author:
Bryan E. Smith - bryanesmith@gmail.com

Constructor Summary
LogUtil()
           
 
Method Summary
static long convertBytesToLong(byte[] longVal)
          Convert bytes to longs and return long representation.
static byte[] convertLongToBytes(long value)
          Convert long to bytes and return the byte array representation.
static byte[] createCertificateMD5(java.security.cert.X509Certificate cert)
          Generate a MD5 certificate.
static byte createXORChecksum(byte[] data)
          Create a single-byte XOR checksum for data.
static java.lang.String getIPString(byte[] IPBytes)
          Retrieve IP address as a formatted string.
static byte[] getIPv4Bytes(java.lang.String ip)
          Return bytes for an IPv4 address string.
static byte[] getIPv6Bytes(java.lang.String ip)
          Returns bytes for an IPv6 address string.
static byte getIPVersion(java.lang.String ip)
          Get the IP version for an address
static boolean uploadLogFile(java.io.File logFile, java.lang.String fromServerIP, java.lang.String POST_URL)
          Upload a file to a server.
static boolean uploadLogFile(java.io.File logFile, java.lang.String fromServerIP, java.lang.String POST_URL, boolean isCompleteHour)
          Upload a log file to server.
static boolean validateXORChecksum(byte checksum, byte[] data)
          Validate a checksum byte for data
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LogUtil

public LogUtil()
Method Detail

getIPVersion

public static byte getIPVersion(java.lang.String ip)
Get the IP version for an address

Parameters:
ip - The string representing the IP address
Returns:
The ActionByte representation of the IP version.

getIPv4Bytes

public static byte[] getIPv4Bytes(java.lang.String ip)
Return bytes for an IPv4 address string.

Parameters:
ip -
Returns:

getIPv6Bytes

public static byte[] getIPv6Bytes(java.lang.String ip)
Returns bytes for an IPv6 address string.

Parameters:
ip -
Returns:

getIPString

public static java.lang.String getIPString(byte[] IPBytes)
                                    throws java.lang.Exception
Retrieve IP address as a formatted string.

Parameters:
IPBytes -
Returns:
Throws:
java.lang.Exception

createCertificateMD5

public static byte[] createCertificateMD5(java.security.cert.X509Certificate cert)
                                   throws java.lang.Exception
Generate a MD5 certificate.

Parameters:
cert -
Returns:
Throws:
java.lang.Exception

convertLongToBytes

public static byte[] convertLongToBytes(long value)
                                 throws java.lang.Exception
Convert long to bytes and return the byte array representation.

Parameters:
value -
Returns:
Throws:
java.lang.Exception

convertBytesToLong

public static long convertBytesToLong(byte[] longVal)
                               throws java.lang.Exception
Convert bytes to longs and return long representation.

Parameters:
longVal -
Returns:
Throws:
java.lang.Exception

createXORChecksum

public static byte createXORChecksum(byte[] data)
Create a single-byte XOR checksum for data.

Parameters:
data - The data that requires a checksum.
Returns:
A byte representing the checksum.

validateXORChecksum

public static boolean validateXORChecksum(byte checksum,
                                          byte[] data)
Validate a checksum byte for data

Parameters:
checksum - A single-byte XOR checksum that needs validated
data - The data for which the checksum was created.
Returns:
True if validates, false otherwise.

uploadLogFile

public static boolean uploadLogFile(java.io.File logFile,
                                    java.lang.String fromServerIP,
                                    java.lang.String POST_URL)
                             throws java.lang.Exception
Upload a file to a server.

Returns:
True if server returns HTTP code stating already added, false otherwise.
Throws:
java.lang.Exception

uploadLogFile

public static boolean uploadLogFile(java.io.File logFile,
                                    java.lang.String fromServerIP,
                                    java.lang.String POST_URL,
                                    boolean isCompleteHour)
                             throws java.lang.Exception
Upload a log file to server.

Parameters:
isCompleteHour - True only if an entire hour has passed.
Returns:
True if server returns HTTP code stating already added, false otherwise.
Throws:
java.lang.Exception


This code is free for use both commercially and non-commercially as stated in the project's license