3
I am creating an application in which I need to read from a video file and transmit packets of data that can be read again in memory. I am using the Ogg video format, because it is open source and because I found it simpler to understand. I used the BufferedInputStream
to read from the file, but since the first 28 bytes are header information I chose to use the method buffer.read(byte[])
as follows:
byte[] buffer = new byte[28];
FileInputStream in = new FileInputStream("/path/video.ogv");
BufferedInputStream buffStream = new BufferedInputStream(in);
buffStream(buffer);
Thus, I can read a sequence of bytes faster. When inspecting the element buffer
in the eclipse debug, I noticed that values above 128 are negative, this, I believe, is due to the fact that the maximum number I can represent with 1 byte is 128. I know that the values are corrupted because when opening the file on https://hexed.it, i can visualize the correct value in hexadecimal. For example, the value that corresponds to B5 = 181(dec)
is as -75. How can I use this method and bypass this data corruption?
Obs.: Using a video decoder that already does this transparently is not an option. It is necessary to be this way because I am developing a distributed application and the data packets will be destined to other computers.
Thank you very much for the clarification.
– Rodrigo Brito
@Rodrigobrito If this answer solved your problem and there was no doubt left, I ask you to mark it as accepted/correct by clicking below the vote number.
– Victor Stafusa
@Carlosheuberger Yes. Thank you for the suggestion. In fact, that’s exactly what I had put into the method
formarByte
.– Victor Stafusa