/** * Create a file within this temporary directory, prepopulating the file from the given input stream. * * @param relativePath the relative path name * @param sourceData the source input stream to use * @return the file * @throws IOException if the directory was closed at the time of this invocation or an error occurs */ public File createFile(String relativePath, InputStream sourceData) throws IOException { final File tempFile = getFile(relativePath); boolean ok = false; try { final FileOutputStream fos = new FileOutputStream(tempFile); try { VFSUtils.copyStream(sourceData, fos); fos.close(); sourceData.close(); ok = true; return tempFile; } finally { VFSUtils.safeClose(fos); } } finally { VFSUtils.safeClose(sourceData); if (!ok) { tempFile.delete(); } } }
contentsDir = tempDir.getFile("contents"); contentsDir.mkdir(); VFSLogger.ROOT_LOGGER.tracef("Created zip filesystem for file %s in temp dir %s", archiveFile, tempDir);
@Override public URL getStreamURL() throws IOException { if (vfsFile.isFile() == true) return vfsFile.toURL(); synchronized (this) { if (streamFile == null) { streamDir = tmpProvider.createTempDir("urlstream"); streamFile = streamDir.getFile(getName()); JarOutputStream jarOut = new JarOutputStream(new FileOutputStream(streamFile)); VirtualJarInputStream jarIn = (VirtualJarInputStream) vfsFile.openStream(); ZipEntry nextEntry = jarIn.getNextEntry(); while (nextEntry != null) { jarOut.putNextEntry(nextEntry); VFSUtils.copyStream(jarIn, jarOut); nextEntry = jarIn.getNextEntry(); } jarOut.close(); jarIn.close(); } } return streamFile.toURI().toURL(); }