/** * {@inheritDoc} */ public boolean delete(VirtualFile mountPoint, VirtualFile target) { final ZipNode zipNode = getZipNode(mountPoint, target); if (zipNode == null) { return false; } final File cachedFile = zipNode.cachedFile; return cachedFile != null && cachedFile.delete(); }
/** * {@inheritDoc} */ public File getFile(VirtualFile mountPoint, VirtualFile target) throws IOException { final ZipNode zipNode = getExistingZipNode(mountPoint, target); // check if we have cached one already File cachedFile = zipNode.cachedFile; if (cachedFile != null) { return cachedFile; } synchronized (zipNode) { // double-check cachedFile = zipNode.cachedFile; if (cachedFile != null) { return cachedFile; } // nope, create a cached temp final JarEntry zipEntry = zipNode.entry; String name = target.getPathNameRelativeTo(mountPoint); cachedFile = buildFile(contentsDir, name); if (zipEntry == null) { cachedFile.mkdir(); } else { VFSUtils.copyStreamAndClose(zipFile.getInputStream(zipEntry), new BufferedOutputStream(new FileOutputStream(cachedFile))); } zipNode.cachedFile = cachedFile; return cachedFile; } }
/** * Create and mount a zip file into the filesystem, returning a single handle which will unmount and close the file * system 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 mountZip(File zipFile, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException { boolean ok = false; final TempDir tempDir = tempFileProvider.createTempDir(zipFile.getName()); try { final MountHandle handle = doMount(new JavaZipFileSystem(zipFile, tempDir), mountPoint); ok = true; return handle; } finally { if (!ok) { VFSUtils.safeClose(tempDir); } } }
/** * {@inheritDoc} */ public InputStream openInputStream(VirtualFile mountPoint, VirtualFile target) throws IOException { final ZipNode zipNode = getExistingZipNode(mountPoint, target); final File cachedFile = zipNode.cachedFile; if (cachedFile != null) { return new FileInputStream(cachedFile); } if (rootNode == zipNode) { return new FileInputStream(archiveFile); } final JarEntry entry = zipNode.entry; if (entry == null) { throw VFSMessages.MESSAGES.notAFile(target.getPathName()); } return zipFile.getInputStream(entry); }
final ZipNode rootNode = new ZipNode(new HashMap<String, ZipNode>(), "", null); FILES: for (JarEntry entry : iter(entries)) { final String name = entry.getName(); final boolean isDirectory = entry.isDirectory();
/** * Create and mount a zip file into the filesystem, returning a single handle which will unmount and close the file * system when closed. * * @param zipData an input stream containing the zip data * @param zipName the name of the archive * @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 mountZip(InputStream zipData, String zipName, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException { boolean ok = false; try { final TempDir tempDir = tempFileProvider.createTempDir(zipName); try { final MountHandle handle = doMount(new JavaZipFileSystem(zipName, zipData, tempDir), mountPoint); ok = true; return handle; } finally { if (!ok) { VFSUtils.safeClose(tempDir); } } } finally { VFSUtils.safeClose(zipData); } }
/** * {@inheritDoc} */ public long getLastModified(VirtualFile mountPoint, VirtualFile target) { final ZipNode zipNode = getZipNode(mountPoint, target); if (zipNode == null) { return 0L; } final File cachedFile = zipNode.cachedFile; final JarEntry entry = zipNode.entry; return cachedFile != null ? cachedFile.lastModified() : entry == null ? zipTime : entry.getTime(); }
/** * {@inheritDoc} */ public CodeSigner[] getCodeSigners(VirtualFile mountPoint, VirtualFile target) { final ZipNode zipNode = getZipNode(mountPoint, target); if (zipNode == null) { return null; } JarEntry jarEntry = zipNode.entry; return jarEntry.getCodeSigners(); }
/** * {@inheritDoc} */ public List<String> getDirectoryEntries(VirtualFile mountPoint, VirtualFile target) { final ZipNode zipNode = getZipNode(mountPoint, target); if (zipNode == null) { return Collections.emptyList(); } final Map<String, ZipNode> children = zipNode.children; if (children == null) { return Collections.emptyList(); } final Collection<ZipNode> values = children.values(); final List<String> names = new ArrayList<String>(values.size()); for (ZipNode node : values) { names.add(node.name); } return names; }
/** * {@inheritDoc} */ public long getSize(VirtualFile mountPoint, VirtualFile target) { final ZipNode zipNode = getZipNode(mountPoint, target); if (zipNode == null) { return 0L; } final File cachedFile = zipNode.cachedFile; final JarEntry entry = zipNode.entry; if (zipNode == rootNode) { return archiveFile.length(); } return cachedFile != null ? cachedFile.length() : entry == null ? 0L : entry.getSize(); }