private Tag readTagPayload(int type,int depth) throws IOException {
switch (type) {
case NBTConstants.TYPE_END:
    if (depth == 0) {
      throw new IOException("TAG_End found without a TAG_Compound/TAG_List tag preceding it.");
    }
 else {
      return new EndTag();
    }
case NBTConstants.TYPE_BYTE:
  return new ByteTag(is.readByte());
case NBTConstants.TYPE_SHORT:
return new ShortTag(is.readShort());
case NBTConstants.TYPE_INT:
return new IntTag(is.readInt());
case NBTConstants.TYPE_LONG:
return new LongTag(is.readLong());
case NBTConstants.TYPE_FLOAT:
return new FloatTag(is.readFloat());
case NBTConstants.TYPE_DOUBLE:
return new DoubleTag(is.readDouble());
case NBTConstants.TYPE_BYTE_ARRAY:
int length=is.readInt();
byte[] bytes=new byte[length];
is.readFully(bytes);
return new ByteArrayTag(bytes);
case NBTConstants.TYPE_STRING:
length=is.readShort();
bytes=new byte[length];
is.readFully(bytes);
return new StringTag(new String(bytes,NBTConstants.CHARSET));
case NBTConstants.TYPE_LIST:
int childType=is.readByte();
length=is.readInt();
List<Tag> tagList=new ArrayList<Tag>();
for (int i=0; i < length; ++i) {
Tag tag=readTagPayload(childType,depth + 1);
if (tag instanceof EndTag) {
throw new IOException("TAG_End not permitted in a list.");
}
tagList.add(tag);
}
return new ListTag(NBTUtils.getTypeClass(childType),tagList);
case NBTConstants.TYPE_COMPOUND:
Map<String,Tag> tagMap=new HashMap<String,Tag>();
while (true) {
NamedTag namedTag=readNamedTag(depth + 1);
Tag tag=namedTag.getTag();
if (tag instanceof EndTag) {
break;
}
 else {
tagMap.put(namedTag.getName(),tag);
}
}
return new CompoundTag(tagMap);
case NBTConstants.TYPE_INT_ARRAY:
length=is.readInt();
int[] data=new int[length];
for (int i=0; i < length; i++) {
data[i]=is.readInt();
}
return new IntArrayTag(data);
default :
throw new IOException("Invalid tag type: " + type + ".");
}
}

private Tag readTagPayload ( int type , int depth ) throws IOException { switch ( type ) { case NBTConstants . TYPE_END : if ( depth == 0 ) { throw new IOException ( "TAG_End found without a TAG_Compound/TAG_List tag preceding it." ) ; } else { return new EndTag ( ) ; } case NBTConstants . TYPE_BYTE : return new ByteTag ( is . readByte ( ) ) ; case NBTConstants . TYPE_SHORT : return new ShortTag ( is . readShort ( ) ) ; case NBTConstants . TYPE_INT : return new IntTag ( is . readInt ( ) ) ; case NBTConstants . TYPE_LONG : return new LongTag ( is . readLong ( ) ) ; case NBTConstants . TYPE_FLOAT : return new FloatTag ( is . readFloat ( ) ) ; case NBTConstants . TYPE_DOUBLE : return new DoubleTag ( is . readDouble ( ) ) ; case NBTConstants . TYPE_BYTE_ARRAY : int length = is . readInt ( ) ; byte [ ] bytes = new byte [ length ] ; is . readFully ( bytes ) ; return new ByteArrayTag ( bytes ) ; case NBTConstants . TYPE_STRING : length = is . readShort ( ) ; bytes = new byte [ length ] ; is . readFully ( bytes ) ; return new StringTag ( new String ( bytes , NBTConstants . CHARSET ) ) ; case NBTConstants . TYPE_LIST : int childType = is . readByte ( ) ; length = is . readInt ( ) ; List < Tag > tagList = new ArrayList < Tag > ( ) ; for ( int i = 0 ; i < length ; ++ i ) { Tag tag = readTagPayload ( childType , depth + 1 ) ; if ( tag instanceof EndTag ) { throw new IOException ( "TAG_End not permitted in a list." ) ; } tagList . add ( tag ) ; } return new ListTag ( NBTUtils . getTypeClass ( childType ) , tagList ) ; case NBTConstants . TYPE_COMPOUND : Map < String , Tag > tagMap = new HashMap < String , Tag > ( ) ; while ( true ) { NamedTag namedTag = readNamedTag ( depth + 1 ) ; Tag tag = namedTag . getTag ( ) ; if ( tag instanceof EndTag ) { break ; } else { tagMap . put ( namedTag . getName ( ) , tag ) ; } } return new CompoundTag ( tagMap ) ; case NBTConstants . TYPE_INT_ARRAY : length = is . readInt ( ) ; int [ ] data = new int [ length ] ; for ( int i = 0 ; i < length ; i ++ ) { data [ i ] = is . readInt ( ) ; } return new IntArrayTag ( data ) ; default : throw new IOException ( "Invalid tag type: " + type + "." ) ; } }
reads the payload of a tag given the type .
