public static MultiMessage decode(ByteArray encodedMessages, TempFileContext tempFileContext) throws IOException {
		if(encodedMessages.size == 0) return EMPTY_MULTI_MESSAGE;

		try (DataInputStream in = new DataInputStream(new AoByteArrayInputStream(encodedMessages.array))) {
			int totalRead = 0;
			final int size = in.readInt();
			totalRead += 4;
			List<Message> decodedMessages = new ArrayList<>(size);
			for(int i=0; i<size; i++) {
				MessageType type = MessageType.getFromTypeByte(in.readByte());
				totalRead++;
				final int capacity = in.readInt();
				totalRead += 4;
				byte[] encodedMessage = new byte[capacity];
				in.readFully(encodedMessage, 0, capacity);
				totalRead += capacity;
				decodedMessages.add(type.decode(new ByteArray(encodedMessage, capacity), tempFileContext));
			}
			if(totalRead != encodedMessages.size) throw new IllegalArgumentException("totalRead != encodedMessages.size");
			return new MultiMessage(Collections.unmodifiableList(decodedMessages));
		}
	}
public static MultiMessage decode ( ByteArray encodedMessages , TempFileContext tempFileContext ) throws IOException { if ( encodedMessages . size == 0 ) return EMPTY_MULTI_MESSAGE ; try ( DataInputStream in = new DataInputStream ( new AoByteArrayInputStream ( encodedMessages . array ) ) ) { int totalRead = 0 ; final int size = in . readInt ( ) ; totalRead += 4 ; List < Message > decodedMessages = new ArrayList < > ( size ) ; for ( int i = 0 ; i < size ; i ++ ) { MessageType type = MessageType . getFromTypeByte ( in . readByte ( ) ) ; totalRead ++ ; final int capacity = in . readInt ( ) ; totalRead += 4 ; byte [ ] encodedMessage = new byte [ capacity ] ; in . readFully ( encodedMessage , 0 , capacity ) ; totalRead += capacity ; decodedMessages . add ( type . decode ( new ByteArray ( encodedMessage , capacity ) , tempFileContext ) ) ; } if ( totalRead != encodedMessages . size ) throw new IllegalArgumentException ( "totalRead != encodedMessages.size" ) ; return new MultiMessage ( Collections . unmodifiableList ( decodedMessages ) ) ; } }
Decodes the messages using the provided {@link TempFileContext temporary file context}.