cn.nukkit.nbt.stream.NBTInputStream Java Examples

The following examples show how to use cn.nukkit.nbt.stream.NBTInputStream. 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: 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 #2
Source File: Tag.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public static Tag readNamedTag(NBTInputStream dis) throws IOException {
    byte type = dis.readByte();
    if (type == 0) return new EndTag();

    String name = dis.readUTF();

    Tag tag = newTag(type, name);

    tag.load(dis);
    return tag;
}
 
Example #3
Source File: ListTag.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
void load(NBTInputStream dis) throws IOException {
    type = dis.readByte();
    int size = dis.readInt();

    list = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        Tag tag = Tag.newTag(type, null);
        tag.load(dis);
        tag.setName("");
        list.add((T) tag);
    }
}
 
Example #4
Source File: NBTIO.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public static CompoundTag read(InputStream inputStream, ByteOrder endianness, boolean network) throws IOException {
    try (NBTInputStream stream = new NBTInputStream(inputStream, endianness, network)) {
        Tag tag = Tag.readNamedTag(stream);
        if (tag instanceof CompoundTag) {
            return (CompoundTag) tag;
        }
        throw new IOException("Root tag must be a named compound tag");
    }
}
 
Example #5
Source File: CompoundTag.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void load(NBTInputStream dis) throws IOException {
    tags.clear();
    Tag tag;
    while ((tag = Tag.readNamedTag(dis)).getId() != Tag.TAG_End) {
        tags.put(tag.getName(), tag);
    }
}
 
Example #6
Source File: IntArrayTag.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
void load(NBTInputStream dis) throws IOException {
    int length = dis.readInt();
    data = new int[length];
    for (int i = 0; i < length; i++) {
        data[i] = dis.readInt();
    }
}
 
Example #7
Source File: IntArrayTag.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
void load(NBTInputStream dis) throws IOException {
    int length = dis.readInt();
    data = new int[length];
    for (int i = 0; i < length; i++) {
        data[i] = dis.readInt();
    }
}
 
Example #8
Source File: CompoundTag.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void load(NBTInputStream dis) throws IOException {
    tags.clear();
    Tag tag;
    while ((tag = Tag.readNamedTag(dis)).getId() != Tag.TAG_End) {
        tags.put(tag.getName(), tag);
    }
}
 
Example #9
Source File: NBTIO.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public static CompoundTag read(InputStream inputStream, ByteOrder endianness, boolean network) throws IOException {
    try (NBTInputStream stream = new NBTInputStream(inputStream, endianness, network)) {
        Tag tag = Tag.readNamedTag(stream);
        if (tag instanceof CompoundTag) {
            return (CompoundTag) tag;
        }
        throw new IOException("Root tag must be a named compound tag");
    }
}
 
Example #10
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 #11
Source File: Tag.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public static Tag readNamedTag(NBTInputStream dis) throws IOException {
    byte type = dis.readByte();
    if (type == 0) return new EndTag();

    String name = dis.readUTF();

    Tag tag = newTag(type, name);

    tag.load(dis);
    return tag;
}
 
Example #12
Source File: ListTag.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
void load(NBTInputStream dis) throws IOException {
    type = dis.readByte();
    int size = dis.readInt();

    list = new ArrayList<>();
    for (int i = 0; i < size; i++) {
        Tag tag = Tag.newTag(type, null);
        tag.load(dis);
        list.add((T) tag);
    }
}
 
Example #13
Source File: ListTag.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
void load(NBTInputStream dis) throws IOException {
    type = dis.readByte();
    int size = dis.readInt();

    list = new ArrayList<>();
    for (int i = 0; i < size; i++) {
        Tag tag = Tag.newTag(type, null);
        tag.load(dis);
        list.add((T) tag);
    }
}
 
Example #14
Source File: Tag.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public static Tag readNamedTag(NBTInputStream dis) throws IOException {
    byte type = dis.readByte();
    if (type == 0) return new EndTag();

    String name = dis.readUTF();

    Tag tag = newTag(type, name);

    tag.load(dis);
    return tag;
}
 
Example #15
Source File: IntArrayTag.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
void load(NBTInputStream dis) throws IOException {
    int length = dis.readInt();
    data = new int[length];
    for (int i = 0; i < length; i++) {
        data[i] = dis.readInt();
    }
}
 
Example #16
Source File: CompoundTag.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void load(NBTInputStream dis) throws IOException {
    tags.clear();
    Tag tag;
    while ((tag = Tag.readNamedTag(dis)).getId() != Tag.TAG_End) {
        tags.put(tag.getName(), tag);
    }
}
 
Example #17
Source File: LongTag.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
void load(NBTInputStream dis) throws IOException {
    data = dis.readLong();
}
 
Example #18
Source File: StringTag.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
void load(NBTInputStream dis) throws IOException {
    data = dis.readUTF();
}
 
Example #19
Source File: EndTag.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
void load(NBTInputStream dis) throws IOException {
}
 
Example #20
Source File: IntTag.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
void load(NBTInputStream dis) throws IOException {
    data = dis.readInt();
}
 
Example #21
Source File: LongTag.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
void load(NBTInputStream dis) throws IOException {
    data = dis.readLong();
}
 
Example #22
Source File: IntTag.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
void load(NBTInputStream dis) throws IOException {
    data = dis.readInt();
}
 
Example #23
Source File: ByteArrayTag.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
void load(NBTInputStream dis) throws IOException {
    int length = dis.readInt();
    data = new byte[length];
    dis.readFully(data);
}
 
Example #24
Source File: ByteTag.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
void load(NBTInputStream dis) throws IOException {
    data = dis.readByte();
}
 
Example #25
Source File: FloatTag.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
void load(NBTInputStream dis) throws IOException {
    data = dis.readFloat();
}
 
Example #26
Source File: EndTag.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
void load(NBTInputStream dis) throws IOException {
}
 
Example #27
Source File: DoubleTag.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
void load(NBTInputStream dis) throws IOException {
    data = dis.readDouble();
}
 
Example #28
Source File: StringTag.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
void load(NBTInputStream dis) throws IOException {
    data = dis.readUTF();
}
 
Example #29
Source File: ShortTag.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
void load(NBTInputStream dis) throws IOException {
    data = dis.readUnsignedShort();
}
 
Example #30
Source File: EndTag.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@Override
void load(NBTInputStream dis) throws IOException {
}