Package com.saicone.nbt.io
Class TagWriter<T>
java.lang.Object
java.io.Writer
com.saicone.nbt.io.TagWriter<T>
- Type Parameters:
T
- the tag object implementation.
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
Writes tag objects into delegated
The formatting method aims to be compatible with older Minecraft versions by avoiding the usage of single quotes.
Writer
as SNBT format.The formatting method aims to be compatible with older Minecraft versions by avoiding the usage of single quotes.
- See Also:
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
flush()
Get the mapper that is used to extract values.Get the delegated writer.protected boolean
isUnquoted
(char c) Check if the provided char is an allowed unquoted character.protected boolean
Check if the provided string should be unquoted.Create a tag writer that accepts nbt-represented java objects with providedWriter
.Convert nbt-represented java object into SNBT.Convert tag object into SNBT with providedTagMapper
.void
write
(@org.jetbrains.annotations.NotNull char[] cbuf, int off, int len) void
writeBooleanArrayTag
(boolean[] booleans) Write fake boolean array tag value.void
writeByteArrayTag
(byte[] bytes) Write byte array tag value.void
writeCompoundTag
(@NotNull Map<String, T> map) Write map of string-tag entries value from compound tag type.void
writeIntArrayTag
(int[] ints) Write int array tag value.void
writeListTag
(@NotNull List<T> list) Write list of tag objects value from list tag type.void
writeLongArrayTag
(long[] longs) Write long array tag value.<V> void
writePrimitiveTag
(@NotNull TagType<V> type, V v) Write to provided primitive tag value with associated type.void
Write string tag value, any"
will be replaced with\"
to match SNBT compatibility.void
Write to provided tag object.
-
Constructor Details
-
TagWriter
- Parameters:
writer
- the delegated writer to append characters.mapper
- the mapper to extract values from tags.
-
-
Method Details
-
of
Create a tag writer that accepts nbt-represented java objects with providedWriter
.- Parameters:
writer
- the delegated writer to append characters.- Returns:
- a newly generated tag writer.
-
of
@NotNull public static <T> @NotNull TagWriter<T> of(@NotNull @NotNull Writer writer, @NotNull @NotNull TagMapper<T> mapper) - Type Parameters:
T
- the tag object implementation.- Parameters:
writer
- the delegated writer to append characters.mapper
- the mapper to extract values from tags- Returns:
- a newly generated tag writer.
-
isUnquoted
Check if the provided string should be unquoted.- Parameters:
s
- the string to check.- Returns:
- true if the string is unquoted, false otherwise.
-
isUnquoted
protected boolean isUnquoted(char c) Check if the provided char is an allowed unquoted character.- Parameters:
c
- the char to check.- Returns:
- true if the char should be unquoted, false otherwise.
-
getWriter
Get the delegated writer.- Returns:
- a writer that is used to append characters.
-
getMapper
Get the mapper that is used to extract values.- Returns:
- a tag mapper.
-
writeTag
Write to provided tag object.- Parameters:
t
- the tag object to write.- Throws:
IOException
- if any I/O exception occurs.
-
writePrimitiveTag
public <V> void writePrimitiveTag(@NotNull @NotNull TagType<V> type, @NotNull V v) throws IOException Write to provided primitive tag value with associated type.- Type Parameters:
V
- the nbt-represented value type implementation.- Parameters:
type
- the type of tag.v
- the tag value to write.- Throws:
IOException
- if any I/O exception occurs.
-
writeStringTag
Write string tag value, any"
will be replaced with\"
to match SNBT compatibility.- Parameters:
s
- the tag value to write.- Throws:
IOException
- if any I/O exception occurs.
-
writeByteArrayTag
Write byte array tag value.- Parameters:
bytes
- the tag value to write.- Throws:
IOException
- if any I/O exception occurs.
-
writeBooleanArrayTag
Write fake boolean array tag value.- Parameters:
booleans
- the tag value to write.- Throws:
IOException
- if any I/O exception occurs.
-
writeIntArrayTag
Write int array tag value.- Parameters:
ints
- the tag value to write.- Throws:
IOException
- if any I/O exception occurs.
-
writeLongArrayTag
Write long array tag value.- Parameters:
longs
- the tag value to write.- Throws:
IOException
- if any I/O exception occurs.
-
writeListTag
Write list of tag objects value from list tag type.- Parameters:
list
- the tag value to write.- Throws:
IOException
- if any I/O exception occurs.
-
writeCompoundTag
Write map of string-tag entries value from compound tag type.- Parameters:
map
- the tag value to write.- Throws:
IOException
- if any I/O exception occurs.
-
write
public void write(@NotNull @org.jetbrains.annotations.NotNull char[] cbuf, int off, int len) throws IOException - Specified by:
write
in classWriter
- Throws:
IOException
-
flush
- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in classWriter
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classWriter
- Throws:
IOException
-
toString
Convert nbt-represented java object into SNBT.- Parameters:
object
- the nbt-represented java object to convert.- Returns:
- a SNBT that represent the java object.
-
toString
@NotNull public static <T> @NotNull String toString(@Nullable T t, @NotNull @NotNull TagMapper<T> mapper) Convert tag object into SNBT with providedTagMapper
.- Type Parameters:
T
- the tag object implementation.- Parameters:
t
- the tag object to convert.mapper
- the mapper to extract value from tag.- Returns:
- a SNBT that represent the tag object.
-