Oi pessoal! Estou com o seguinte problema: eu tenho um arquivo que está em binários de 0 à 256. cada quebra de linha acontece no com o char 10, então eu formo uma linha a sempre q encontro o caracter 10. E quando eu encontro o caracter 26, eu sei q o cabeçalho do meu arquivo terminou pra começar uma imagem. Isso foi definido.
porém, quando eu chamo o função readCharLine(), entra numa recursão, como eu quero, mas o programa soh faz 16 vezes e não até o final do arquivo, pois dah StackOverflow…
Alguém pode me ajudar?
public class ReadingMethods {
public void readHeaderLine (RandomAccessFile fis) throws IOException {
int s=0;
String thisString="";
char thisChar = (char) fis.read();
while ((thisChar != 13) && (thisChar != 0)) {
if (thisChar!=10){
thisString=thisString+thisChar;
}
thisChar = (char) fis.read();
}
s=(int)thisString.charAt(thisString.length()-1);
System.out.println(thisString);
readHeader(fis, s);
}
public void readHeader (RandomAccessFile fis, int s) throws IOException{
if (s==26){
readCharLine(fis);
}
else{
readHeaderLine(fis);
}
}
public void readCharLine(RandomAccessFile fis) throws IOException {
char thisChar = (char) fis.read();
String hex;
int bin;
hex = Integer.toHexString((int)thisChar);
bin = (int)thisChar;
System.out.print(hex+" ");
System.out.println(bin);
readMap(fis, bin);
}
public void readMap (RandomAccessFile fis, int s) throws IOException{
if (s==0){
System.out.println();
System.out.println();
System.out.println();
System.out.println();
readCharLine(fis); // faz 16 vezes e depois dah StackOverflowError
}
else{
readCharLine(fis);
}
}
}