I'm trying to validate an incoming image in an FTP folder. The images begin with the "FFD8" bytes and end with the "FFD9" sequence so that you can perform the scan.
I'm getting the image in a BufferedImage
and converting it to an array of bytes, however, when accessing the initial positions of this array never match the value of FFD8, I get values like 001F 0019. I performed the verification of these same files in editors as sublimetext and some hexdumps and in them the start and end bytes correspond with the correct value "FFD8" (Initial) and "FFD9" (Final). In this small snippet of code I'm concatenating everything in StringBuilder
. What could I be doing wrong?
void startProcessBloco(){
int qtdBloco = 0;
File fList[] = diretorio.listFiles();
for ( int i = 0; i < fList.length; i++ ){
//Validação verificando se o vetor não é nulo
if(fList.length > i + 3){
if(fList[i].getName().contains("_1") && fList[i+3].getName().contains("_4")){
try {
File imagemFisica = new File(dir+fList[i].getName());
BufferedImage imagemEmBuffer = ImageIO.read(imagemFisica);
byte[] imagemEmBytes = bloco.extractBytes(imagemEmBuffer);
bloco.getImagens().add(imagemEmBuffer);
StringBuilder sb = new StringBuilder();
for (byte b : imagemEmBytes) {
sb.append(String.format("%04X ", b));
}
System.out.println(sb.toString());
ImageIO.write(imagemEmBuffer, "jpg",
new File("D:\testesBlocoFtp\recebeImg\" + fList[i].getName()));
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
System.out.println(qtdBloco);
}