Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deleteing file fails after Compressor.decompress() #42

Open
BaseRegister opened this issue Jun 18, 2015 · 2 comments
Open

Deleteing file fails after Compressor.decompress() #42

BaseRegister opened this issue Jun 18, 2015 · 2 comments

Comments

@BaseRegister
Copy link

Simple and clean API but I have an issue.

I am using a test file named fileNane.gz. It is not a compressed file but a text file with the .gz extension. This file seems to be locked by a process when trying to delete.

compressor.decompress(f, new File(f.getParent()) ) throws an exception as expected but I cannot delete the file.

Here is my code:

private boolean decompress(File f) {
    try{
        Compressor compressor = CompressorFactory.createCompressor(f);
        System.out.println("COMPRESSED FILE");

        compressor.decompress(f, new File(f.getParent()) );
        FileUtils.deleteQuietly(f);

        return true;
    }catch(IllegalArgumentException e){

    }catch(FileNotFoundException e){

    }catch (Exception e) {

        System.out.println(f.canExecute()); // is true
        System.out.println(f.canRead()); // is true
        System.out.println(f.canWrite()); // is true
        System.out.println(f.exists()); // is true

        System.out.println(f.delete()); // is false

        System.err.println(e); 
    }

    return false;
}
@thrau
Copy link
Owner

thrau commented Jun 18, 2015

i can not replicate this on my system. i wrote a junit test:

    @Test
    public void test() throws Exception {
        File source = new File("/tmp/fake.gz");
        assertTrue(source.createNewFile());

        Compressor compressor = CompressorFactory.createCompressor(source);
        try {
            compressor.decompress(source, new File(source.getParent()));
        } catch (Exception e) {
            assertTrue(source.exists());
            assertTrue(source.delete());
            assertFalse(new File("/tmp/fake.gz").exists());
        }
    }

and it runs through properly.

can you specify what environment you working are in?

  • operating system
  • java version
  • in what type of environment are you executing the code?

@BaseRegister
Copy link
Author

Thank you for your quick response. I've done more testing and still receive the same error. Maybe it is a problem with the Java version?

Operating System: Windows 7
Java Version: 1.6.0_29
Environment: From Eclipse Luna as a java application. Also tested from Windows command prompt after creating an executable jar.

I've simplified the execution to this:

public static void main(String[] args){
    File f = new File("document.txt.gz");
    System.out.println("Java Version: "+ System.getProperty("java.version"));
    try{
        Compressor compressor = CompressorFactory.createCompressor(f);
        compressor.decompress(f, new File(f.getParent()) );
    }catch(IllegalArgumentException e){
        e.printStackTrace();
    }catch (Exception e) {
        e.printStackTrace();    
    }finally{
        System.out.println(f.delete());         
    }       
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants