Skip to content

Commit c126591

Browse files
author
david
committed
Add detailed Javadoc comments to NBT tag classes
Enhanced the NBT tag classes with comprehensive Javadoc comments. This improvement adds detailed descriptions and method documentation, aiding developers in understanding and using these classes effectively.
1 parent 17e4445 commit c126591

21 files changed

+494
-15
lines changed

nbt/src/main/java/core/nbt/NBTInputStream.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,31 @@
1414
import java.util.Optional;
1515
import java.util.zip.GZIPInputStream;
1616

17+
/**
18+
* An input stream for reading NBT (Named Binary Tag) data.
19+
*/
1720
@Getter
1821
@NullMarked
1922
public final class NBTInputStream extends DataInputStream {
2023
private final Charset charset;
2124

2225
/**
23-
* @param inputStream the input stream
24-
* @throws IOException thrown if something goes wrong
26+
* Constructs an {@code NBTInputStream} for reading NBT data from the specified input stream.
27+
*
28+
* @param inputStream the input stream from which the NBT data is to be read
29+
* @throws IOException if an I/O error occurs while reading from the stream
2530
*/
2631
public NBTInputStream(InputStream inputStream) throws IOException {
2732
this(inputStream, StandardCharsets.UTF_8);
2833
}
2934

3035
/**
31-
* @param charset the charset of the content
32-
* @param inputStream the input stream
33-
* @throws IOException thrown if something goes wrong
36+
* Constructs an {@code NBTInputStream} for reading NBT data from the specified input stream
37+
* and charset.
38+
*
39+
* @param inputStream the input stream from which the NBT data is to be read
40+
* @param charset the charset to use for reading string data from the stream
41+
* @throws IOException if an I/O error occurs while reading from the stream
3442
*/
3543
public NBTInputStream(InputStream inputStream, Charset charset) throws IOException {
3644
super(new DataInputStream(new GZIPInputStream(inputStream)));
@@ -109,6 +117,13 @@ public void registerMapping(int typeId, MappingFunction function) {
109117
*/
110118
@FunctionalInterface
111119
public interface MappingFunction {
120+
/**
121+
* Maps an NBTInputStream to a Tag object.
122+
*
123+
* @param inputStream the NBTInputStream to be mapped
124+
* @return the Tag object mapped from the inputStream
125+
* @throws IOException if an I/O error occurs while reading from the stream
126+
*/
112127
Tag map(NBTInputStream inputStream) throws IOException;
113128
}
114129
}

nbt/src/main/java/core/nbt/NBTOutputStream.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import core.nbt.tag.EscapeTag;
44
import core.nbt.tag.Tag;
55
import lombok.Getter;
6-
import org.jspecify.annotations.NonNull;
6+
import org.jspecify.annotations.NullMarked;
77
import org.jspecify.annotations.Nullable;
88

99
import java.io.DataOutputStream;
@@ -13,17 +13,23 @@
1313
import java.nio.charset.StandardCharsets;
1414
import java.util.zip.GZIPOutputStream;
1515

16+
/**
17+
* A specialized DataOutputStream for writing Named Binary Tag (NBT) data.
18+
* This stream supports GZIP compression and allows for writing various
19+
* types of NBT tags.
20+
*/
1621
@Getter
22+
@NullMarked
1723
public final class NBTOutputStream extends DataOutputStream {
18-
private final @NonNull Charset charset;
24+
private final Charset charset;
1925

2026
/**
2127
* Create a nbt output stream
2228
*
2329
* @param outputStream the stream to write to
2430
* @throws IOException thrown if something goes wrong
2531
*/
26-
public NBTOutputStream(@NonNull OutputStream outputStream) throws IOException {
32+
public NBTOutputStream(OutputStream outputStream) throws IOException {
2733
this(outputStream, StandardCharsets.UTF_8);
2834
}
2935

@@ -34,7 +40,7 @@ public NBTOutputStream(@NonNull OutputStream outputStream) throws IOException {
3440
* @param outputStream the stream to write to
3541
* @throws IOException thrown if something goes wrong
3642
*/
37-
public NBTOutputStream(@NonNull OutputStream outputStream, @NonNull Charset charset) throws IOException {
43+
public NBTOutputStream(OutputStream outputStream, Charset charset) throws IOException {
3844
super(new GZIPOutputStream(outputStream));
3945
this.charset = charset;
4046
}
@@ -47,7 +53,7 @@ public NBTOutputStream(@NonNull OutputStream outputStream, @NonNull Charset char
4753
* @throws IOException thrown if something goes wrong
4854
* @throws IllegalArgumentException thrown if an escape tag was provided
4955
*/
50-
public void writeTag(@Nullable String name, @NonNull Tag tag) throws IOException, IllegalArgumentException {
56+
public void writeTag(@Nullable String name, Tag tag) throws IOException, IllegalArgumentException {
5157
if (tag instanceof EscapeTag) throw new IllegalArgumentException("EscapeTag not allowed");
5258
var bytes = name != null ? name.getBytes(getCharset()) : new byte[0];
5359
writeByte(tag.getTypeId());

nbt/src/main/java/core/nbt/file/NBTFile.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,21 @@
1818

1919
import static java.nio.file.StandardOpenOption.*;
2020

21+
/**
22+
* Represents an NBT (Named Binary Tag) file that can be read from and written to.
23+
* This class extends the {@link FileIO} class, allowing for operations specific to NBT files.
24+
*
25+
* @param <R> the type of the root object, which extends {@link CompoundTag}
26+
*/
2127
@Getter
2228
@Setter
2329
@ToString(callSuper = true)
2430
@EqualsAndHashCode(callSuper = true)
2531
public class NBTFile<R extends CompoundTag> extends FileIO<R> {
32+
/**
33+
* The name of the root tag in an NBT (Named Binary Tag) file.
34+
* This variable can be null if no root name is specified.
35+
*/
2636
private @Nullable String rootName;
2737

2838
/**

nbt/src/main/java/core/nbt/tag/BooleanTag.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,42 @@
22

33
import org.jspecify.annotations.NullMarked;
44

5+
/**
6+
* The BooleanTag class represents a boolean value as a byte, where the boolean
7+
* value is stored as 0 for false and 1 for true.
8+
* This class extends the ByteTag class and provides methods to manipulate boolean values specifically.
9+
*/
510
@NullMarked
611
public class BooleanTag extends ByteTag {
12+
/**
13+
* Constructs a new BooleanTag instance, representing a boolean value as a byte.
14+
*
15+
* @param value the boolean value to be stored in this tag, where true is
16+
* represented as 1 and false is represented as 0
17+
*/
718
public BooleanTag(boolean value) {
819
super((byte) (value ? 1 : 0));
920
}
1021

22+
/**
23+
* Sets the byte value based on the provided boolean value.
24+
* {@code true} is represented as byte value 1, and {@code false} is represented as byte value 0.
25+
*
26+
* @param value the boolean value to be converted to a byte and set
27+
*/
1128
public void setValue(boolean value) {
1229
setValue((byte) (value ? 1 : 0));
1330
}
1431

32+
/**
33+
* Sets the value of this BooleanTag to the specified byte value.
34+
* The value must be either 0 or 1. If the value is valid,
35+
* it will delegate the setting operation to the superclass method.
36+
* If the value is not valid, it throws an IllegalArgumentException.
37+
*
38+
* @param value the byte value to set, which must be 0 or 1
39+
* @throws IllegalArgumentException if the value is not 0 or 1
40+
*/
1541
@Override
1642
public void setValue(Byte value) {
1743
if (value == 0 || value == 1) super.setValue(value);

nbt/src/main/java/core/nbt/tag/ByteArrayTag.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,25 @@
66

77
import java.io.IOException;
88

9+
/**
10+
* Represents a tag that contains a byte array.
11+
* This class extends {@code ValueTag<byte[]>} and implements {@code IterableTag<Byte>},
12+
* providing functionality for handling and manipulating a byte array within an NBT (Named Binary Tag) structure.
13+
* It provides methods for reading from and writing to an {@code NBTInputStream}
14+
* and {@code NBTOutputStream} respectively.
15+
*/
916
@NullMarked
1017
public class ByteArrayTag extends ValueTag<byte[]> implements IterableTag<Byte> {
18+
/**
19+
* Represents the unique identifier for this Tag.
20+
*/
1121
public static final int ID = 7;
1222

23+
/**
24+
* Constructs a new ByteArrayTag with the given byte array.
25+
*
26+
* @param array the byte array to be encapsulated by this tag
27+
*/
1328
public ByteArrayTag(byte[] array) {
1429
super(array);
1530
}
@@ -40,6 +55,13 @@ public void write(NBTOutputStream outputStream) throws IOException {
4055
outputStream.write(getValue());
4156
}
4257

58+
/**
59+
* Reads a ByteArrayTag from the given NBTInputStream.
60+
*
61+
* @param inputStream the NBT input stream to read the byte array from
62+
* @return a ByteArrayTag containing the byte array read from the input stream
63+
* @throws IOException if an I/O error occurs while reading from the input stream
64+
*/
4365
public static ByteArrayTag read(NBTInputStream inputStream) throws IOException {
4466
var length = inputStream.readInt();
4567
var bytes = new byte[length];

nbt/src/main/java/core/nbt/tag/ByteTag.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,32 @@
66

77
import java.io.IOException;
88

9+
/**
10+
* The ByteTag class represents a byte value in the tag structure.
11+
* It extends the NumberTag class with Byte as the specific number type.
12+
* This class provides methods to manipulate the byte value and read/write it to an NBT stream.
13+
*/
914
@NullMarked
1015
public class ByteTag extends NumberTag<Byte> {
16+
/**
17+
* Represents the unique identifier for this Tag.
18+
*/
1119
public static final int ID = 1;
1220

21+
/**
22+
* Constructs a new ByteTag instance with the specified byte value.
23+
*
24+
* @param value the byte value to be stored in this tag
25+
*/
1326
public ByteTag(Byte value) {
1427
super(value);
1528
}
1629

30+
@Override
31+
public boolean getAsBoolean() {
32+
return getValue() == 1;
33+
}
34+
1735
@Override
1836
public byte getAsByte() {
1937
return getValue();
@@ -29,12 +47,14 @@ public void write(NBTOutputStream outputStream) throws IOException {
2947
outputStream.write(getValue());
3048
}
3149

50+
/**
51+
* Reads a byte value from the provided NBTInputStream and returns it as a ByteTag.
52+
*
53+
* @param inputStream the NBTInputStream to read the byte value from
54+
* @return a ByteTag containing the read byte value
55+
* @throws IOException if an I/O error occurs while reading from the input stream
56+
*/
3257
public static ByteTag read(NBTInputStream inputStream) throws IOException {
3358
return new ByteTag(inputStream.readByte());
3459
}
35-
36-
@Override
37-
public boolean getAsBoolean() {
38-
return getValue() == 1;
39-
}
4060
}

0 commit comments

Comments
 (0)