I am developing an app that needs to frequently access a zip file to add, delete, and read files. I'm looking at using truezip because it promises that I can do all these fairly easily (being able to pass arond and read from a currently zipped file is the biggest advantage it presents) but in playing with it I am unable to add files to the archive. My code:
public void testfunction()
{
//below create the archive if it doesn't exist
TFile tFile = new TFile("src\\test\\resources\\archiveTest\\demoZip.zip");
if (!tFile.exists()) // I get an EOFException here
{
tFile.createNewFile();
}
TFile innerFile = new TFile("src\\test\\resources\\archiveTest\\demoZip.zip\\someText.txt");
innerFile.createNewFile(); // also here
BufferedWriter out = new BufferedWriter(new FileWriter(innerFile));
out.write("demo text");
out.close(); // I know this is bad
}
When I run this I get a java.io.EOFException no matter how I try to arrange this simple thing. If I try to make sure that the file has been created already I just get the exception when I call tFile.exists() method. If I don't, then I get it when I try to create the innerFile later (even if the zip file already exists).
I should note: the examples in the truezip archetype use the TApplication class, but I can't do that. I have to be able to use this library pretty much out of the box. I cannot change the structure of the application, so making the application itself a TApplication subclass is not a viable solution (though I can alter the structure of the calling class however I need to).
At present my POM includes these dependencies (included from examples I found):
<dependency>
<groupId>de.schlichtherle.truezip</groupId>
<artifactId>truezip-file</artifactId>
<version>7.4.1</version>
</dependency>
<dependency>
<groupId>de.schlichtherle.truezip</groupId>
<artifactId>truezip-driver-zip</artifactId>
<version>7.4.1</version>
</dependency>
<dependency>
<groupId>de.schlichtherle.truezip</groupId>
<artifactId>truezip-kernel</artifactId>
<version>7.4.1</version>
</dependency>
<dependency>
<groupId>de.schlichtherle.truezip</groupId>
<artifactId>truezip-driver-file</artifactId>
<version>7.4.1</version>
</dependency>
So I've no idea what I'm doing so any advice I could get would be appreciated as most examples on the internet seem to assume more knowledge than I have.