You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Matthew Harrison <ma...@gmail.com> on 2018/07/05 22:32:06 UTC
Parsing a file inside a zip file locking zip file on windows
Hi,
I've hit a bit of an odd case, that I'm hoping someone can tell me what I'm
doing wrong, or how to fix it.
As part of a transform (using Saxon), we're processing files that are
inside a zip file. To access the files we're using a 'jar' URI, however
after accessing/parsing the file it seems to be locked, and so cannot be
deleted until the java program terminates.
I believe I've created a reproducing case:
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import com.google.common.io.Files;
public class CleanupInvestigation3 {
public static void main(String[] args)
throws IOException, SAXException, ParserConfigurationException,
URISyntaxException, InterruptedException {
File input = new File("src/test/resources/books.zip");
File inputCopy = new File("src/test/resources/booksCopy.zip");
Files.copy(input, inputCopy);
DocumentBuilder builder =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc =
builder.parse("jar:file:src/test/resources/booksCopy.zip!/app.xml");
System.out.println(doc.getLastChild().getNodeName());
System.out.println("File delete (booksCopy.zip): " + inputCopy.delete());
System.out.println("complete");
}
}
I'm running this using Xerces 2.12.0 running on a Windows 10 machine,
talking with the Saxon guys its looks like it works ok on a Mac (i.e. the
booksCopy.zip file can be deleted).
If anyone has any ideas on what the issue might be that would be great.
Thanks,
Matt