<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: zip code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 17 May 2008 02:20:34 GMT</pubDate>
    <description>DZone Snippets: zip code</description>
    <item>
      <title>Create ZIP files on the fly</title>
      <link>http://snippets.dzone.com/posts/show/3530</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;    def createZIP(self, startdate, enddate):&lt;br /&gt;        """ Create the XTG file and the photos in a ZIP file """&lt;br /&gt;        from StringIO import StringIO&lt;br /&gt;        xtgString = StringIO()&lt;br /&gt;        photofiles = []&lt;br /&gt;        zorionagurrak = self.getZorionAgurrak(startdate, enddate)&lt;br /&gt;&lt;br /&gt;        xtgString.write('&lt;v6.50&gt;&lt;e0&gt;\r')&lt;br /&gt;        for zorionagurra in zorionagurrak:&lt;br /&gt;            a = self.createZorionAgurraXTG(zorionagurra).getvalue()&lt;br /&gt;            xtgString.write(a)&lt;br /&gt;            photofiles.append((zorionagurra['id'], zorionagurra['photo']))&lt;br /&gt;            &lt;br /&gt;        zipfile = self.appendFiles(xtgString, photofiles)&lt;br /&gt;&lt;br /&gt;        request = self.request&lt;br /&gt;&lt;br /&gt;        request.response.setHeader('Content-Type', 'application/zip')&lt;br /&gt;        request.response.setHeader('Content-Disposition', 'attachment; filename=zorionagurrak.zip')&lt;br /&gt;        request.response.write(zipfile.getvalue())&lt;br /&gt;        return request.response&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 16 Feb 2007 11:50:15 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3530</guid>
      <author>erral (Mikel)</author>
    </item>
    <item>
      <title>Adding files to an existing jar file</title>
      <link>http://snippets.dzone.com/posts/show/3468</link>
      <description>Adds files to an existing Zip file. &lt;br /&gt;&lt;br /&gt;Overwrites zip entries with the same name as one of the new files. &lt;br /&gt;&lt;br /&gt;The function renames the existing zip file to a temporary file and then adds all entries in the existing zip along with the new files, excluding the zip entries that have the same name as one of the new files. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Note: I'm not sure I used the best way to get a temp file. A snippet for that is welcome :)&lt;br /&gt;&lt;br /&gt;&lt;code&gt;	&lt;br /&gt;	public static void addFilesToExistingZip(File zipFile,&lt;br /&gt;			 File[] files) throws IOException {&lt;br /&gt;                // get a temp file&lt;br /&gt;		File tempFile = File.createTempFile(zipFile.getName(), null);&lt;br /&gt;                // delete it, otherwise you cannot rename your existing zip to it.&lt;br /&gt;		tempFile.delete();&lt;br /&gt;&lt;br /&gt;		boolean renameOk=zipFile.renameTo(tempFile);&lt;br /&gt;		if (!renameOk)&lt;br /&gt;		{&lt;br /&gt;			throw new RuntimeException("could not rename the file "+zipFile.getAbsolutePath()+" to "+tempFile.getAbsolutePath());&lt;br /&gt;		}&lt;br /&gt;		byte[] buf = new byte[1024];&lt;br /&gt;		&lt;br /&gt;		ZipInputStream zin = new ZipInputStream(new FileInputStream(tempFile));&lt;br /&gt;		ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFile));&lt;br /&gt;		&lt;br /&gt;		ZipEntry entry = zin.getNextEntry();&lt;br /&gt;		while (entry != null) {&lt;br /&gt;			String name = entry.getName();&lt;br /&gt;			boolean notInFiles = true;&lt;br /&gt;			for (File f : files) {&lt;br /&gt;				if (f.getName().equals(name)) {&lt;br /&gt;					notInFiles = false;&lt;br /&gt;					break;&lt;br /&gt;				}&lt;br /&gt;			}&lt;br /&gt;			if (notInFiles) {&lt;br /&gt;				// Add ZIP entry to output stream.&lt;br /&gt;				out.putNextEntry(new ZipEntry(name));&lt;br /&gt;				// Transfer bytes from the ZIP file to the output file&lt;br /&gt;				int len;&lt;br /&gt;				while ((len = zin.read(buf)) &gt; 0) {&lt;br /&gt;					out.write(buf, 0, len);&lt;br /&gt;				}&lt;br /&gt;			}&lt;br /&gt;			entry = zin.getNextEntry();&lt;br /&gt;		}&lt;br /&gt;		// Close the streams		&lt;br /&gt;		zin.close();&lt;br /&gt;		// Compress the files&lt;br /&gt;		for (int i = 0; i &lt; files.length; i++) {&lt;br /&gt;			InputStream in = new FileInputStream(files[i]);&lt;br /&gt;			// Add ZIP entry to output stream.&lt;br /&gt;			out.putNextEntry(new ZipEntry(files[i].getName()));&lt;br /&gt;			// Transfer bytes from the file to the ZIP file&lt;br /&gt;			int len;&lt;br /&gt;			while ((len = in.read(buf)) &gt; 0) {&lt;br /&gt;				out.write(buf, 0, len);&lt;br /&gt;			}&lt;br /&gt;			// Complete the entry&lt;br /&gt;			out.closeEntry();&lt;br /&gt;			in.close();&lt;br /&gt;		}&lt;br /&gt;		// Complete the ZIP file&lt;br /&gt;		out.close();&lt;br /&gt;		tempFile.delete();&lt;br /&gt;	}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 07 Feb 2007 14:00:10 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3468</guid>
      <author>jknight (Andrian)</author>
    </item>
    <item>
      <title>unix, pack folder and contents with tar gz</title>
      <link>http://snippets.dzone.com/posts/show/3075</link>
      <description>&lt;code&gt;&lt;br /&gt;tar -zcvf packagename.tar.gz folder/&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 04 Dec 2006 16:28:02 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3075</guid>
      <author>assbach (assbach)</author>
    </item>
    <item>
      <title>Create a single JPG gallery from an image archive</title>
      <link>http://snippets.dzone.com/posts/show/878</link>
      <description>The following comes from &lt;a href="http://ascii.textfiles.com/archives/000137.html"&gt;Jason Scott&lt;/a&gt; and is posted here with permission under the &lt;a href="http://creativecommons.org/licenses/by-sa/1.0/"&gt;Creative Commons Attribution-ShareAlike License&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The script expands a zip or rar archive of images, makes thumbnails, and compiles the thumbnails into a single JPG to represent what's in the archive. Requires &lt;a href="http://www.imagemagick.org/"&gt;ImageMagick&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Code:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/sh&lt;br /&gt;# GALLERATE: Turn a zip of images into a gallery.&lt;br /&gt;# From Jason Scott. http://ascii.textfiles.com/archives/000137.html&lt;br /&gt;if [ -f "$1" ]&lt;br /&gt;   then&lt;br /&gt;   rm -rf .galleryworld&lt;br /&gt;   echo "[%] Preparting to squat out $1...."&lt;br /&gt;   mkdir .galleryworld&lt;br /&gt;   cd .galleryworld&lt;br /&gt;   unzip -j "../$1"&lt;br /&gt;   unrar e -ep "../$1"&lt;br /&gt;   echo "[%] WHY DOES IT HURT!!!!"&lt;br /&gt;   montage +frame +shadow +label -tile 7 *.JPG *.GIF *.gif *.jpg *.bmp *.png *.PNG *.BMP "../$1.jpg"&lt;br /&gt;   cd ..&lt;br /&gt;   rm -rf .galleryworld&lt;br /&gt;   ls -l "$1.jpg"&lt;br /&gt;  else&lt;br /&gt;  echo "No such file, assmaster."&lt;br /&gt;fi&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Usage:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;GALLERATE [file]&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;where [file] is the zip or rar archive of images to be processed.</description>
      <pubDate>Wed, 09 Nov 2005 07:05:13 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/878</guid>
      <author>madphilosopher (Darren Paul Griffith)</author>
    </item>
    <item>
      <title>Reading from a zip file</title>
      <link>http://snippets.dzone.com/posts/show/742</link>
      <description>&lt;code&gt;&lt;br /&gt;import zipfile&lt;br /&gt;&lt;br /&gt;z = zipfile.ZipFile("zipfile.zip", "r")&lt;br /&gt;for filename in z.namelist():&lt;br /&gt;        print filename&lt;br /&gt;        bytes = z.read(filename)&lt;br /&gt;        print len(bytes)&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 18 Sep 2005 15:14:11 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/742</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>Zip two Arrays together into a Hash</title>
      <link>http://snippets.dzone.com/posts/show/406</link>
      <description>Found this here: &lt;br /&gt;&lt;br /&gt;http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/122906&lt;br /&gt;&lt;code&gt; &lt;br /&gt;def Hash.from_pairs_e(keys,values)&lt;br /&gt;  hash = {}&lt;br /&gt;  keys.size.times { |i| hash[ keys[i] ] = values[i] }&lt;br /&gt;  hash&lt;br /&gt;end &lt;/code&gt;</description>
      <pubDate>Tue, 21 Jun 2005 15:08:49 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/406</guid>
      <author>Babbage (Patrick Hall)</author>
    </item>
  </channel>
</rss>
