/*
 * Decompiled with CFR 0.152.
 */
package com.evilco.mc.nbt.tag;

import com.evilco.mc.nbt.stream.NbtInputStream;
import com.evilco.mc.nbt.stream.NbtOutputStream;
import com.evilco.mc.nbt.tag.AbstractTag;
import com.evilco.mc.nbt.tag.TagType;
import com.google.common.base.Preconditions;
import java.io.IOException;
import javax.annotation.Nonnull;

public class TagByteArray
extends AbstractTag {
    protected byte[] value;

    public TagByteArray(@Nonnull String name, @Nonnull byte[] value) {
        super(name);
        this.setValue(value);
    }

    public TagByteArray(@Nonnull NbtInputStream inputStream, boolean anonymous) throws IOException {
        super(inputStream, anonymous);
        int size = inputStream.readInt();
        byte[] data = new byte[size];
        inputStream.readFully(data);
        this.setValue(data);
    }

    @Override
    public byte getTagID() {
        return TagType.BYTE_ARRAY.typeID;
    }

    public byte[] getValue() {
        return this.value;
    }

    public void setValue(@Nonnull byte[] b) {
        Preconditions.checkNotNull(b, "b");
        this.value = b;
    }

    @Override
    public void write(NbtOutputStream outputStream, boolean anonymous) throws IOException {
        super.write(outputStream, anonymous);
        outputStream.writeInt(this.value.length);
        outputStream.write(this.value);
    }
}
