SF.net SVN: jrpm: [20] trunk

[email protected] Sun, 20 Apr 2008 10:14:01 -0700
Newsgroups gmane.comp.java.jrpm.devel
Message-ID <[email protected]>
Revision: 20
          http://jrpm.svn.sourceforge.net/jrpm/?rev=20&view=rev
Author:   mkuss
Date:     2008-04-20 10:14:01 -0700 (Sun, 20 Apr 2008)

Log Message:
-----------
LZMA support and some better logging

Modified Paths:
--------------
    trunk/project.xml
    trunk/src/java/com/jguild/jrpm/io/Header.java
    trunk/src/java/com/jguild/jrpm/io/RPMFile.java
    trunk/src/java/com/jguild/jrpm/io/RPMLead.java

Added Paths:
-----------
    trunk/.classpath
    trunk/.project
    trunk/resources/lib/JLzma.jar
    trunk/resources/test/pld/
    trunk/resources/test/pld/apache1-mod_auth_ldap-1.6.0-6.i686.rpm
    trunk/src/java/com/jguild/jrpm/tools/Info.java

Added: trunk/.classpath
===================================================================
--- trunk/.classpath	                        (rev 0)
+++ trunk/.classpath	2008-04-20 17:14:01 UTC (rev 20)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry excluding="**/.svn/**" kind="src" path="src/java"/>
+	<classpathentry kind="src" path="src/test"/>
+	<classpathentry kind="lib" path="resources/lib/JLzma.jar"/>
+	<classpathentry kind="lib" path="resources/lib/junit.jar"/>
+	<classpathentry kind="lib" path="target/commons-logging.jar"/>
+	<classpathentry kind="lib" path="target/jrpm-SNAPSHOT.jar"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

Added: trunk/.project
===================================================================
--- trunk/.project	                        (rev 0)
+++ trunk/.project	2008-04-20 17:14:01 UTC (rev 20)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>jRPM</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

Modified: trunk/project.xml
===================================================================
--- trunk/project.xml	2006-11-08 00:13:40 UTC (rev 19)
+++ trunk/project.xml	2008-04-20 17:14:01 UTC (rev 20)
@@ -22,9 +22,9 @@
     </organization>
 
     <repository>
-        <connection>scm:cvs:pserver:[email protected]:/cvsroot/jrpm:jrpm</connection>
-        <developerConnection>scm:cvs:ext:${maven.username}@cvs.sourceforge.net:/cvsroot/jrpm:jrpm</developerConnection>
-        <url>http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jrpm/</url>
+        <connection>scm:cvs:pserver:[email protected]:/cvsroot/jrpm:jrpm</connection>
+        <developerConnection>scm:cvs:ext:${maven.username}@jrpm.cvs.sourceforge.net:/cvsroot/jrpm:jrpm</developerConnection>
+        <url>http://jrpm.cvs.sourceforge.net/jrpm/</url>
     </repository>
 
     <mailingLists>
@@ -87,6 +87,7 @@
     </licenses>
 
     <build>
+        <sourceDirectory>src/java</sourceDirectory>
         <unitTestSourceDirectory>src/test</unitTestSourceDirectory>
         <unitTest>
             <includes>

Added: trunk/resources/lib/JLzma.jar
===================================================================
(Binary files differ)


Property changes on: trunk/resources/lib/JLzma.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/resources/test/pld/apache1-mod_auth_ldap-1.6.0-6.i686.rpm
===================================================================
(Binary files differ)


Property changes on: trunk/resources/test/pld/apache1-mod_auth_ldap-1.6.0-6.i686.rpm
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: trunk/src/java/com/jguild/jrpm/io/Header.java
===================================================================
--- trunk/src/java/com/jguild/jrpm/io/Header.java	2006-11-08 00:13:40 UTC (rev 19)
+++ trunk/src/java/com/jguild/jrpm/io/Header.java	2008-04-20 17:14:01 UTC (rev 20)
@@ -73,9 +73,19 @@
             // Read header
             size = HEADER_LENGTH;
 
-            check(inputStream.readUnsignedByte() == 0x8E);
-            check(inputStream.readUnsignedByte() == 0xAD);
-            check(inputStream.readUnsignedByte() == 0xE8);
+            int magic = 0;
+            
+            do {
+               magic = inputStream.readUnsignedByte();
+               if (magic == 0)
+                  inputStream.skip(7);
+            } while(magic == 0);
+            
+            check(magic == 0x8E, "Header magic 0x"+ Integer.toHexString(magic) + " != 0x8E");
+            magic =inputStream.readUnsignedByte();  
+            check(magic == 0xAD, "Header magic 0x"+ Integer.toHexString(magic) + " != 0xAD");
+            magic =inputStream.readUnsignedByte();  
+            check(magic == 0xE8, "Header magic 0x"+ Integer.toHexString(magic) + " != 0xE8");
             version = inputStream.readUnsignedByte();
 
             if (logger.isLoggable(Level.FINER)) {
@@ -295,10 +305,10 @@
      * @param test A boolean test variable
      * @throws IOException if the variable test is false
      */
-    private static final void check(boolean test)
+    private static final void check(boolean test, String message)
             throws IOException {
         if (!test) {
-            throw new IOException("Corrupted archive");
+            throw new IOException("Corrupted archive: " + message);
         }
     }
 

Modified: trunk/src/java/com/jguild/jrpm/io/RPMFile.java
===================================================================
--- trunk/src/java/com/jguild/jrpm/io/RPMFile.java	2006-11-08 00:13:40 UTC (rev 19)
+++ trunk/src/java/com/jguild/jrpm/io/RPMFile.java	2008-04-20 17:14:01 UTC (rev 20)
@@ -13,6 +13,27 @@
  **/
 package com.jguild.jrpm.io;
 
+import java.io.BufferedInputStream;
+import java.io.DataInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.zip.GZIPInputStream;
+
+import SevenZip.ICodeProgress;
+import SevenZip.Compression.LZMA.Decoder;
+
 import com.jguild.jrpm.io.bzip2.CBZip2InputStream;
 import com.jguild.jrpm.io.cpio.CPIOEntry;
 import com.jguild.jrpm.io.cpio.CPIOInputStream;
@@ -21,447 +42,529 @@
 import com.jguild.jrpm.io.datatype.STRING_ARRAY;
 import com.jguild.jrpm.io.datatype.TypeFactory;
 
-import java.io.*;
-import java.util.ArrayList;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.zip.GZIPInputStream;
-
 /**
  * This class allows IO access to an RPM file.
- *
+ * 
  * @todo Implement equals()
  */
 public class RPMFile {
-    public static final Logger logger = Logger.getLogger("jrpm.io");
-    private RPMHeader header = null;
-    private RPMLead lead = null;
-    private RPMSignature signature = null;
-    private int localePosition;
-    private File rpmFile = null;
-    private boolean editingRpmFile = false;
+	public static final Logger logger = Logger.getLogger("jrpm.io");
 
-    /**
-     * Creates a new empty RPMFile object.
-     */
-    public RPMFile() {
-    }
+	private RPMHeader header = null;
 
-    /**
-     * Creates a new RPMFile object out of a file.
-     *
-     * @param fh The file object representing a rpm file
-     */
-    public RPMFile(File fh) {
-        rpmFile = fh;
-    }
+	private RPMLead lead = null;
 
-    private synchronized void reset() {
-        header = null;
-        lead = null;
-        signature = null;
-        editingRpmFile = false;
-    }
+	private RPMSignature signature = null;
 
-    /**
-     * Set the file this RPMFile should represent
-     *
-     * @param fh The file object representing a rpm file
-     */
-    public synchronized void setFile(File fh) {
-        if (editingRpmFile) {
-            throw new IllegalStateException("RPM file is currently edited");
-        }
-        rpmFile = fh;
-        reset();
-    }
+	private int localePosition;
 
-    /**
-     * Parse the RPMFile and will extract all informations. This must be called
-     * before any informations can be read from the rpm file.
-     *
-     * @throws IOException If an error occurs during read of the rpm file
-     */
-    public synchronized void parse() throws IOException {
-        if (rpmFile == null)
-            throw new IllegalStateException("A file must be specified");
+	private File rpmFile = null;
 
-        if (!rpmFile.exists())
-            throw new IllegalStateException(
-                    "The specified file does not exist");
+	private boolean editingRpmFile = false;
 
-        try {
-            readFromStream(new BufferedInputStream(new FileInputStream(rpmFile)));
-        } catch (IOException e) {
-            reset();
-            throw e;
-        }
-        editingRpmFile = true;
-    }
+	/**
+	 * Creates a new empty RPMFile object.
+	 */
+	public RPMFile() {
+	}
 
-    /**
-     * Get the header section of this rpm file.
-     *
-     * @return The rpm header
-     */
-    public synchronized RPMHeader getHeader() {
-        if (header == null)
-            throw new IllegalStateException(
-                    "There are no header informations");
+	/**
+	 * Creates a new RPMFile object out of a file.
+	 * 
+	 * @param fh
+	 *            The file object representing a rpm file
+	 */
+	public RPMFile(File fh) {
+		rpmFile = fh;
+	}
 
-        return header;
-    }
+	private synchronized void reset() {
+		header = null;
+		lead = null;
+		signature = null;
+		editingRpmFile = false;
+	}
 
-    /**
-     * Get all known tags of this rpm file. This is equivalent to the
-     * --querytags option in rpm.
-     *
-     * @return An array of all tag names
-     */
-    public static String[] getKnownTagNames() {
-        return Header.getKnownTagNames();
-    }
+	/**
+	 * Set the file this RPMFile should represent
+	 * 
+	 * @param fh
+	 *            The file object representing a rpm file
+	 */
+	public synchronized void setFile(File fh) {
+		if (editingRpmFile) {
+			throw new IllegalStateException("RPM file is currently edited");
+		}
+		rpmFile = fh;
+		reset();
+	}
 
-    /**
-     * Get the lead section of this rpm file
-     *
-     * @return The rpm lead
-     */
-    public synchronized RPMLead getLead() {
-        if (lead == null)
-            throw new IllegalStateException(
-                    "There are no lead informations");
+	/**
+	 * Parse the RPMFile and will extract all informations. This must be called
+	 * before any informations can be read from the rpm file.
+	 * 
+	 * @throws IOException
+	 *             If an error occurs during read of the rpm file
+	 */
+	public synchronized void parse() throws IOException {
+		if (rpmFile == null)
+			throw new IllegalStateException("A file must be specified");
 
-        return lead;
-    }
+		if (!rpmFile.exists())
+			throw new IllegalStateException("The specified file does not exist");
 
-    /**
-     * Set the locale as int for all I18N strings that are returned by
-     * getTag(). The position has to correspond with the same position in the
-     * array returned by getLocales().
-     *
-     * @param pos The position in the array returned by getLocales().
-     */
-    public synchronized void setLocale(int pos) {
-        localePosition = pos;
-    }
+		try {
+			readFromStream(new BufferedInputStream(
+					new FileInputStream(rpmFile), 4096));
+		} catch (IOException e) {
+			reset();
+			throw e;
+		}
+		editingRpmFile = true;
+	}
 
-    /**
-     * Set the locale as string for all I18N strings that are returned by
-     * getTag(). The string must match with a string returned by getLocales().
-     *
-     * @param locale A locale matching a locale returned by getLocales()
-     * @throws IllegalArgumentException If the locale is not defined by getLocales().
-     */
-    public synchronized void setLocale(String locale) {
-        String[] locales = ((STRING_ARRAY) getTag("HEADERI18NTABLE")).getData();
+	/**
+	 * Get the header section of this rpm file.
+	 * 
+	 * @return The rpm header
+	 */
+	public synchronized RPMHeader getHeader() {
+		if (header == null)
+			throw new IllegalStateException("There are no header informations");
 
-        for (int pos = 0; pos < locales.length; pos++) {
-            if (locales[pos].equals(locale)) {
-                setLocale(pos);
+		return header;
+	}
 
-                return;
-            }
-        }
+	/**
+	 * Get all known tags of this rpm file. This is equivalent to the
+	 * --querytags option in rpm.
+	 * 
+	 * @return An array of all tag names
+	 */
+	public static String[] getKnownTagNames() {
+		return Header.getKnownTagNames();
+	}
 
-        throw new IllegalArgumentException("Unknown locale <" + locale + ">");
-    }
+	/**
+	 * Get the lead section of this rpm file
+	 * 
+	 * @return The rpm lead
+	 */
+	public synchronized RPMLead getLead() {
+		if (lead == null)
+			throw new IllegalStateException("There are no lead informations");
 
-    /**
-     * Return all known locales that are supported by this RPM file. The array
-     * is read out of the RPM file with the tag "HEADERI18NTABLE". The RPM has
-     * one entry for all I18N strings defined by this tag.
-     *
-     * @return A string array of all defined locales
-     */
-    public synchronized String[] getLocales() {
-        return ((STRING_ARRAY) getTag("HEADERI18NTABLE")).getData();
-    }
+		return lead;
+	}
 
-    /**
-     * Get the signature section of this rpm file
-     *
-     * @return The rpm signature
-     */
-    public synchronized RPMSignature getSignature() {
-        if (signature == null)
-            throw new IllegalStateException(
-                    "There are no signature informations");
+	/**
+	 * Set the locale as int for all I18N strings that are returned by getTag().
+	 * The position has to correspond with the same position in the array
+	 * returned by getLocales().
+	 * 
+	 * @param pos
+	 *            The position in the array returned by getLocales().
+	 */
+	public synchronized void setLocale(int pos) {
+		localePosition = pos;
+	}
 
-        return signature;
-    }
+	/**
+	 * Set the locale as string for all I18N strings that are returned by
+	 * getTag(). The string must match with a string returned by getLocales().
+	 * 
+	 * @param locale
+	 *            A locale matching a locale returned by getLocales()
+	 * @throws IllegalArgumentException
+	 *             If the locale is not defined by getLocales().
+	 */
+	public synchronized void setLocale(String locale) {
+		String[] locales = ((STRING_ARRAY) getTag("HEADERI18NTABLE")).getData();
 
-    /**
-     * Get a tag by id as a Long
-     *
-     * @param tag A tag id as a Long
-     * @return A data struct containing the data of this tag
-     */
-    public synchronized DataTypeIf getTag(Long tag) {
-        DataTypeIf data = getHeader().getTag(tag);
+		for (int pos = 0; pos < locales.length; pos++) {
+			if (locales[pos].equals(locale)) {
+				setLocale(pos);
 
-        // set the locale for all I18N strings
-        if (data instanceof I18NSTRING) {
-            ((I18NSTRING) data).setLocaleIndex(localePosition);
-        }
+				return;
+			}
+		}
 
-        return data;
-    }
+		throw new IllegalArgumentException("Unknown locale <" + locale + ">");
+	}
 
-    /**
-     * Get a tag by id as a long
-     *
-     * @param tag A tag id as a long
-     * @return A data struct containing the data of this tag
-     */
-    public synchronized DataTypeIf getTag(long tag) {
-        return getTag(new Long(tag));
-    }
+	/**
+	 * Return all known locales that are supported by this RPM file. The array
+	 * is read out of the RPM file with the tag "HEADERI18NTABLE". The RPM has
+	 * one entry for all I18N strings defined by this tag.
+	 * 
+	 * @return A string array of all defined locales
+	 */
+	public synchronized String[] getLocales() {
+		return ((STRING_ARRAY) getTag("HEADERI18NTABLE")).getData();
+	}
 
-    /**
-     * Get a tag by name
-     *
-     * @param tagname A tag name
-     * @return A data struct containing the data of this tag
-     */
-    public synchronized DataTypeIf getTag(String tagname) {
-        return getTag(getTagIdForName(tagname));
-    }
+	/**
+	 * Get the signature section of this rpm file
+	 * 
+	 * @return The rpm signature
+	 */
+	public synchronized RPMSignature getSignature() {
+		if (signature == null)
+			throw new IllegalStateException(
+					"There are no signature informations");
 
-    /**
-     * Read a tag with a given tag name.
-     *
-     * @param tagname A RPM tag name
-     * @return The id of the RPM tag
-     * @throws IllegalArgumentException if the tag name was not found
-     * @see Header#getTagIdForName(String)
-     */
-    public synchronized long getTagIdForName(String tagname) {
-        return getHeader().getTagIdForName(tagname);
-    }
+		return signature;
+	}
 
-    /**
-     * Get all tag ids contained in this rpm file.
-     *
-     * @return All tag ids contained in this rpm file.
-     */
-    public synchronized long[] getTagIds() {
-        return getHeader().getTagIds();
-    }
+	/**
+	 * Get a tag by id as a Long
+	 * 
+	 * @param tag
+	 *            A tag id as a Long
+	 * @return A data struct containing the data of this tag
+	 */
+	public synchronized DataTypeIf getTag(Long tag) {
+		DataTypeIf data = getHeader().getTag(tag);
 
-    /**
-     * Read a tag with a given tag id.
-     *
-     * @param tagid A RPM tag id
-     * @return The name of the RPM tag
-     * @throws IllegalArgumentException if the tag id was not found
-     * @see Header#getTagNameForId(long)
-     */
-    public synchronized String getTagNameForId(long tagid) {
-        return getHeader().getTagNameForId(tagid);
-    }
+		// set the locale for all I18N strings
+		if (data instanceof I18NSTRING) {
+			((I18NSTRING) data).setLocaleIndex(localePosition);
+		}
 
-    /**
-     * Get all tag names contained in this rpm file.
-     *
-     * @return All tag names contained in this rpm file.
-     */
-    public synchronized String[] getTagNames() {
-        return getHeader().getTagNames();
-    }
+		return data;
+	}
 
-    /**
-     * Read informations of a rpm file out of an input stream.
-     *
-     * @param rpmInputStream The input stream representing the rpm file
-     * @throws IOException if an error occurs during read of the rpm file
-     */
-    private void readFromStream(InputStream rpmInputStream) throws IOException {
-        InputStream inputStream = new DataInputStream(rpmInputStream);
+	/**
+	 * Get a tag by id as a long
+	 * 
+	 * @param tag
+	 *            A tag id as a long
+	 * @return A data struct containing the data of this tag
+	 */
+	public synchronized DataTypeIf getTag(long tag) {
+		return getTag(new Long(tag));
+	}
 
-        lead = new RPMLead((DataInputStream) inputStream);
-        signature = new RPMSignature((DataInputStream) inputStream);
+	/**
+	 * Get a tag by name
+	 * 
+	 * @param tagname
+	 *            A tag name
+	 * @return A data struct containing the data of this tag
+	 */
+	public synchronized DataTypeIf getTag(String tagname) {
+		return getTag(getTagIdForName(tagname));
+	}
 
-        if (logger.isLoggable(Level.FINER)) {
-            logger.finer("Signature Size: " + signature.getSize());
-        }
+	/**
+	 * Read a tag with a given tag name.
+	 * 
+	 * @param tagname
+	 *            A RPM tag name
+	 * @return The id of the RPM tag
+	 * @throws IllegalArgumentException
+	 *             if the tag name was not found
+	 * @see Header#getTagIdForName(String)
+	 */
+	public synchronized long getTagIdForName(String tagname) {
+		return getHeader().getTagIdForName(tagname);
+	}
 
-        header = new RPMHeader((DataInputStream) inputStream);
+	/**
+	 * Get all tag ids contained in this rpm file.
+	 * 
+	 * @return All tag ids contained in this rpm file.
+	 */
+	public synchronized long[] getTagIds() {
+		return getHeader().getTagIds();
+	}
 
-        if (logger.isLoggable(Level.FINER)) {
-            logger.finer("Header Size: " + header.getSize());
-        }
+	/**
+	 * Read a tag with a given tag id.
+	 * 
+	 * @param tagid
+	 *            A RPM tag id
+	 * @return The name of the RPM tag
+	 * @throws IllegalArgumentException
+	 *             if the tag id was not found
+	 * @see Header#getTagNameForId(long)
+	 */
+	public synchronized String getTagNameForId(long tagid) {
+		return getHeader().getTagNameForId(tagid);
+	}
 
-        final DataTypeIf payloadTag = getTag("PAYLOADFORMAT");
-        final String payloadFormat = payloadTag != null ?
-                payloadTag.toString() : "cpio";
-        final DataTypeIf payloadCompressionTag = getTag("PAYLOADCOMPRESSOR");
-        final String payloadCompressor = payloadCompressionTag != null ?
-                payloadCompressionTag.toString() : "gzip";
+	/**
+	 * Get all tag names contained in this rpm file.
+	 * 
+	 * @return All tag names contained in this rpm file.
+	 */
+	public synchronized String[] getTagNames() {
+		return getHeader().getTagNames();
+	}
 
-        if (payloadFormat.equals("cpio")) {
-            if (logger.isLoggable(Level.FINER)) {
-                logger.finer("PAYLOADCOMPRESSOR: " + payloadCompressor);
-            }
+	/**
+	 * Read informations of a rpm file out of an input stream.
+	 * 
+	 * @param rpmInputStream
+	 *            The input stream representing the rpm file
+	 * @throws IOException
+	 *             if an error occurs during read of the rpm file
+	 */
+	private void readFromStream(InputStream rpmInputStream) throws IOException {
+		InputStream inputStream = new DataInputStream(rpmInputStream);
 
-            if (payloadCompressor.equals("gzip")) {
-                inputStream = new GZIPInputStream(rpmInputStream);
-            } else if (payloadCompressor.equals("bzip2")) {
-                inputStream = new CBZip2InputStream(rpmInputStream);
-            } else if (payloadCompressor.equals("none")) {
-                inputStream = rpmInputStream;
-            } else {
-                throw new IOException("Unsupported compressor type "
-                        + payloadCompressor);
-            }
+		lead = new RPMLead((DataInputStream) inputStream);
+		signature = new RPMSignature((DataInputStream) inputStream);
 
-            ByteCountInputStream countInputStream = new ByteCountInputStream(
-                    inputStream);
-            CPIOInputStream cpioInputStream = new CPIOInputStream(
-                    countInputStream);
-            CPIOEntry readEntry;
-            ArrayList fileNamesList = new ArrayList();
-            String fileEntry;
-            while ((readEntry = cpioInputStream.getNextEntry()) != null) {
-                if (logger.isLoggable(Level.FINER)) {
-                    logger.finer("Read CPIO entry: " + readEntry.getName()
-                            + " ;mode:" + readEntry.getMode());
-                }
-                if (readEntry.isRegularFile() || readEntry.isSymbolicLink()
-                        || readEntry.isDirectory()) {
-                    fileEntry = readEntry.getName();
-                    if (fileEntry.startsWith("./"))
-                        fileEntry = fileEntry.substring(1);
-                    fileNamesList.add(fileEntry);
-                }
-            }
-            getHeader().setTag(
-                    "FILENAMES",
-                    TypeFactory.createSTRING_ARRAY((String[]) fileNamesList
-                            .toArray(new String[0])));
-        } else {
-            throw new IOException("Unsupported Payload type " + payloadFormat);
-        }
-        // TODO check ARCHIVESIZE with countInputStream.getCount();
+		if (logger.isLoggable(Level.FINER)) {
+			logger.finer("Signature Size: " + signature.getSize());
+		}
 
-        // filling in signatures
-        // TODO: check signatures!
-        setHeaderTagFromSignature("SIGSIZE", "SIZE");
-        setHeaderTagFromSignature("SIGLEMD5_1", "LEMD5_1");
-        setHeaderTagFromSignature("SIGPGP", "PGP");
-        setHeaderTagFromSignature("SIGLEMD5_2", "LEMD5_2");
-        setHeaderTagFromSignature("SIGMD5", "MD5");
-        setHeaderTagFromSignature("SIGGPG", "GPG");
-        setHeaderTagFromSignature("SIGPGP5", "PGP5");
-        setHeaderTagFromSignature("BADSHA1_1", "BADSHA1_1");
-        setHeaderTagFromSignature("BADSHA1_2", "BADSHA1_2");
-        setHeaderTagFromSignature("DSAHEADER", "DSA");
-        setHeaderTagFromSignature("RSAHEADER", "RSA");
-        setHeaderTagFromSignature("SHA1HEADER", "SHA1");
-        setHeaderTagFromSignature("ARCHIVESIZE", "PAYLOADSIZE");
-        rpmInputStream.close();
+		header = new RPMHeader((DataInputStream) inputStream);
 
-    }
+		if (logger.isLoggable(Level.FINER)) {
+			logger.finer("Header Size: " + header.getSize());
+		}
 
-    private void setHeaderTagFromSignature(String headerTag, String signatureTag) {
-        if (getHeader().getTag(headerTag) == null)
-            getHeader().setTag(headerTag,
-                    getSignature().getTag(signatureTag));
-    }
+		final DataTypeIf payloadTag = getTag("PAYLOADFORMAT");
+		final String payloadFormat = payloadTag != null ? payloadTag.toString()
+				: "cpio";
+		final DataTypeIf payloadCompressionTag = getTag("PAYLOADCOMPRESSOR");
+		final String payloadCompressor = payloadCompressionTag != null ? payloadCompressionTag
+				.toString()
+				: "gzip";
 
-    /**
-     * Release locked resources.
-     */
-    public void close() {
-        reset();
-    }
+		if (payloadFormat.equals("cpio")) {
+			if (logger.isLoggable(Level.FINER)) {
+				logger.finer("PAYLOADCOMPRESSOR: " + payloadCompressor);
+			}
 
-    /**
-     * Same as doing toXML(true).
-     *
-     * @return String containing the XML representation of this RPM.
-     * @see #toXML(boolean)
-     */
-    public String toXML() {
-        StringWriter buf = new StringWriter();
-        try {
-            toXML(buf, true);
-            buf.flush();
-            return buf.toString();
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
-    }
+			if (payloadCompressor.equals("gzip")) {
+				inputStream = new GZIPInputStream(rpmInputStream);
+			} else if (payloadCompressor.equals("bzip2")) {
+				inputStream = new CBZip2InputStream(rpmInputStream);
+			} else if (payloadCompressor.equals("lzma")) {
+				try {
+					final PipedOutputStream pout = new PipedOutputStream();
+					inputStream = new PipedInputStream(pout);
+					byte[] properties = new byte[5];
+					if (rpmInputStream.read(properties, 0, 5) != 5)
+						throw (new IOException("input .lzma is too short"));
+					final SevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();
+					decoder.SetDecoderProperties(properties);
+					long outSize = 0;
+					for (int i = 0; i < 8; i++) {
+						int v = rpmInputStream.read();
+						if (v < 0)
+							throw (new IOException("lzma error : Can't Read 1"));
+						outSize |= ((long) v) << (8 * i);
+					}
+					if (outSize == -1)
+						outSize = Long.MAX_VALUE;
 
-    /**
-     * Returns an XML version of this file
-     *
-     * @param excludePayload If this is true, the payload will not be included in the XML.
-     * @return XML rpm.
-     */
-    public String toXML(boolean excludePayload) {
-        StringWriter buf = new StringWriter();
-        try {
-            toXML(buf, excludePayload);
-            buf.flush();
-            return buf.toString();
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
-    }
+					Decode decoderRunnable = new Decode(decoder,
+							rpmInputStream, pout, outSize);
+					Thread t = new Thread(decoderRunnable, "LZMA Decoder");
+					t.start();
+				} catch (NoClassDefFoundError e) {
+					String message = "No LZMA library found. Attach p7zip library to classpath (http://p7zip.sourceforge.net/)";
+					logger.severe(message);
+					throw new IOException(message);
+				}
+			} else if (payloadCompressor.equals("none")) {
+				inputStream = rpmInputStream;
+			} else {
+				throw new IOException("Unsupported compressor type "
+						+ payloadCompressor);
+			}
 
-    /**
-     * Outputs this rpm in an XML format to the specified i/o writer.
-     *
-     * @param writer         Writer stream.
-     * @param excludePayload If this is true, the payload will not be included in the XML.
-     * @throws IOException If an error occurred writing to the writer.
-     */
-    public void toXML(Writer writer, boolean excludePayload) throws IOException {
-        // TODO
-    }
+			ByteCountInputStream countInputStream = new ByteCountInputStream(
+					inputStream);
+			CPIOInputStream cpioInputStream = new CPIOInputStream(
+					countInputStream);
+			CPIOEntry readEntry;
+			List fileNamesList = new ArrayList();
+			String fileEntry;
+			while ((readEntry = cpioInputStream.getNextEntry()) != null) {
+				if (logger.isLoggable(Level.FINER)) {
+					logger.finer("Read CPIO entry: " + readEntry.getName()
+							+ " ;mode:" + readEntry.getMode());
+				}
+				if (readEntry.isRegularFile() || readEntry.isSymbolicLink()
+						|| readEntry.isDirectory()) {
+					fileEntry = readEntry.getName();
+					if (fileEntry.startsWith("./"))
+						fileEntry = fileEntry.substring(1);
+					fileNamesList.add(fileEntry);
+				}
+			}
+			getHeader().setTag(
+					"FILENAMES",
+					TypeFactory.createSTRING_ARRAY((String[]) fileNamesList
+							.toArray(new String[0])));
+		} else {
+			throw new IOException("Unsupported Payload type " + payloadFormat);
+		}
+		// TODO check ARCHIVESIZE with countInputStream.getCount();
 
-    private class ByteCountInputStream extends FilterInputStream {
-        private int count = 0;
+		// filling in signatures
+		// TODO: check signatures!
+		setHeaderTagFromSignature("SIGSIZE", "SIZE");
+		setHeaderTagFromSignature("SIGLEMD5_1", "LEMD5_1");
+		setHeaderTagFromSignature("SIGPGP", "PGP");
+		setHeaderTagFromSignature("SIGLEMD5_2", "LEMD5_2");
+		setHeaderTagFromSignature("SIGMD5", "MD5");
+		setHeaderTagFromSignature("SIGGPG", "GPG");
+		setHeaderTagFromSignature("SIGPGP5", "PGP5");
+		setHeaderTagFromSignature("BADSHA1_1", "BADSHA1_1");
+		setHeaderTagFromSignature("BADSHA1_2", "BADSHA1_2");
+		setHeaderTagFromSignature("DSAHEADER", "DSA");
+		setHeaderTagFromSignature("RSAHEADER", "RSA");
+		setHeaderTagFromSignature("SHA1HEADER", "SHA1");
+		setHeaderTagFromSignature("ARCHIVESIZE", "PAYLOADSIZE");
+		rpmInputStream.close();
 
-        public ByteCountInputStream(InputStream is) {
-            super(is);
-        }
+	}
 
-        public int getCount() {
-            return count;
-        }
+	private void setHeaderTagFromSignature(String headerTag, String signatureTag) {
+		if (getHeader().getTag(headerTag) == null)
+			getHeader().setTag(headerTag, getSignature().getTag(signatureTag));
+	}
 
-        public int read() throws IOException {
-            count++;
-            return in.read();
-        }
+	/**
+	 * Release locked resources.
+	 */
+	public void close() {
+		reset();
+	}
 
-        public int read(byte b[]) throws IOException {
-            int size = read(b, 0, b.length);
-            count += size;
-            return size;
-        }
+	/**
+	 * Same as doing toXML(true).
+	 * 
+	 * @return String containing the XML representation of this RPM.
+	 * @see #toXML(boolean)
+	 */
+	public String toXML() {
+		StringWriter buf = new StringWriter();
+		try {
+			toXML(buf, true);
+			buf.flush();
+			return buf.toString();
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
+	}
 
-        public int read(byte b[], int off, int len) throws IOException {
-            int size = in.read(b, off, len);
-            count += size;
-            return size;
-        }
+	/**
+	 * Returns an XML version of this file
+	 * 
+	 * @param excludePayload
+	 *            If this is true, the payload will not be included in the XML.
+	 * @return XML rpm.
+	 */
+	public String toXML(boolean excludePayload) {
+		StringWriter buf = new StringWriter();
+		try {
+			toXML(buf, excludePayload);
+			buf.flush();
+			return buf.toString();
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
+	}
 
-        public long skip(long n) throws IOException {
-            long size = in.skip(n);
-            count += size;
-            return size;
-        }
-    }
+	/**
+	 * Outputs this rpm in an XML format to the specified i/o writer.
+	 * 
+	 * @param writer
+	 *            Writer stream.
+	 * @param excludePayload
+	 *            If this is true, the payload will not be included in the XML.
+	 * @throws IOException
+	 *             If an error occurred writing to the writer.
+	 */
+	public void toXML(Writer writer, boolean excludePayload) throws IOException {
+		// TODO
+	}
 
-    /**
-     * Load an RPM file using the native rpm executables.
-     *
-     * @param file RPM file.
-     */
-    public static RPMFile loadUsingNative(File file) {
-        return null; // TODO
-    }
+	private class ByteCountInputStream extends FilterInputStream {
+		private int count = 0;
+
+		public ByteCountInputStream(InputStream is) {
+			super(is);
+		}
+
+		public int getCount() {
+			return count;
+		}
+
+		public int read() throws IOException {
+			count++;
+			return in.read();
+		}
+
+		public int read(byte b[]) throws IOException {
+			int size = read(b, 0, b.length);
+			count += size;
+			return size;
+		}
+
+		public int read(byte b[], int off, int len) throws IOException {
+			int size = in.read(b, off, len);
+			count += size;
+			return size;
+		}
+
+		public long skip(long n) throws IOException {
+			long size = in.skip(n);
+			count += size;
+			return size;
+		}
+	}
+
+	/**
+	 * Load an RPM file using the native rpm executables.
+	 * 
+	 * @param file
+	 *            RPM file.
+	 */
+	public static RPMFile loadUsingNative(File file) {
+		return null; // TODO
+	}
+
+	static final class Decode implements Runnable {
+		private SevenZip.Compression.LZMA.Decoder decoder;
+
+		private InputStream inputStream;
+
+		private OutputStream outputStream;
+
+		private long size;
+
+		public Decode(Decoder decoder, InputStream inputStream,
+				OutputStream outputStream, long size) {
+			super();
+			this.decoder = decoder;
+			this.inputStream = inputStream;
+			this.outputStream = outputStream;
+			this.size = size;
+		}
+
+		public void run() {
+			try {
+				decoder.Code(inputStream, outputStream, size,
+						new ICodeProgress() {
+							public void SetProgress(long arg0, long arg1) {
+								// ignore
+							}
+						});
+				outputStream.close();
+			} catch (IOException e) {
+			}
+			try {
+				outputStream.close();
+			} catch (IOException e) {
+			}
+		}
+	}
 }

Modified: trunk/src/java/com/jguild/jrpm/io/RPMLead.java
===================================================================
--- trunk/src/java/com/jguild/jrpm/io/RPMLead.java	2006-11-08 00:13:40 UTC (rev 19)
+++ trunk/src/java/com/jguild/jrpm/io/RPMLead.java	2008-04-20 17:14:01 UTC (rev 20)
@@ -51,11 +51,16 @@
         }
 
         try {
-            check(inputStream.readUnsignedByte() == 0xED);
-            check(inputStream.readUnsignedByte() == 0xAB);
-            check(inputStream.readUnsignedByte() == 0xEE);
-            check(inputStream.readUnsignedByte() == 0xDB);
+            int magic = inputStream.readUnsignedByte();
+            check(magic == 0xED, "Lead magic 0x"+ Integer.toHexString(magic) + " != 0xED");
+            magic = inputStream.readUnsignedByte();
+            check(magic == 0xAB, "Lead magic 0x"+ Integer.toHexString(magic) + " != 0xAB");
+            magic = inputStream.readUnsignedByte();
+            check(magic == 0xEE, "Lead magic 0x"+ Integer.toHexString(magic) + " != 0xEE");
+            magic = inputStream.readUnsignedByte();
+            check(magic == 0xDB, "Lead magic 0x"+ Integer.toHexString(magic) + " != 0xDB");
             major = inputStream.readUnsignedByte();
+            check(major < 5, "Major Number should be less than 5");
 
             if (logger.isLoggable(Level.FINER)) {
                 logger.finer("major: " + major);
@@ -102,10 +107,8 @@
 
             inputStream.skipBytes(16);
 
-            check(major < 5);
-            check(!type.equals(LeadType.UNKNOWN));
-
-            check(!sigType.equals(LeadType.UNKNOWN));
+            check(!type.equals(LeadType.UNKNOWN), "Type is not specified");
+            check(!sigType.equals(LeadType.UNKNOWN), "Signaturetype is not specified");           
         } finally {
             if (logger.isLoggable(Level.FINER)) {
                 logger.finer("Finished Reading Lead");
@@ -186,10 +189,10 @@
         return type;
     }
 
-    private static final void check(boolean test)
+    private static final void check(boolean test, String message)
             throws IOException {
         if (!test) {
-            throw new IOException("Corrupted archive");
+            throw new IOException("Corrupted archive: "+message);
         }
     }
 }

Added: trunk/src/java/com/jguild/jrpm/tools/Info.java
===================================================================
--- trunk/src/java/com/jguild/jrpm/tools/Info.java	                        (rev 0)
+++ trunk/src/java/com/jguild/jrpm/tools/Info.java	2008-04-20 17:14:01 UTC (rev 20)
@@ -0,0 +1,132 @@
+/*
+ * Created on 02.04.2008
+ *
+ * To change the template for this generated file go to
+ * Window - Preferences - Java - Code Generation - Code and Comments
+ */
+package com.jguild.jrpm.tools;
+
+import java.io.File;
+import java.io.IOException;
+
+import com.jguild.jrpm.io.RPMFile;
+import com.jguild.jrpm.io.datatype.DataTypeIf;
+
+public class Info {
+	private static double kbs = 0;
+
+	private static long start_base = 0;
+
+	/**
+	 * @param args
+	 * @throws IOException
+	 */
+	public static void main(String[] args) {
+		File dir = new File(args[0]);
+
+		start_base = System.currentTimeMillis();
+
+		scanFiles(dir.listFiles());
+		print("DONE ================================== ", 45, false);
+		print(getTime(System.currentTimeMillis() - start_base), 10, true);
+	}
+
+	/**
+	 * @param files
+	 */
+	private static void scanFiles(File[] files) {
+		for (int pos = 0; pos < files.length; pos++) {
+			if (files[pos].isDirectory()) {
+				scanFiles(files[pos].listFiles());
+				continue;
+			}
+			if (!files[pos].getName().endsWith(".rpm"))
+				continue;
+
+			long start = System.currentTimeMillis();
+			try {
+
+				print(files[pos].getName(), 40, false);
+				RPMFile rpm = new RPMFile(files[pos]);
+				rpm.parse();
+
+				print(" ", 1, false);
+				print("OK!", 5, false);
+				print(" ", 1, false);
+				long time = System.currentTimeMillis() - start;
+				print(getTime(time++), 8, true);
+				print(" ", 1, false);
+				print(rpm.getTag("PAYLOADCOMPRESSOR"), 6, true);
+				print(" ", 1, false);
+				print(rpm.getTag("VENDOR"), 20, false);
+				print(" ", 1, false);
+				double kb = (files[pos].length() / 1024d);
+				kbs += kb;
+				print(Math.round(kb / (time / 1000d)) + " KB/s", 20, false);
+				print(Math.round(kbs
+						/ ((System.currentTimeMillis() - start_base) / 1000d))
+						+ " KB/s", 20, false);
+				System.out.println();
+			} catch (Exception e) {
+				print(" ", 1, false);
+				print("FAILED!", 10, false);
+				System.out.println();
+				e.printStackTrace(System.out);
+			}
+		}
+	}
+
+	/**
+	 * @param tag
+	 * @param i
+	 * @param b
+	 */
+	private static void print(DataTypeIf tag, int i, boolean b) {
+		String str = "";
+		if (tag != null) {
+			str = tag.toString();
+		}
+		print(str, i, b);
+	}
+
+	/**
+	 * @param l
+	 * @return
+	 */
+	private static String getTime(long time) {
+		String einheit = "ms";
+		if (time > 2000) {
+			time /= 1000;
+			einheit = "s";
+
+			if (time > 120) {
+				time /= 60;
+				einheit = "m";
+			}
+		}
+		return time + " " + einheit;
+	}
+
+	/**
+	 * @param string
+	 * @param i
+	 */
+	private static void print(String string, int size, boolean right) {
+		int length = string.length();
+		if (length > size) {
+			string = string.substring(0, size);
+		}
+		if (right) {
+			while (length++ < size) {
+				System.out.print(" ");
+			}
+		}
+		System.out.print(string);
+
+		if (!right) {
+			while (length++ < size) {
+				System.out.print(" ");
+			}
+		}
+	}
+}


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone