|
|||||||||
| Home >> All >> com >> voytechs >> jnetstream >> primitive >> [ address overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
com.voytechs.jnetstream.primitive.address
Class Address

java.lang.Objectcom.voytechs.jnetstream.primitive.address.Address
- Direct Known Subclasses:
- IpAddress, IpNetmask, IpNetwork, MacAddress
- public class Address
- extends java.lang.Object
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
|
private int |
defaultNumberBase
|
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 |
DEFAULT_NUMBER_BASE
public static final int DEFAULT_NUMBER_BASE
- See Also:
- Constant Field Values
defaultNumberBase
private int defaultNumberBase
debug
public static final boolean debug
- See Also:
- Constant Field Values
address
protected byte[] address
- Array which stores the IP address bytes.
This is a variable array so that both v4 and v6 addresses.
separator
protected char separator
format
protected char[] format
| Constructor Detail |
Address
protected Address()
- Special internal use only constructor that does not initialize the
Address right away but later.
Address
public Address(byte[] address)
- Main constructor taking the array of bytes as the address
Address
public Address(Address ad)
- Main constructor taking the array of bytes as the address
| Method Detail |
setAddress
public void setAddress(byte[] address)
setSeparator
public void setSeparator(char separator)
setFormat
public void setFormat(java.lang.String format)
setFormat
public void setFormat(char[] format)
setRadix
public void setRadix(int radix)
getRadix
public int getRadix()
INVERT
public byte[] INVERT()
- This method INVERTs (Java statment
~) 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.
INVERT
public static byte[] INVERT(byte[] a)
- This method ORs 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.
EOR
public byte[] EOR(Address b)
- This method EORs (Exclusive OR) 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.
EOR
public static byte[] EOR(byte[] a,
byte[] b)
- This method ORs 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.
OR
public byte[] OR(Address b)
- This method ORs 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.
OR
public static byte[] OR(byte[] a,
byte[] b)
- This method ORs 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.
AND
public byte[] AND(Address b)
- This method ANDs 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.
AND
public static byte[] AND(byte[] a,
byte[] b)
- This method ANDs 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.
getByte
protected byte getByte(int index)
getByte
public static byte getByte(byte b)
equals
public boolean equals(java.lang.Object o)
- Compare our byte values for IP address to the object's.
If length do not match then the objects are considered unequal.
If byte counts are the same then a byte for byte comparison is made and
appropriate result return.
compareTo
public int compareTo(java.lang.Object o)
compare
public static int compare(Address a, Address b) throws java.lang.IllegalArgumentException
- Compare our byte values for IP address to the object's.
If length do not match then the one with smaller number of bytes
is considered less then the one with more bytes (V6 is always > V4).
If byte counts are the same then a byte for byte comparison is made and
appropriate result return.
compare
public static int compare(Address a, byte[] b) throws java.lang.IllegalArgumentException
longToByteArray
public static byte[] longToByteArray(long longAddress)
- Convert a long (32 bits) to byte array (4 bytes).
toByteArray
public byte[] toByteArray()
- Returns a byte[] representing this Address.
byteArrayValue
public byte[] byteArrayValue()
- Gets the byte array representation of this address.
stringValue
public java.lang.String stringValue()
- Get the Address number value in a dot notation.
setByteArrayAddress
protected void setByteArrayAddress(byte[] address)
- Set the internal address array.
parseByteArray
public static byte[] parseByteArray(java.lang.String address, int size, char separator) throws java.lang.IllegalArgumentException
- Return current IP address as byte array, for V4 that will be 4 bytes
for V6 16.
toString
public java.lang.String toString()
- Convert to dot notation string representation of the address
toString
public static java.lang.String toString(byte[] address, int radix, char separator)
- Convert internal address to a string. Use separator
to convert to string.
toString
public static java.lang.String toString(byte[] address, int radix, char[] format)
- Convert internal address to a string. Use separator
to convert to string.
main
public static void main(java.lang.String[] args)
- Test function for Address
|
|||||||||
| Home >> All >> com >> voytechs >> jnetstream >> primitive >> [ address overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
com.voytechs.jnetstream.primitive.address.Address