|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.voytechs.jnetstream.primitive.address.Address
public class Address
A Class for storing IP Addresses Currently is only designed to utilize IPv4 (32bit) addresses. There are various functions for converting the IP address to a LONG. Why would you want to use a long for storage of an IP address, in my case I store IP address 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 address in a byte array.
| Field Summary | |
|---|---|
protected byte[] |
address
Array which stores the IP address bytes. |
static boolean |
debug
|
static int |
DEFAULT_NUMBER_BASE
|
protected char[] |
format
|
protected char |
separator
|
| Constructor Summary | |
|---|---|
protected |
Address()
Special internal use only constructor that does not initialize the Address right away but later. |
|
Address(Address ad)
Main constructor taking the array of bytes as the address |
|
Address(byte[] address)
Main constructor taking the array of bytes as the address |
| Method Summary | |
|---|---|
byte[] |
AND(Address b)
This method ANDs Address object to another Address object. |
static byte[] |
AND(byte[] a,
byte[] b)
This method ANDs Address object to another Address object. |
byte[] |
byteArrayValue()
Gets the byte array representation of this address. |
static int |
compare(Address a,
Address b)
Compare our byte values for IP address to the object's. |
static int |
compare(Address a,
byte[] b)
|
int |
compareTo(java.lang.Object o)
|
byte[] |
EOR(Address b)
This method EORs (Exclusive OR) Address object to another Address object. |
static byte[] |
EOR(byte[] a,
byte[] b)
This method ORs Address object to another Address object. |
boolean |
equals(java.lang.Object o)
Compare our byte values for IP address to the object's. |
static byte |
getByte(byte b)
|
protected byte |
getByte(int index)
|
int |
getRadix()
|
byte[] |
INVERT()
This method INVERTs (Java statment ~) Address object to another Address object. |
static byte[] |
INVERT(byte[] a)
This method ORs Address object to another Address object. |
static byte[] |
longToByteArray(long longAddress)
Convert a long (32 bits) to byte array (4 bytes). |
static void |
main(java.lang.String[] args)
Test function for Address |
byte[] |
OR(Address b)
This method ORs Address object to another Address object. |
static byte[] |
OR(byte[] a,
byte[] b)
This method ORs Address object to another Address object. |
static byte[] |
parseByteArray(java.lang.String address,
int size,
char separator)
Return current IP address as byte array, for V4 that will be 4 bytes for V6 16. |
void |
setAddress(byte[] address)
|
protected void |
setByteArrayAddress(byte[] address)
Set the internal address array. |
void |
setFormat(char[] format)
|
void |
setFormat(java.lang.String format)
|
void |
setRadix(int radix)
|
void |
setSeparator(char separator)
|
java.lang.String |
stringValue()
Get the Address number value in a dot notation. |
byte[] |
toByteArray()
Returns a byte[] representing this Address. |
java.lang.String |
toString()
Convert to dot notation string representation of the address |
static java.lang.String |
toString(byte[] address,
int radix,
char separator)
Convert internal address to a string. |
static java.lang.String |
toString(byte[] address,
int radix,
char[] format)
Convert internal address to a string. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFAULT_NUMBER_BASE
public static final boolean debug
protected byte[] address
protected char separator
protected char[] format
| Constructor Detail |
|---|
protected Address()
stringAddress - takes the IP address as a string.public Address(byte[] address)
public Address(Address ad)
| Method Detail |
|---|
public void setAddress(byte[] address)
public void setSeparator(char separator)
public void setFormat(java.lang.String format)
public void setFormat(char[] format)
public void setRadix(int radix)
public int getRadix()
public byte[] INVERT()
~) Address object to another Address 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(Address b)
public static byte[] EOR(byte[] a,
byte[] b)
public byte[] OR(Address b)
public static byte[] OR(byte[] a,
byte[] b)
public byte[] AND(Address b)
public static byte[] AND(byte[] a,
byte[] b)
protected byte getByte(int index)
public static byte getByte(byte b)
public boolean equals(java.lang.Object o)
equals in class java.lang.Objecto - Address 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)
public static int compare(Address a,
Address b)
throws java.lang.IllegalArgumentException
a - Address object to campare to.b - Address 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.IllegalArgumentException
public static int compare(Address a,
byte[] b)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentExceptionpublic static byte[] longToByteArray(long longAddress)
address - IP address. Only first 32 bits are importantpublic byte[] toByteArray()
public byte[] byteArrayValue()
public java.lang.String stringValue()
protected void setByteArrayAddress(byte[] address)
public static byte[] parseByteArray(java.lang.String address,
int size,
char separator)
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.Object
public static java.lang.String toString(byte[] address,
int radix,
char separator)
public static java.lang.String toString(byte[] address,
int radix,
char[] format)
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 | ||||||||