0

Currently i have byte array. Which contains a .jpg file also some other unwanted data.

What I wanted to do is to find out the position of data "FF D8" (start of JPEG data).

Same Code in iOS is : https://stackoverflow.com/a/18477915/5215474

Community
  • 1
  • 1
Saranjith
  • 11,242
  • 5
  • 69
  • 122

1 Answers1

3

This is trivial to implement in Java.

int position = -1;

for (int i = 0; i < bytes.length - 2; i++) {
    if (bytes[i] == (byte) 0xff && bytes[i + 1] == (byte) 0xdf) {
        position = i;
        break;
    }
}
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216