archive file in image

ah-blabla

New Member
Messages
375
Reaction score
7
Points
0
"illegal start of expression" and "; expected" when trying that.

Edit: You do mean
Code:
if(archiveType.equals("rar")){
                    // Identify rar
                    out.write(new byte[] {(byte)0x58,(byte)0x59,(byte)0x12,(byte)0xA2});
                } else if(archiveType.equals("zip")) {
                    // Identify zip
                    out.write(new byte[] {(byte)0x58,(byte)0x59,(byte)0x12,(byte)0xA3});
                }
right? Because now it works xD
Doh... I wasn't thinking clearly... But you got it to work, so aim achieved.;)
 

galaxyAbstractor

Community Advocate
Community Support
Messages
5,508
Reaction score
35
Points
48
k I'm getting some weird issue again :/

Code:
public boolean isArchive(String input){

                        InputStream inFile = null;
                        //Initialise the value of 'valid' to false
                        boolean valid = false;
                        //This is the signature every file should have
                        int[] filesigrar = {0x58, 0x59, 0x12, 0xA2};
                        int[] filesigzip = {0x58, 0x59, 0x12, 0xA3};
                        try {
                            inFile = new FileInputStream(input);
                            //Go to the last 4 bytes
                            inFile.skip(input.length() - 4);
                            //Compare each of the last 4 bytes to the expected signatures
                            for(int i=0; i<4; i++) {
                                int c = inFile.read();
                                if(c == filesigrar[i]) {
                                    valid = true;

                                } else if(c == filesigzip[i]) {
                                    valid = true;

                                } else {
                                    //In case any of the 4 bytes fails the check, the file is invalid
                                    //and the loop is aborted.
                                    valid = false;
                                    break;
                                }
                            }
                        //Any exception assumes that the input is invalid.
                        } catch (FileNotFoundException ex) {
                                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                                valid = false;
                        } catch (IOException ex) {
                                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                                valid = false;
                        }
                        System.out.println(valid);
                        return valid;
    }

it will return false even if the image contains a rar/zip. It's weird as same code is used to search for the archive in a Thread, and there it works :s
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
Sorry I'm really busy lately, so I won't debug your code for you. (Maybe some other time.)
Try finding out where it goes wrong. Put System.out.println's where the boolean can be set to false and find out which part of the algorithm causes valid to be false. Then you can focus on that area and you'll probably find the bug easily.

Good luck :)
 

galaxyAbstractor

Community Advocate
Community Support
Messages
5,508
Reaction score
35
Points
48
oh I fail, I skipped the length of the string, not the file xD. Now it works
 
Top