cn.nukkit.nbt.stream.NBTOutputStream Java Examples

The following examples show how to use cn.nukkit.nbt.stream.NBTOutputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NBTIO.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public static byte[] write(Collection<CompoundTag> tags, ByteOrder endianness, boolean network) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try (NBTOutputStream stream = new NBTOutputStream(baos, endianness, network)) {
        for (CompoundTag tag : tags) {
            Tag.writeNamedTag(tag, stream);
        }
        return baos.toByteArray();
    }
}
 
Example #2
Source File: Chunk.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BaseChunk clone() {
    Chunk chunk = (Chunk) super.clone();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    NBTOutputStream out = new NBTOutputStream(baos);
    try {
        nbt.write(out);
        NBTInputStream in = new NBTInputStream(new ByteArrayInputStream(baos.toByteArray()));
        chunk.nbt = new CompoundTag();
        chunk.nbt.load(in);
    } catch (IOException e) {

    }
    return chunk;
}
 
Example #3
Source File: Tag.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public static void writeNamedTag(Tag tag, NBTOutputStream dos) throws IOException {
    dos.writeByte(tag.getId());
    if (tag.getId() == Tag.TAG_End) return;
    dos.writeUTF(tag.getName());

    tag.write(dos);
}
 
Example #4
Source File: ListTag.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
void write(NBTOutputStream dos) throws IOException {
    if (list.size() > 0) type = list.get(0).getId();
    else type = 1;

    dos.writeByte(type);
    dos.writeInt(list.size());
    for (T aList : list) aList.write(dos);
}
 
Example #5
Source File: CompoundTag.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void write(NBTOutputStream dos) throws IOException {
    for (Tag tag : tags.values()) {
        Tag.writeNamedTag(tag, dos);
    }
    dos.writeByte(Tag.TAG_End);
}
 
Example #6
Source File: IntArrayTag.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
void write(NBTOutputStream dos) throws IOException {
    dos.writeInt(data.length);
    for (int aData : data) {
        dos.writeInt(aData);
    }
}
 
Example #7
Source File: ByteArrayTag.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
void write(NBTOutputStream dos) throws IOException {
    if (data == null) {
        dos.writeInt(0);
        return;
    }
    dos.writeInt(data.length);
    dos.write(data);
}
 
Example #8
Source File: Tag.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public static void writeNamedTag(Tag tag, String name, NBTOutputStream dos) throws IOException {
    dos.writeByte(tag.getId());
    if (tag.getId() == Tag.TAG_End) return;
    dos.writeUTF(name);

    tag.write(dos);
}
 
Example #9
Source File: ListTag.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
void write(NBTOutputStream dos) throws IOException {
    if (list.size() > 0) type = list.get(0).getId();
    else type = 1;

    dos.writeByte(type);
    dos.writeInt(list.size());
    for (T aList : list) aList.write(dos);
}
 
Example #10
Source File: CompoundTag.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void write(NBTOutputStream dos) throws IOException {

    for (Map.Entry<String, Tag> entry : this.tags.entrySet()) {
        Tag.writeNamedTag(entry.getValue(), entry.getKey(), dos);
    }

    dos.writeByte(Tag.TAG_End);
}
 
Example #11
Source File: IntArrayTag.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
void write(NBTOutputStream dos) throws IOException {
    dos.writeInt(data.length);
    for (int aData : data) {
        dos.writeInt(aData);
    }
}
 
Example #12
Source File: ByteArrayTag.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
void write(NBTOutputStream dos) throws IOException {
    if (data == null) {
        dos.writeInt(0);
        return;
    }
    dos.writeInt(data.length);
    dos.write(data);
}
 
Example #13
Source File: NBTIO.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public static byte[] writeNetwork(Tag tag) throws IOException {
    FastByteArrayOutputStream baos = ThreadCache.fbaos.get().reset();
    try (NBTOutputStream stream = new NBTOutputStream(baos, ByteOrder.LITTLE_ENDIAN, true)) {
        Tag.writeNamedTag(tag, stream);
    }
    return baos.toByteArray();
}
 
Example #14
Source File: NBTIO.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public static byte[] write(Collection<CompoundTag> tags, ByteOrder endianness, boolean network) throws IOException {
    FastByteArrayOutputStream baos = ThreadCache.fbaos.get().reset();
    try (NBTOutputStream stream = new NBTOutputStream(baos, endianness, network)) {
        for (CompoundTag tag : tags) {
            Tag.writeNamedTag(tag, stream);
        }
        return baos.toByteArray();
    }
}
 
Example #15
Source File: NBTIO.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public static byte[] write(Tag tag, ByteOrder endianness, boolean network) throws IOException {
    FastByteArrayOutputStream baos = ThreadCache.fbaos.get().reset();
    try (NBTOutputStream stream = new NBTOutputStream(baos, endianness, network)) {
        Tag.writeNamedTag(tag, stream);
        return baos.toByteArray();
    }
}
 
Example #16
Source File: Chunk.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BaseChunk clone() {
    Chunk chunk = (Chunk) super.clone();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    NBTOutputStream out = new NBTOutputStream(baos);
    try {
        nbt.write(out);
        NBTInputStream in = new NBTInputStream(new ByteArrayInputStream(baos.toByteArray()));
        chunk.nbt = new CompoundTag();
        chunk.nbt.load(in);
    } catch (IOException e) {

    }
    return chunk;
}
 
Example #17
Source File: NBTIO.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public static byte[] write(CompoundTag tag, ByteOrder endianness, boolean network) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try (NBTOutputStream stream = new NBTOutputStream(baos, endianness, network)) {
        Tag.writeNamedTag(tag, stream);
        return baos.toByteArray();
    }
}
 
Example #18
Source File: Tag.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public static void writeNamedTag(Tag tag, NBTOutputStream dos) throws IOException {
    dos.writeByte(tag.getId());
    if (tag.getId() == Tag.TAG_End) return;
    dos.writeUTF(tag.getName());

    tag.write(dos);
}
 
Example #19
Source File: CompoundTag.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void write(NBTOutputStream dos) throws IOException {
    for (Tag tag : tags.values()) {
        Tag.writeNamedTag(tag, dos);
    }
    dos.writeByte(Tag.TAG_End);
}
 
Example #20
Source File: ListTag.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
void write(NBTOutputStream dos) throws IOException {
    if (list.size() > 0) type = list.get(0).getId();
    else type = 1;

    dos.writeByte(type);
    dos.writeInt(list.size());
    for (T aList : list) aList.write(dos);
}
 
Example #21
Source File: ByteArrayTag.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
void write(NBTOutputStream dos) throws IOException {
    if (data == null) {
        dos.writeInt(0);
        return;
    }
    dos.writeInt(data.length);
    dos.write(data);
}
 
Example #22
Source File: IntArrayTag.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
void write(NBTOutputStream dos) throws IOException {
    dos.writeInt(data.length);
    for (int aData : data) {
        dos.writeInt(aData);
    }
}
 
Example #23
Source File: LongTag.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
void write(NBTOutputStream dos) throws IOException {
    dos.writeLong(data);
}
 
Example #24
Source File: EndTag.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
void write(NBTOutputStream dos) throws IOException {
}
 
Example #25
Source File: IntTag.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
void write(NBTOutputStream dos) throws IOException {
    dos.writeInt(data);
}
 
Example #26
Source File: FloatTag.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
void write(NBTOutputStream dos) throws IOException {
    dos.writeFloat(data);
}
 
Example #27
Source File: FloatTag.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@Override
void write(NBTOutputStream dos) throws IOException {
    dos.writeFloat(data);
}
 
Example #28
Source File: DoubleTag.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
void write(NBTOutputStream dos) throws IOException {
    dos.writeDouble(data);
}
 
Example #29
Source File: StringTag.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
void write(NBTOutputStream dos) throws IOException {
    dos.writeUTF(data);
}
 
Example #30
Source File: ShortTag.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
void write(NBTOutputStream dos) throws IOException {
    dos.writeShort(data);
}