Skip to content

Commit

Permalink
🏷️ Release 1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
XyperCode committed May 7, 2024
1 parent 3b265b5 commit f3acd21
Show file tree
Hide file tree
Showing 37 changed files with 405 additions and 340 deletions.
4 changes: 0 additions & 4 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .run/Build Project.run.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Build Project" type="GradleRunConfiguration" factoryName="Gradle">
<configuration default="false" name="Build Project" dataType="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ Assuming you use gradle.
public class DataTest {
public static void main(String[] args) {
MapType type = new MapType();
type.putString("greetings", "Hello World");
MapType dataType = new MapType();
dataType.putString("greetings", "Hello World");
DataIo.write(type, new File("data.ubo"));
DataIo.write(dataType, new File("data.ubo"));
}
}
```
Expand Down
106 changes: 84 additions & 22 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ plugins {

}

apply(plugin="java")
apply(plugin="java-library")
apply(plugin="maven-publish")
apply(plugin="signing")
apply(plugin = "java")
apply(plugin = "java-library")
apply(plugin = "maven-publish")
apply(plugin = "signing")

group = project.property("group")!!
version = "${project.property("version")}"
Expand All @@ -28,10 +28,10 @@ dependencies {
compileOnly("org.jetbrains:annotations:23.0.0")
}

//tasks.compileJava {
// sourceCompatibility = JavaVersion("1.8")
// targetCompatibility = JavaVersion("1.8")
//}
tasks.compileJava {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}

java {
withSourcesJar()
Expand All @@ -46,6 +46,64 @@ publishing {
publications {
register("mavenJava", MavenPublication::class) {
from(components["java"])

groupId = project.group.toString()
artifactId = project.name
version = project.version.toString()

pom {
name.set("UBO")
description.set("Extensible NBT-like data API.")

url.set("https://github.com/Ultreon/ubo")
inceptionYear.set("2022")

developers {
developer {
name.set("XyperCode")
email.set("qboiwastaken@gmail.com")

organization.set("Ultreon")
organizationUrl.set("https://github.com/Ultreon")
}
}

organization {
name.set("Ultreon")
url.set("https://github.com/Ultreon")
}

issueManagement {
system.set("GitHub")
url.set("https://github.com/Ultreon/ubo/issues")
}

licenses {
license {
name.set("Apache License")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
}
}

scm {
connection.set("scm:git:git://github.com/Ultreon/ubo.git")
developerConnection.set("scm:git:ssh://github.com/Ultreon/ubo.git")

url.set("https://github.com/Ultreon/ubo/tree/main")
}

contributors {
contributor {
name.set("XyperCode")
url.set("https://github.com/XyperCode")
}

contributor {
name.set("AndEditor7")
url.set("https://github.com/AndEditor7")
}
}
}
}
}
repositories {
Expand All @@ -56,26 +114,29 @@ publishing {
val ossrhUsername = findProperty("ossrh.username") ?: System.getenv("OSSRH_USERNAME")
val ossrhPassword = findProperty("ossrh.password") ?: System.getenv("OSSRH_PASSWORD")

maven {
name = "OssSonatype"
url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
if (ossrhUsername != null && ossrhPassword != null) {
if (ossrhUsername != null && ossrhPassword != null) {
maven {
name = "OssSonatype"
url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")

credentials {
username = ossrhUsername.toString()
password = ossrhPassword.toString()
}

}
}

maven {
name = "OssSnapshots"
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
credentials {
if (ossrhUsername != null && ossrhPassword != null) {
maven {
name = "OssSnapshots"
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")

credentials {
username = ossrhUsername.toString()
password = ossrhPassword.toString()
}
}
} else {
logger.warn("No OSSRH credentials found, skipping upload to OSSRH.")
}
}
}
Expand All @@ -90,9 +151,10 @@ tasks.withType<GenerateModuleMetadata> {
enabled = false
}

//tasks.signing {
// sign(configurations["archives"])
//}
extensions.configure<SigningExtension>("signing") {
useGpgCmd()
sign(publishing.publications["mavenJava"])
}

afterEvaluate {
tasks.javadoc {
Expand Down
68 changes: 34 additions & 34 deletions src/main/java/dev/ultreon/ubo/DataIo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.ultreon.ubo;

import dev.ultreon.ubo.types.DataType;
import dev.ultreon.ubo.util.DataTypeVisitor;
import dev.ultreon.ubo.types.IType;

import java.io.*;
import java.net.URL;
Expand All @@ -15,14 +15,14 @@ public class DataIo {
private static final int BUFFER_SIZE = 4096;

@SafeVarargs
public static <T extends IType<?>> T read(File file, T... type) throws IOException {
public static <T extends DataType<?>> T read(File file, T... type) throws IOException {
try (InputStream stream = new BufferedInputStream(Files.newInputStream(file.toPath()), BUFFER_SIZE)) {
return read(stream, type);
}
}

@SafeVarargs
public static <T extends IType<?>> T read(URL url, T... type) throws IOException {
public static <T extends DataType<?>> T read(URL url, T... type) throws IOException {
try (InputStream stream = new BufferedInputStream(url.openStream(), BUFFER_SIZE)) {
return read(stream, type);
}
Expand All @@ -33,7 +33,7 @@ public static <T extends IType<?>> T read(URL url, T... type) throws IOException
* @throws DataTypeException when the read data type is invalid.
*/
@SafeVarargs
public static <T extends IType<?>> T read(InputStream stream, T... type) throws IOException {
public static <T extends DataType<?>> T read(InputStream stream, T... type) throws IOException {
if (stream instanceof DataInput) {
return read((DataInput) stream, type);
}
Expand All @@ -46,7 +46,7 @@ public static <T extends IType<?>> T read(InputStream stream, T... type) throws
*/
@SafeVarargs
@SuppressWarnings("unchecked")
public static <T extends IType<?>> T read(DataInput input, T... type) throws IOException {
public static <T extends DataType<?>> T read(DataInput input, T... type) throws IOException {
int magic = input.readInt();
if (magic != HEADER) {
throw new StreamCorruptedException(String.format("Invalid header got 0x%08X (expected 0xFF804269)", magic));
Expand All @@ -58,99 +58,99 @@ public static <T extends IType<?>> T read(DataInput input, T... type) throws IOE
}

Class<T> componentType = (Class<T>) type.getClass().getComponentType();
int componentId = TypeRegistry.getId(componentType);
int componentId = DataTypeRegistry.getId(componentType);
int id = input.readUnsignedByte();

if (componentId != id) {
throw new DataTypeException("The read data id " + id + " is different from the expected id: " + componentId);
}

return (T) TypeRegistry.read(id, input);
return (T) DataTypeRegistry.read(id, input);
}

@SafeVarargs
public static <T extends IType<?>> T readCompressed(File file, T... type) throws IOException {
public static <T extends DataType<?>> T readCompressed(File file, T... type) throws IOException {
try (InputStream stream = new BufferedInputStream(Files.newInputStream(file.toPath()), BUFFER_SIZE)) {
return readCompressed(stream, type);
}
}

@SafeVarargs
public static <T extends IType<?>> T readCompressed(URL url, T... type) throws IOException {
public static <T extends DataType<?>> T readCompressed(URL url, T... type) throws IOException {
try (InputStream stream = new BufferedInputStream(url.openStream())) {
return readCompressed(stream, type);
}
}

@SafeVarargs
public static <T extends IType<?>> T readCompressed(InputStream stream, T... type) throws IOException {
public static <T extends DataType<?>> T readCompressed(InputStream stream, T... type) throws IOException {
GZIPInputStream gzipStream = new GZIPInputStream(stream);
return read(gzipStream, type);
}

public static void write(IType<?> type, File file) throws IOException {
public static void write(DataType<?> dataType, File file) throws IOException {
try (OutputStream stream = new BufferedOutputStream(Files.newOutputStream(file.toPath()), BUFFER_SIZE)) {
write(type, stream);
write(dataType, stream);
}
}

public static void write(IType<?> type, URL file) throws IOException {
public static void write(DataType<?> dataType, URL file) throws IOException {
try (OutputStream stream = new BufferedOutputStream(file.openConnection().getOutputStream(), BUFFER_SIZE)) {
write(type, stream);
write(dataType, stream);
}
}

public static void write(IType<?> type, OutputStream stream) throws IOException {
public static void write(DataType<?> dataType, OutputStream stream) throws IOException {
if (stream instanceof DataOutput) {
write(type, (DataOutput) stream);
write(dataType, (DataOutput) stream);
}
write(type, (DataOutput) new DataOutputStream(stream));
write(dataType, (DataOutput) new DataOutputStream(stream));
}

public static void write(IType<?> type, DataOutput output) throws IOException {
public static void write(DataType<?> dataType, DataOutput output) throws IOException {
output.writeInt(HEADER);
output.writeShort(VERSION); // Version
output.writeByte(type.id()); // Type
type.write(output);
output.writeByte(dataType.id()); // Type
dataType.write(output);
}

public static void writeCompressed(IType<?> type, URL file) throws IOException {
public static void writeCompressed(DataType<?> dataType, URL file) throws IOException {
try (OutputStream stream = new BufferedOutputStream(file.openConnection().getOutputStream(), BUFFER_SIZE)) {
writeCompressed(type, stream);
writeCompressed(dataType, stream);
}
}

public static void writeCompressed(IType<?> type, File file) throws IOException {
public static void writeCompressed(DataType<?> dataType, File file) throws IOException {
try (OutputStream stream = new BufferedOutputStream(Files.newOutputStream(file.toPath()), BUFFER_SIZE)) {
writeCompressed(type, stream);
writeCompressed(dataType, stream);
}
}

public static void writeCompressed(IType<?> type, OutputStream stream) throws IOException {
public static void writeCompressed(DataType<?> dataType, OutputStream stream) throws IOException {
GZIPOutputStream gzipStream = new GZIPOutputStream(stream);
write(type, gzipStream);
write(dataType, gzipStream);
gzipStream.finish();
gzipStream.flush();
}

public static String toUso(IType<?> type) {
return type.writeUso();
public static String toUso(DataType<?> dataType) {
return dataType.writeUso();
}

public static <T> T visit(DataTypeVisitor<T> visitor, IType<?> type) {
return type.accept(visitor);
public static <T> T visit(DataTypeVisitor<T> visitor, DataType<?> dataType) {
return dataType.accept(visitor);
}

@SuppressWarnings("unchecked")
@SafeVarargs
public static <T extends IType<?>> T fromUso(String value, T... type) throws IOException {
public static <T extends DataType<?>> T fromUso(String value, T... type) throws IOException {
try (BufferedReader reader = new BufferedReader(new StringReader(value))) {
IType<?> iType = readUso(reader.readLine());
return (T) iType;
DataType<?> iDataType = readUso(reader.readLine());
return (T) iDataType;
}
}

private static IType<?> readUso(String value) throws IOException {
private static DataType<?> readUso(String value) throws IOException {
return new UsoParser(value).parse();
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package dev.ultreon.ubo;

import dev.ultreon.ubo.types.IType;
import dev.ultreon.ubo.types.DataType;

import java.io.DataInput;
import java.io.IOException;

@FunctionalInterface
public interface IReader<T extends IType<?>> {
public interface DataReader<T extends DataType<?>> {
T read(DataInput input) throws IOException;
}
Loading

0 comments on commit f3acd21

Please sign in to comment.