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
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidflush()Get the mapper that is used to extract values.Get the delegated writer.protected booleanisUnquoted(char c) Check if the provided char is an allowed unquoted character.protected booleanCheck 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.voidvoidwriteBooleanArrayTag(boolean[] booleans) Write fake boolean array tag value.voidwriteByteArrayTag(byte[] bytes) Write byte array tag value.voidwriteCompoundTag(@NotNull Map<String, T> map) Write map of string-tag entries value from compound tag type.voidwriteIntArrayTag(int[] ints) Write int array tag value.voidwriteListTag(@NotNull List<T> list) Write list of tag objects value from list tag type.voidwriteLongArrayTag(long[] longs) Write long array tag value.<V> voidwritePrimitiveTag(@NotNull TagType<V> type, V v) Write to provided primitive tag value with associated type.voidWrite string tag value, any"will be replaced with\"to match SNBT compatibility.voidWrite to provided tag object.
-
Constructor Details
-
TagWriter
-
-
Method Details
-
of
-
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
-
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
-
getMapper
-
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
- Specified by:
writein classWriter- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Specified by:
flushin classWriter- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException
-
toString
-
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.
-