phpamble
asked on
Modified Read Procedure For An InputStream In J2ME
I had a question answered with some brilliant code from CEHJ regarding how bytes can be read (in Java) from an input stream up to a certain sequence of bytes. I am also needing to do this in J2ME.
So this question is really for CEHJ is there a similar way to do this in J2ME?
So this question is really for CEHJ is there a similar way to do this in J2ME?
public static void main(String[] args) throws Exception {
byte[] search = { (byte)0x69, (byte)0x73, (byte)0x6F, (byte)0x6D, (byte)0x33, (byte)0x67, (byte)0x70 }; byte[] matcher = new byte[search.length];
ByteArrayOutputStream out = new ByteArrayOutputStream();
PushbackInputStream in = new PushbackInputStream(new FileInputStream(args[0]), search.length); int c = -1;
while ((c = in.read()) > -1) {
if (c == search[0]) {
in.unread(c);
in.read(matcher);
System.out.println(new String(matcher));
if (Arrays.equals(search, matcher)) {
// Found pattern
in.unread(matcher);
break;
}
else {
out.write(matcher);
}
}
out.write(c);
}
in.close();
System.out.printf("'%s'", new String(out.toByteArray()));
}
Ah. In that case, you could try it using mark and reset on BufferedInputStream. Does it have that class?
ASKER
Unfortunately no BufferedInputStream in CLDC.
ASKER
But it does have DataInputStream that supports mark() and reset().
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank You
:-)
ASKER