Link to home
Start Free TrialLog in
Avatar of phpamble
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?
Avatar of phpamble
phpamble

ASKER

The code given by CEHJ and referred to above is as follows:

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.toByteArray());
Avatar of CEHJ
What is that 'sequence of 7 bytes'?
In hex values: 69 73 6F 6D 33 67 70
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Stunning, Thanks, I am also posting another question for how this can be done in J2ME if this can be done?
:-)