I needed to combine to inpustreams, which one has only string and the other one is an avi file. I can easily combine two of them like below:
InputStream is = new SequenceInputStream(stringStream, aviStream);
However, when it comes to take the string and the avi separately, I am failing. The avi file does not match to its first size and somehow I am losing some size.
I can read is with a Scanner by using a delimiter, but in that case the avi stream will be String and i will lose information.
Any idea how can I separate the inputstream? I want to read back my string and i should have the rest of the stream as an inpustream.
EDIT: I am thinking of converting the stream to a byte array, then divide the array into two according to the delimiter. Then second part, which is the avi one, i can convert it back to an inputstream. But it seems to troublesome.
A Scanner is only for text data, not binary. Binary data e.g. AVI can contain every byte value which means there is no delimiter you can use which will not appear in the data.
You can combine text with raw data in the following manner.
to reverse the process you can use DataInputStream with readUTF, readInt and readFully()