phpamble
asked on
Modified Read Procedure For An InputStream
I previously submitted a question that was excellently answered by CEHJ regarding reading bytes from an inputstream and writing them to a suitable buffer structure.
However I have one further modification I want to make namely the following:
The length of bytes I want to read from a file is unknown when I issue the request to read. The only known is that all the bytes must be read up to the start of of a sequence of 7 bytes.
Is it possible to modify your code above to do this. I have been looking at using the read method of an input stream that reads and returns a single byte at a time and then build the logic around iterations of this. Is there a smarter way to do this?
However I have one further modification I want to make namely the following:
The length of bytes I want to read from a file is unknown when I issue the request to read. The only known is that all the bytes must be read up to the start of of a sequence of 7 bytes.
Is it possible to modify your code above to do this. I have been looking at using the read method of an input stream that reads and returns a single byte at a time and then build the logic around iterations of this. Is there a smarter way to do this?
What is that 'sequence of 7 bytes'?
ASKER
In hex values: 69 73 6F 6D 33 67 70
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Stunning, Thanks, I am also posting another question for how this can be done in J2ME if this can be done?
ASKER
:-)
ASKER
final int BUF_SIZE = 1 << 10 << 3;// 8 KiB buffer
int bytesRead = -1;
byte[] buffer= new byte[BUF_SIZE];
ByteArrayOutputStream out = new ByteArrayOutputStream();
while ((bytesRead = in.read(buffer)) > -1) { // read from the input stream
out.write(buffer, 0, bytesRead);
}
in.close();
callPlayerMethod(out.toByt