Skip to content

Commit 65060c5

Browse files
Update README.md
1 parent bf95e00 commit 65060c5

1 file changed

Lines changed: 167 additions & 64 deletions

File tree

README.md

Lines changed: 167 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,197 @@
1-
# Laivy's java-address
1+
# Java Address 📬
22

3-
This library provides robust classes for representing and manipulating network addresses and ports, including IPv4 and IPv6 addresses. It ensures valid formatting, supports various address operations, and offers utilities for common networking tasks.
3+
![Java](https://img.shields.io/badge/Java-ED8B00?style=for-the-badge&logo=java&logoColor=white)
4+
![License](https://img.shields.io/github/license/ItsLaivy/java-address?style=for-the-badge)
45

5-
## Table of Contents
6+
## Overview 🌐
67

7-
- [Port](#port)
8-
- [Address](#address)
9-
- [IPv4Address](#ipv4address)
10-
- [IPv6Address](#ipv6address)
8+
`java-address` is a lightweight library for handling internet addresses and communication protocols, including IPv4, IPv6 and Domains. It provides robust utilities for validation, parsing, and manipulation of network addresses and ports.
119

12-
## Port
10+
## Features ✨
1311

14-
The `Port` class represents a network port and ensures it adheres to the valid port number range (0 to 65535). It is an immutable and thread-safe class that extends `Number` and implements `Comparable`.
12+
- **Validation and Parsing**: Validate and create instances of IPv4 and IPv6 addresses from strings.
13+
- **Port Handling**: Represent and manipulate network ports, ensuring they are within the valid range (0 to 65535).
14+
- **Address Utilities**: Retrieve raw bytes and formatted names of addresses.
15+
- **Domain Names**: A fully complete Domain classes including **SLD**, **TLD** and **Subdomain** classes with all verifications.
1516

16-
### Key Features
17+
## Installation 📦
1718

18-
- **Validation**: Check if a string is a valid port number.
19-
- **Parsing**: Create `Port` instances from strings or integers.
20-
- **Port Type Classification**: Determine if a port is well-known, registered, or dynamic/private.
21-
- **Utilities**: Methods for incrementing, decrementing, and checking port characteristics.
19+
For now, there's no public artifact at the Maven Central for this.
20+
To use the **Java Address** library.
21+
You should install it manually at your project
22+
using [Maven Guide to installing 3rd party JARs](https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html)
2223

23-
### Example Methods
24+
## Usage 🛠️
2425

25-
- `validate(String string)`: Validates if a string is a valid port number.
26-
- `parse(String port)`: Parses a string to create a `Port` object.
27-
- `create(int port)`: Creates a `Port` object from an integer.
28-
- `isWellKnown()`: Checks if the port is a well-known port (0-1023).
29-
- `isRegistered()`: Checks if the port is a registered port (1024-49151).
30-
- `isDynamicPrivate()`: Checks if the port is a dynamic or private port (49152-65535).
31-
- `getPortType()`: Returns the type of the port.
26+
### Basic Example
3227

33-
## Address
28+
```java
29+
// Parses the 8080 into a port object
30+
Port port = Port.create(8080);
31+
// Parses the ipv4 into an object
32+
IPv4Address address = IPv4Address.parse("192.168.1.1");
33+
// The Host object includes information about the address and port
34+
Host host = Host.create(address, port);
3435

35-
The `Address` interface represents a network address, providing methods for handling both IPv4 and IPv6 addresses. It includes static methods to validate and parse addresses, and abstract methods to retrieve address bytes and names.
36+
// Print objects
37+
System.out.println("Port: " + port);
38+
System.out.println("Address: " + address);
39+
System.out.println("Host: " + host);
40+
```
3641

37-
### Key Features
42+
### Advanced Usage
3843

39-
- **Validation**: Validate addresses in IPv4 or IPv6 format.
40-
- **Parsing**: Create address instances from strings.
41-
- **Address Utilities**: Retrieve raw bytes and formatted names of the address.
42-
- **Port Handling**: Methods to convert addresses to strings with ports appended.
44+
#### Working with Ports
4345

44-
### Example Methods
46+
```java
47+
Port wellKnownPort = Port.create(80); // HTTP port
48+
Port registeredPort = Port.create(8080); // Custom application port
4549

46-
- `validate(String string)`: Validates if a string is a valid IPv4 or IPv6 address.
47-
- `parse(String string)`: Parses a string to create an `Address` object.
48-
- `getBytes()`: Returns the raw byte values of the address.
49-
- `getName()`: Returns the formatted string representation of the address.
50-
- `toString(Port port)`: Converts the address into a string representation with a port appended.
50+
System.out.println("Is well-known port: " + wellKnownPort.isWellKnown());
51+
System.out.println("Registered Port: " + registeredPort.isRegistered());
52+
```
5153

52-
## IPv4Address
54+
## IPv4 Address 🌐
5355

54-
The `IPv4Address` class represents an IPv4 network address. IPv4 addresses are 32-bit numerical labels separated by dots, e.g., `192.168.1.1`.
56+
The `IPv4Address` class represents an IPv4 network address. IPv4 addresses are 32-bit numerical labels written in decimal and separated by dots, e.g., `192.168.0.1`.
5557

56-
### Key Features
58+
### Usage Examples
5759

58-
- **Validation**: Ensures the address is a valid IPv4 address.
59-
- **Conversion**: Converts the address to and from its byte representation.
60-
- **Address Utilities**: Methods to check if the address is localhost, or within specific subnets or broadcast addresses.
60+
#### Validating an IPv4 Address
6161

62-
### Example Methods
62+
```java
63+
boolean isValid = IPv4Address.validate("192.168.0.1");
64+
System.out.println("Is valid: " + isValid); // Returns 'true'
6365

64-
- `validate(String string)`: Validates if a string is a valid IPv4 address.
65-
- `parse(String string)`: Parses a string to create an `IPv4Address` object.
66-
- `getOctets()`: Returns the individual octets of the IPv4 address.
67-
- `isLocalHost()`: Checks if the address is a localhost address.
68-
- `isInSubnet(IPv4Address subnetMask)`: Checks if the address is within the range defined by a subnet mask.
69-
- `isBroadcast(IPv4Address subnetMask)`: Checks if the address is a broadcast address for the given subnet mask.
66+
isValid = IPv4Address.validate("255.255.255.255");
67+
System.out.println("Is valid: " + isValid); // Returns 'true'
7068

71-
## IPv6Address
69+
isValid = IPv4Address.validate("999.999.999.999");
70+
System.out.println("Is valid: " + isValid); // Returns 'false'
71+
```
7272

73-
The `IPv6Address` class represents an IPv6 network address. IPv6 addresses are 128-bit numerical labels separated by colons, e.g., `2001:0db8:85a3:0000:0000:8a2e:0370:7334`.
73+
#### Parsing an IPv4 Address
7474

75-
### Key Features
75+
```java
76+
IPv4Address ipv4Address = IPv4Address.parse("192.168.0.1");
77+
System.out.println("Parsed address: " + ipv4Address.getName());
78+
```
7679

77-
- **Validation**: Ensures the address is a valid IPv6 address.
78-
- **Compression Handling**: Handles address compression and decompression.
79-
- **Address Utilities**: Methods to check if the address is a loopback address, or within specific subnets or broadcast addresses.
80+
#### Getting Byte Representation
8081

81-
### Example Methods
82+
```java
83+
IPv4Address ipv4Address = IPv4Address.parse("192.168.0.1");
84+
System.out.println("Byte representation: " + Arrays.toString(ipv4Address.getBytes()));
85+
```
8286

83-
- `validate(String string)`: Validates if a string is a valid IPv6 address.
84-
- `parse(String string)`: Parses a string to create an `IPv6Address` object.
85-
- `getGroups()`: Returns the individual groups of the IPv6 address.
86-
- `getName()`: Returns the address in its compressed format.
87-
- `getRawName()`: Returns the raw, uncompressed string representation of the address.
88-
- `isLocalHost()`: Checks if the address is a loopback address.
89-
- `isInSubnet(IPv6Address subnetMask)`: Checks if the address is within the range defined by a subnet mask.
90-
- `isBroadcast(IPv6Address subnetMask)`: Checks if the address is a broadcast address for the given subnet mask.
87+
#### Checking if Address is local
88+
89+
```java
90+
IPv4Address ipv4Address = IPv4Address.parse("127.0.0.1");
91+
System.out.println("Is local: " + ipv4Address.isLocal());
92+
```
93+
94+
## IPv6 Addresses 🌐
95+
96+
The `IPv6Address` class represents an IPv6 network address. IPv6 addresses are 128-bit numerical labels written in hexadecimal and separated by colons, e.g., `2001:0db8:85a3:0000:0000:8a2e:0370:7334`.
97+
98+
### Usage Examples
99+
100+
#### Validating an IPv6 Address
101+
102+
```java
103+
boolean isValid = IPv6Address.validate("2001:0db8:85a3:0000:0000:8a2e:0370:7334");
104+
System.out.println("Is valid: " + isValid); // Prints 'true'
105+
106+
isValid = IPv6Address.validate("::ffff:192.0.2.128");
107+
System.out.println("Is valid: " + isValid); // Prints 'true'
108+
109+
isValid = IPv6Address.validate("2001:0db8:85a3::85a3::7334");
110+
System.out.println("Is valid: " + isValid); // Prints 'false'
111+
```
112+
113+
#### Parsing an IPv6 Address
114+
115+
```java
116+
IPv6Address ipv6Address = IPv6Address.parse("2001:0db8:85a3:0000:0000:8a2e:0370:7334");
117+
System.out.println("Parsed address: " + ipv6Address.getName());
118+
```
119+
120+
#### Getting Byte Representation
121+
122+
```java
123+
IPv6Address ipv6Address = IPv6Address.parse("2001:0db8:85a3:0000:0000:8a2e:0370:7334");
124+
System.out.println("Byte representation: " + Arrays.toString(ipv6Address.getBytes()));
125+
```
126+
127+
#### Checking if Address is local
128+
129+
```java
130+
IPv6Address ipv6Address = IPv6Address.parse("::1");
131+
System.out.println("Is local: " + ipv6Address.isLocal());
132+
```
133+
134+
## Domain Names 🌐
135+
136+
### Domain
137+
The `Domain` class represents a fully qualified domain name (FQDN). It provides methods to parse and validate domain names, ensuring they conform to standard formats.
138+
139+
#### Example
140+
```java
141+
Domain domain = Domain.parse("example.com");
142+
System.out.println("Domain: " + domain);
143+
```
144+
145+
### TLD (Top-Level Domain)
146+
The `TLD` class represents the top-level domain of a domain name, such as `.com`, `.org`, or `.net`. It includes methods for validation and retrieval of the TLD from a given domain.
147+
148+
#### Example
149+
```java
150+
TLD tld = TLD.parse("com");
151+
System.out.println("Top-Level Domain: " + tld);
152+
```
153+
154+
### SLD (Second-Level Domain)
155+
The `SLD` class represents the second-level domain, which is the part of the domain name directly to the left of the TLD. For example, in `example.com`, `example` is the SLD. This class provides methods to parse and validate the SLD.
156+
157+
#### Example
158+
```java
159+
SLD sld = SLD.parse("example");
160+
System.out.println("Second-Level Domain: " + sld);
161+
```
162+
163+
### Subdomain
164+
The `Subdomain` class represents the subdomain part of a domain name, which is the part to the left of the SLD. For example, in `blog.example.com`, `blog` is the subdomain. This class provides methods to parse and validate subdomains.
165+
166+
#### Example
167+
```java
168+
Subdomain subdomain = Subdomain.parse("blog");
169+
System.out.println("Subdomain: " + subdomain);
170+
```
171+
172+
These classes work together to provide a comprehensive toolkit for handling and manipulating domain names in your applications.
173+
174+
## Contributing 🤝
175+
176+
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
177+
178+
1. Fork the repository
179+
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
180+
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
181+
4. Push to the branch (`git push origin feature/AmazingFeature`)
182+
5. Open a pull request
183+
184+
## License 📄
185+
186+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
187+
188+
## Acknowledgements 🙏
189+
190+
- Thanks to all the contributors who have helped improve this project.
191+
- Special thanks to the open-source community for their continuous support and contributions.
91192

92193
---
93194

94-
For more details and usage examples, please refer to the API documentation or the source code of the library. Feel free to contribute and enhance the library by opening issues or submitting pull requests.
195+
Feel free to reach out if you have any questions or need further assistance!
196+
197+
Happy coding! 🚀

0 commit comments

Comments
 (0)