Surily is collection of objects about URI for Java 11+. It's written with object thinking, standardization and minimalism in mind. Excluding JDK 11+ it doesn't require any dependencies.
It's in work in progress state
Here you are some examples:
import io.github.raffaeleflorio.surily.*;
import io.github.raffaeleflorio.surily.authority.Authority;
import io.github.raffaeleflorio.surily.authority.RegName;
import io.github.raffaeleflorio.surily.fragment.Fragment;
import io.github.raffaeleflorio.surily.path.*;
import io.github.raffaeleflorio.surily.query.PairQuery;
import io.github.raffaeleflorio.surily.scheme.Scheme;
import java.nio.charset.StandardCharsets;
class Examples {
void assertDogFactUri() {
assertEquals(
"https://dog-facts-api.herokuapp.com/api/v1/resources/dogs?number=1",
new Uri(
new Scheme("https"),
new Authority(
new RegName("dog-facts-api.herokuapp.com")
),
new AbsolutePath(
List.of(
new PathSegment("api"),
new PathSegment("v1"),
new PathSegment("resources"),
new PathSegment("dogs")
)
),
new PairQuery("number", "1")
).asString()
);
}
void assertSameDocumentReference() {
assertEquals(
"#a%20reference%20in%20a%20document",
new SameDocumentReference(
new Fragment("a reference in a document")
).encoded(StandardCharsets.UTF_8)
);
}
void assertPathTraversal() {
assertEquals(
"../../../../etc/passwd",
new RelativePath(
List.of(
new DoubleDotSegment(),
new DoubleDotSegment(),
new DoubleDotSegment(),
new DoubleDotSegment(),
new PathSegment("etc"),
new PathSegment("passwd")
)
).encoded(StandardCharsets.US_ASCII)
);
}
void assertNormalizedPathTraversal() {
assertEquals(
"etc/passwd",
new RelativePath(
new NormalizedSegments(
new RelativePath(
List.of(
new DoubleDotSegment(),
new DoubleDotSegment(),
new DoubleDotSegment(),
new DoubleDotSegment(),
new PathSegment("etc"),
new PathSegment("passwd")
)
)
)
).encoded(StandardCharsets.US_ASCII)
);
}
void assertISBN() {
assertEquals(
"urn:isbn:0048230464",
new Uri(
new Scheme("urn"),
new RelativePath(
List.of(
new PathSegment("isbn:0048230464")
)
)
).encoded(StandardCharsets.UTF_8)
);
}
// WIP
}
Surily will be distributed through the Maven Central Repository. So you can integrate it with:
<dependency>
<groupId>io.github.raffaeleflorio</groupId>
<artifactId>surily</artifactId>
<version>1.0.0</version>
</dependency>