|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.voytechs.jnetstream.primitive.address.IpNumber
public class IpNumber
A Class for storing IP Addresses Currently is only designed to utilize IPv4 (32bit) byteArrayAddresses. There are various functions for converting the IP byteArrayAddress to a LONG. Why would you want to use a long for storage of an IP byteArrayAddress, in my case I store IP byteArrayAddress in a database as an UNSIGNED INT, java does not have unsigned numbers so you have to go to next bigger primitive type to store it or do like other implementations do store the byteArrayAddress in a byte array.
| Field Summary | |
|---|---|
protected byte[] |
byteArrayAddress
Array which stores the IP byteArrayAddress bytes. |
static boolean |
debug
|
| Constructor Summary | |
|---|---|
protected |
IpNumber()
Special internal use only constructor that does not initialize the IpNumber right away but later. |
|
IpNumber(byte[] byteArrayAddress)
Main constructor taking the array of bytes as the byteArrayAddress |
|
IpNumber(IpNumber ip)
Main constructor taking another IpNumber object |
|
IpNumber(long longAddress)
Constructor taking a integer IPv4 value |
|
IpNumber(java.lang.String stringAddress)
Constructor taking a integer IPv4 value |
| Method Summary | |
|---|---|
static byte[] |
AND(byte[] a,
byte[] b)
This method ANDs IpNumber object to another IpNumber object. |
byte[] |
AND(IpNumber b)
This method ANDs IpNumber object to another IpNumber object. |
byte[] |
byteArrayValue()
Gets the byte array representation of this address. |
static int |
compare(IpNumber a,
IpNumber b)
Compare our byte values for IP address to the object's. |
int |
compareTo(java.lang.Object o)
|
static byte[] |
EOR(byte[] a,
byte[] b)
This method ORs IpNumber object to another IpNumber object. |
byte[] |
EOR(IpNumber b)
This method EORs (Exclusive OR) IpNumber object to another IpNumber object. |
boolean |
equals(java.lang.Object o)
Compare our byte values for IP address to the object's. |
static int |
getByte(byte b)
|
protected int |
getByte(int index)
|
byte[] |
INVERT()
This method INVERTs (Java statment ~) IpNumber object to another IpNumber object. |
static byte[] |
INVERT(byte[] a)
This method ORs IpNumber object to another IpNumber object. |
long |
longValue()
Return the value of this IpNumber object as a long. |
static void |
main(java.lang.String[] args)
Test function for IpNumber |
static byte[] |
OR(byte[] a,
byte[] b)
This method ORs IpNumber object to another IpNumber object. |
byte[] |
OR(IpNumber b)
This method ORs IpNumber object to another IpNumber object. |
static byte[] |
parseByteArray(java.lang.String address)
Return current IP address as byte array, for V4 that will be 4 bytes for V6 16. |
static long |
parseLong(java.lang.String byteArrayAddress)
Parse string containing a string representation of and IP byteArrayAddress in the dot notatio such as 1.2.3.4 to long. |
protected void |
setByteArrayAddress(byte[] address)
Set the internal address array. |
int |
setDefaultNumberBase(int radix)
|
static int |
setGlobalDefaultNumberBase(int radix)
|
java.lang.String |
stringValue()
Get the IP number value in a dot notation. |
byte[] |
toByteArray()
Returns a byte[] representing this IpNumber. |
static byte[] |
toByteArray(long longAddress)
Convert a long (32 bits) to byte array (4 bytes). |
static long |
toLong(byte[] byteArray)
Convert a byte array to a long. |
java.lang.String |
toString()
Convert to dot notation string representation of the byteArrayAddress |
static java.lang.String |
toString(byte[] byteArrayAddress)
Convert internal byteArrayAddress to a string. |
static java.lang.String |
toString(byte[] byteArrayAddress,
int radix)
Convert internal byteArrayAddress to a string. |
static java.lang.String |
toString(long longAddress)
Convert internal byteArrayAddress to a string. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final boolean debug
protected byte[] byteArrayAddress
| Constructor Detail |
|---|
protected IpNumber()
stringAddress - takes the IP address as a string.public IpNumber(java.lang.String stringAddress)
stringAddress - takes the IP address as a string.public IpNumber(long longAddress)
byteArrayAddress - IP byteArrayAddress. Only first 32 bits are importantpublic IpNumber(byte[] byteArrayAddress)
public IpNumber(IpNumber ip)
| Method Detail |
|---|
public int setDefaultNumberBase(int radix)
public static int setGlobalDefaultNumberBase(int radix)
public byte[] INVERT()
~) IpNumber object to another IpNumber object.
Every byte is ANDed with every other byte
in the corresponding object. If number of bytes in the first number
does not match the number in the second object then an IllegalArgumentException
is thrown.
public static byte[] INVERT(byte[] a)
public byte[] EOR(IpNumber b)
public static byte[] EOR(byte[] a,
byte[] b)
public byte[] OR(IpNumber b)
public static byte[] OR(byte[] a,
byte[] b)
public byte[] AND(IpNumber b)
public static byte[] AND(byte[] a,
byte[] b)
protected int getByte(int index)
public static int getByte(byte b)
public boolean equals(java.lang.Object o)
equals in class java.lang.Objecto - IpNumber object to campare to.
If - either object is not of IP v4 or V6. If their byte lengths do not follow the standard.public int compareTo(java.lang.Object o)
compareTo in interface java.lang.Comparable
public static int compare(IpNumber a,
IpNumber b)
throws java.lang.IllegalArgumentException
a - IpNumber object to campare to.b - IpNumber object to campare with.
If - either object is not of IP v4 or V6. If their byte lengths do not follow the standard.
java.lang.IllegalArgumentExceptionpublic static byte[] toByteArray(long longAddress)
byteArrayAddress - IP byteArrayAddress. Only first 32 bits are importantpublic byte[] toByteArray()
public static long toLong(byte[] byteArray)
throws java.lang.IllegalArgumentException
byteArray - 4 byte array to convert to a long.
java.lang.Byte - array will not fit into a long.
java.lang.IllegalArgumentExceptionpublic long longValue()
public byte[] byteArrayValue()
public java.lang.String stringValue()
protected void setByteArrayAddress(byte[] address)
public static byte[] parseByteArray(java.lang.String address)
throws java.lang.IllegalArgumentException
address - String representation of IP address. Both V4 and V6 type addresses are accepted.
java.lang.IllegalArgumentExceptionpublic java.lang.String toString()
toString in class java.lang.Objectpublic static long parseLong(java.lang.String byteArrayAddress)
byteArrayAddress - byteArrayAddress in the dot notation.
public static java.lang.String toString(long longAddress)
public static java.lang.String toString(byte[] byteArrayAddress)
public static java.lang.String toString(byte[] byteArrayAddress,
int radix)
public static void main(java.lang.String[] args)
args - command line arguments
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||