@Override public void close() throws IOException { for (Entry each : this.archives.values()) { each.close(); } this.tempDir.close(); }
/** * Create a new instance. * * @param name the name of the source archive * @param inputStream an input stream from the source archive * @param tempDir the temp dir into which zip information is stored * @throws java.io.IOException if an I/O error occurs */ public JavaZipFileSystem(String name, InputStream inputStream, TempDir tempDir) throws IOException { this(tempDir.createFile(name, inputStream), tempDir); }
/** * 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(); } } }
final TempDir tempDir = tempFileProvider.createTempDir(zipName); try { final File zipFile = File.createTempFile(zipName + "-", ".tmp", tempDir.getRoot()); try { final FileOutputStream os = new FileOutputStream(zipFile); VFSUtils.safeClose(os); final File rootFile = tempDir.getRoot(); VFSUtils.unzip(zipFile, rootFile); final MountHandle handle = doMount(new RealFileSystem(rootFile), mountPoint, tempDir);
/** * Create a temp directory, into which temporary files may be placed. * * @param originalName the original file name * @return the temp directory * @throws IOException for any error */ public TempDir createTempDir(String originalName) throws IOException { if (!open.get()) { throw VFSMessages.MESSAGES.tempFileProviderClosed(); } final String name = createTempName(originalName + "-", ""); final File f = new File(providerRoot, name); for (int i = 0; i < RETRIES; i++) { if (f.mkdirs()) { return new TempDir(this, f); } } throw VFSMessages.MESSAGES.couldNotCreateDirectory(originalName,RETRIES); }
contentsDir = tempDir.getFile("contents"); contentsDir.mkdir(); VFSLogger.ROOT_LOGGER.tracef("Created zip filesystem for file %s in temp dir %s", archiveFile, tempDir);
/** * Create and mount a temporary file system, returning a single handle which will unmount and close the filesystem * when closed. * * @param mountPoint the point at which the filesystem should be mounted * @param tempFileProvider the temporary file provider * @return a handle * @throws IOException if an error occurs */ public static Closeable mountTemp(VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException { boolean ok = false; final TempDir tempDir = tempFileProvider.createTempDir("tmpfs"); try { final MountHandle handle = doMount(new RealFileSystem(tempDir.getRoot()), mountPoint, tempDir); ok = true; return handle; } finally { if (!ok) { VFSUtils.safeClose(tempDir); } } }
File getFile(Entry entry) { if (entry.file == null) { try { entry.file = this.tempDir.createFile(entry.archive.getName(), entry.archive.as(ZipExporter.class).exportAsInputStream()); } catch (IOException e) { e.printStackTrace(); } } return entry.file; }
@Override public void close() throws IOException { for (Entry each : this.archives.values()) { each.close(); } this.tempDir.close(); }
@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(); }
/** * Create and mount an expanded zip file in a temporary file system, returning a single handle which will unmount and * close the filesystem when closed. * * @param zipFile the zip file to mount * @param mountPoint the point at which the filesystem should be mounted * @param tempFileProvider the temporary file provider * @return a handle * @throws IOException if an error occurs */ public static Closeable mountZipExpanded(File zipFile, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException { boolean ok = false; final TempDir tempDir = tempFileProvider.createTempDir(zipFile.getName()); try { final File rootFile = tempDir.getRoot(); VFSUtils.unzip(zipFile, rootFile); final MountHandle handle = doMount(new RealFileSystem(rootFile), mountPoint, tempDir); ok = true; return handle; } finally { if (!ok) { VFSUtils.safeClose(tempDir); } } }
File getFile(Entry entry) { if (entry.file == null) { try { entry.file = this.tempDir.createFile(entry.archive.getName(), entry.archive.as(ZipExporter.class).exportAsInputStream()); } catch (IOException e) { e.printStackTrace(); } } return entry.file; }
@Override public void close() throws IOException { for (Entry each : this.archives.values()) { each.close(); } this.tempDir.close(); }
File getFile(Entry entry) { if (entry.file == null) { try { entry.file = this.tempDir.createFile(entry.archive.getName(), entry.archive.as(ZipExporter.class).exportAsInputStream()); } catch (IOException e) { e.printStackTrace(); } } return entry.file; }
/** * {@inheritDoc} */ public void close() throws IOException { VFSLogger.ROOT_LOGGER.tracef("Closing zip filesystem %s", this); VFSUtils.safeClose(new Closeable() { public void close() throws IOException { zipFile.close(); } }); tempDir.close(); }