This commit is contained in:
Jesse Boyd
2019-06-29 04:20:48 +10:00
parent f1e98da01f
commit 58c6b6278f
12 changed files with 121 additions and 61 deletions

View File

@ -19,6 +19,8 @@
package com.sk89q.jnbt;
import com.boydti.fawe.object.io.LittleEndianOutputStream;
import static com.google.common.base.Preconditions.checkNotNull;
import java.io.Closeable;
@ -66,6 +68,15 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
return os;
}
/**
* Use a little endian output stream
*/
public void setLittleEndian() {
if (!(os instanceof LittleEndianOutputStream)) {
this.os = new LittleEndianOutputStream((OutputStream) os);
}
}
/**
* Writes a tag.
*
@ -79,11 +90,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
checkNotNull(tag);
int type = NBTUtils.getTypeCode(tag.getClass());
byte[] nameBytes = name.getBytes(NBTConstants.CHARSET);
os.writeByte(type);
os.writeShort(nameBytes.length);
os.write(nameBytes);
writeNamedTagName(name, type);
if (type == NBTConstants.TYPE_END) {
throw new IOException("Named TAG_End not permitted.");