3
I am trying to validate an incoming image in an FTP folder. The images start with the bytes "FFD8" and end with the sequence "FFD9" so that there is the possibility to perform the check.
I’m getting the picture on BufferedImage
and converting to an array of bytes, however, when access to the initial positions of this array never corresponds to the value of FFD8, I receive values like 001F 0019. I performed the verification of these same files in editors like sublimetext and some hexdumps and in them the initial and final bytes correspond with the correct value "FFD8" (Initial) and "FFD9" (Final). In this little bit of code I’m concatenating everything into one 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);
}
It helped a lot, from his reply I started thinking in a different direction and after researching a little more, I found two libraries that fell like a glove .
– Cadudragon