In my application, I fetch multiple audio (mp3) files from a server and get them as input stream or byte array. I convert them to a list of AudioInputStreams then and at the moment concat the data to one large ByteArrayInputStream. I then convert that to an AudioInputStream again and provide the data in it (byte[]) through a REST endpoint. My frontend is a react application where users can listen to it and download it.
Unfortunately, this process seems to break the mp3 header and the length is wrong. My frontend player does play the file to the end, so generally, the process is even working, but if I download it as a file the length is always the same as from the first file I concatenated in backend and some audio players won't even play to the end.
The question is: how to concat two mp3 byte-arrays properly in java?