1701 is.transferTo(os);
1702 }
1703 }
1704 Files.delete(e.file);
1705 tmppaths.remove(e.file);
1706 }
1707 }
1708
1709 // sync the zip file system, if there is any update
1710 private void sync() throws IOException {
1711 if (!hasUpdate)
1712 return;
1713 PosixFileAttributes attrs = getPosixAttributes(zfpath);
1714 Path tmpFile = createTempFileInSameDirectoryAs(zfpath);
1715 try (OutputStream os = new BufferedOutputStream(Files.newOutputStream(tmpFile, WRITE))) {
1716 ArrayList<Entry> elist = new ArrayList<>(inodes.size());
1717 long written = 0;
1718 byte[] buf = null;
1719 Entry e;
1720
1721 // write loc
1722 for (IndexNode inode : inodes.values()) {
1723 if (inode instanceof Entry) { // an updated inode
1724 e = (Entry)inode;
1725 try {
1726 if (e.type == Entry.COPY) {
1727 // entry copy: the only thing changed is the "name"
1728 // and "nlen" in LOC header, so we update/rewrite the
1729 // LOC in new file and simply copy the rest (data and
1730 // ext) without enflating/deflating from the old zip
1731 // file LOC entry.
1732 if (buf == null)
1733 buf = new byte[8192];
1734 written += copyLOCEntry(e, true, os, written, buf);
1735 } else { // NEW, FILECH or CEN
1736 e.locoff = written;
1737 written += e.writeLOC(os); // write loc header
1738 written += writeEntry(e, os);
1739 }
1740 elist.add(e);
1741 } catch (IOException x) {
1742 x.printStackTrace(); // skip any in-accurate entry
|
1701 is.transferTo(os);
1702 }
1703 }
1704 Files.delete(e.file);
1705 tmppaths.remove(e.file);
1706 }
1707 }
1708
1709 // sync the zip file system, if there is any update
1710 private void sync() throws IOException {
1711 if (!hasUpdate)
1712 return;
1713 PosixFileAttributes attrs = getPosixAttributes(zfpath);
1714 Path tmpFile = createTempFileInSameDirectoryAs(zfpath);
1715 try (OutputStream os = new BufferedOutputStream(Files.newOutputStream(tmpFile, WRITE))) {
1716 ArrayList<Entry> elist = new ArrayList<>(inodes.size());
1717 long written = 0;
1718 byte[] buf = null;
1719 Entry e;
1720
1721 final IndexNode manifestInode = inodes.get(
1722 IndexNode.keyOf(getBytes("/META-INF/MANIFEST.MF")));
1723 final Iterator<IndexNode> inodeIterator = inodes.values().iterator();
1724 boolean manifestProcessed = false;
1725
1726 // write loc
1727 while (inodeIterator.hasNext()) {
1728 final IndexNode inode;
1729
1730 // write the manifest inode (if any) first so that
1731 // java.util.jar.JarInputStream can find it
1732 if (manifestInode == null) {
1733 inode = inodeIterator.next();
1734 } else {
1735 if (manifestProcessed) {
1736 // advance to next node, filtering out the manifest
1737 // which was already written
1738 inode = inodeIterator.next();
1739 if (inode == manifestInode) {
1740 continue;
1741 }
1742 } else {
1743 inode = manifestInode;
1744 manifestProcessed = true;
1745 }
1746 }
1747
1748 if (inode instanceof Entry) { // an updated inode
1749 e = (Entry)inode;
1750 try {
1751 if (e.type == Entry.COPY) {
1752 // entry copy: the only thing changed is the "name"
1753 // and "nlen" in LOC header, so we update/rewrite the
1754 // LOC in new file and simply copy the rest (data and
1755 // ext) without enflating/deflating from the old zip
1756 // file LOC entry.
1757 if (buf == null)
1758 buf = new byte[8192];
1759 written += copyLOCEntry(e, true, os, written, buf);
1760 } else { // NEW, FILECH or CEN
1761 e.locoff = written;
1762 written += e.writeLOC(os); // write loc header
1763 written += writeEntry(e, os);
1764 }
1765 elist.add(e);
1766 } catch (IOException x) {
1767 x.printStackTrace(); // skip any in-accurate entry
|