SF.net SVN: jrpm:[24] trunk/src/java/com/jguild/jrpm/io
[email protected] Sun, 11 Jan 2009 22:00:35 +0000
| Newsgroups | gmane.comp.java.jrpm.devel |
|---|---|
| Message-ID | <[email protected]> |
Revision: 24
http://jrpm.svn.sourceforge.net/jrpm/?rev=24&view=rev
Author: mkuss
Date: 2009-01-11 22:00:35 +0000 (Sun, 11 Jan 2009)
Log Message:
-----------
reformat
Modified Paths:
--------------
trunk/src/java/com/jguild/jrpm/io/RPMFile.java
trunk/src/java/com/jguild/jrpm/io/Store.java
Modified: trunk/src/java/com/jguild/jrpm/io/RPMFile.java
===================================================================
--- trunk/src/java/com/jguild/jrpm/io/RPMFile.java 2009-01-11 21:53:25 UTC (rev 23)
+++ trunk/src/java/com/jguild/jrpm/io/RPMFile.java 2009-01-11 22:00:35 UTC (rev 24)
@@ -49,542 +49,539 @@
* @todo Implement equals()
*/
public class RPMFile {
- public static final Logger logger = Logger.getLogger("jrpm.io");
+ public static final Logger logger = Logger.getLogger("jrpm.io");
- private Header header = null;
+ private Header header = null;
- private RPMLead lead = null;
+ private RPMLead lead = null;
- private Header signature = null;
+ private Header signature = null;
- private int localePosition;
+ private int localePosition;
- private File rpmFile = null;
+ private File rpmFile = null;
- private boolean editingRpmFile = false;
+ private boolean editingRpmFile = false;
- private Store store = new Store();
+ private Store store = new Store();
- /**
- * Creates a new empty RPMFile object.
- */
- public RPMFile() {
- }
+ /**
+ * Creates a new empty RPMFile object.
+ */
+ public RPMFile() {
+ }
- /**
- * Creates a new RPMFile object out of a file.
- *
- * @param fh
- * The file object representing a rpm file
- */
- public RPMFile(File fh) {
- rpmFile = fh;
- }
+ /**
+ * 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 synchronized void reset() {
- header = null;
- lead = null;
- signature = null;
- editingRpmFile = false;
- }
+ private synchronized void reset() {
+ header = null;
+ lead = null;
+ signature = null;
+ editingRpmFile = false;
+ }
- /**
- * 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");
+ /**
+ * 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();
}
- rpmFile = fh;
- reset();
- }
- /**
- * 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");
+ /**
+ * 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");
- if (!rpmFile.exists())
- throw new IllegalStateException("The specified file does not exist");
+ if (!rpmFile.exists())
+ throw new IllegalStateException("The specified file does not exist");
- try {
- readFromStream(new BufferedInputStream(
- new FileInputStream(rpmFile), 4096));
- } catch (IOException e) {
- reset();
- throw e;
+ try {
+ readFromStream(new BufferedInputStream(
+ new FileInputStream(rpmFile), 4096));
+ } catch (IOException e) {
+ reset();
+ throw e;
+ }
+ editingRpmFile = true;
}
- editingRpmFile = true;
- }
- /**
- * Get the header section of this rpm file.
- *
- * @return The rpm header
- */
- public synchronized Header getHeader() {
- if (header == null)
- throw new IllegalStateException("There are no header informations");
+ /**
+ * Get the header section of this rpm file.
+ *
+ * @return The rpm header
+ */
+ public synchronized Header getHeader() {
+ if (header == null)
+ throw new IllegalStateException("There are no header informations");
- return header;
- }
+ return header;
+ }
- /**
- * 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 Store.getKnownTagNames();
- }
+ /**
+ * 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 Store.getKnownTagNames();
+ }
- /**
- * 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");
+ /**
+ * 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 lead;
- }
+ return lead;
+ }
- /**
- * 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;
- }
-
- /**
- * 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();
-
- for (int pos = 0; pos < locales.length; pos++) {
- if (locales[pos].equals(locale)) {
- setLocale(pos);
-
- return;
- }
+ /**
+ * 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;
}
- throw new IllegalArgumentException("Unknown locale <" + locale + ">");
- }
+ /**
+ * 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();
- /**
- * 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();
- }
+ for (int pos = 0; pos < locales.length; pos++) {
+ if (locales[pos].equals(locale)) {
+ setLocale(pos);
- /**
- * Get the signature section of this rpm file
- *
- * @return The rpm signature
- */
- public synchronized Header getSignature() {
- if (signature == null)
- throw new IllegalStateException(
- "There are no signature informations");
+ return;
+ }
+ }
- return signature;
- }
+ 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) {
- DataTypeIf data = store.getTag(tag);
-
- // set the locale for all I18N strings
- if (data instanceof I18NSTRING) {
- ((I18NSTRING) data).setLocaleIndex(localePosition);
+ /**
+ * 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 data;
- }
+ /**
+ * Get the signature section of this rpm file
+ *
+ * @return The rpm signature
+ */
+ public synchronized Header getSignature() {
+ if (signature == null)
+ throw new IllegalStateException(
+ "There are no signature informations");
- /**
- * 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 signature;
+ }
- /**
- * 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 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 = store.getTag(tag);
- /**
- * 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 store.getTagIdForName(tagname);
- }
+ // set the locale for all I18N strings
+ if (data instanceof I18NSTRING) {
+ ((I18NSTRING) data).setLocaleIndex(localePosition);
+ }
- /**
- * Get all tag ids contained in this rpm file.
- *
- * @return All tag ids contained in this rpm file.
- */
- public synchronized long[] getTagIds() {
- return store.getTagIds();
- }
+ return data;
+ }
- /**
- * 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 store.getTagNameForId(tagid);
- }
+ /**
+ * 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));
+ }
- /**
- * Get all tag names contained in this rpm file.
- *
- * @return All tag names contained in this rpm file.
- */
- public synchronized String[] getTagNames() {
- return store.getTagNames();
- }
+ /**
+ * 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));
+ }
- /**
- * 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 {
- ByteCountInputStream allCountInputStream = new ByteCountInputStream(
- rpmInputStream);
- InputStream inputStream = new DataInputStream(allCountInputStream);
+ /**
+ * 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 store.getTagIdForName(tagname);
+ }
- lead = new RPMLead((DataInputStream) inputStream);
- signature = new RPMSignature((DataInputStream) inputStream, store);
+ /**
+ * Get all tag ids contained in this rpm file.
+ *
+ * @return All tag ids contained in this rpm file.
+ */
+ public synchronized long[] getTagIds() {
+ return store.getTagIds();
+ }
- if (logger.isLoggable(Level.FINER)) {
- logger.finer("Signature Size: " + signature.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 store.getTagNameForId(tagid);
}
- header = new RPMHeader((DataInputStream) inputStream, store);
-
- if (logger.isLoggable(Level.FINER)) {
- logger.finer("Header Size: " + header.getSize());
+ /**
+ * Get all tag names contained in this rpm file.
+ *
+ * @return All tag names contained in this rpm file.
+ */
+ public synchronized String[] getTagNames() {
+ return store.getTagNames();
}
- 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";
+ /**
+ * 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 {
+ ByteCountInputStream allCountInputStream = new ByteCountInputStream(
+ rpmInputStream);
+ InputStream inputStream = new DataInputStream(allCountInputStream);
- if (payloadFormat.equals("cpio")) {
- if (logger.isLoggable(Level.FINER)) {
- logger.finer("PAYLOADCOMPRESSOR: " + payloadCompressor);
- }
+ lead = new RPMLead((DataInputStream) inputStream);
+ signature = new RPMSignature((DataInputStream) inputStream, store);
- if (payloadCompressor.equals("gzip")) {
- inputStream = new GZIPInputStream(allCountInputStream);
- } else if (payloadCompressor.equals("bzip2")) {
- inputStream = new CBZip2InputStream(allCountInputStream);
- } else if (payloadCompressor.equals("lzma")) {
- try {
- final PipedOutputStream pout = new PipedOutputStream();
- inputStream = new PipedInputStream(pout);
- byte[] properties = new byte[5];
- if (allCountInputStream.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 = allCountInputStream.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;
-
- Decode decoderRunnable = new Decode(decoder,
- allCountInputStream, 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);
+ if (logger.isLoggable(Level.FINER)) {
+ logger.finer("Signature Size: " + signature.getSize());
}
- } else if (payloadCompressor.equals("none")) {
- inputStream = allCountInputStream;
- } else {
- throw new IOException("Unsupported compressor type "
- + payloadCompressor);
- }
- ByteCountInputStream countInputStream = new ByteCountInputStream(
- inputStream);
- CPIOInputStream cpioInputStream = new CPIOInputStream(
- countInputStream);
- CPIOEntry readEntry;
- List fileNamesList = new ArrayList();
- String fileEntry;
- while ((readEntry = cpioInputStream.getNextEntry()) != null) {
+ header = new RPMHeader((DataInputStream) inputStream, store);
+
if (logger.isLoggable(Level.FINER)) {
- logger.finer("Read CPIO entry: " + readEntry.getName()
- + " ;mode:" + readEntry.getMode());
+ logger.finer("Header Size: " + header.getSize());
}
- if (readEntry.isRegularFile() || readEntry.isSymbolicLink()
- || readEntry.isDirectory()) {
- fileEntry = readEntry.getName();
- if (fileEntry.startsWith("./"))
- fileEntry = fileEntry.substring(1);
- fileNamesList.add(fileEntry);
- }
- }
- store.setTag("FILENAMES", TypeFactory
- .createSTRING_ARRAY((String[]) fileNamesList
- .toArray(new String[0])));
- setHeaderTagFromSignature("ARCHIVESIZE", "PAYLOADSIZE");
- // check ARCHIVESIZE with countInputStream.getCount();
- Object archiveSizeObject = getTag("ARCHIVESIZE");
- if (archiveSizeObject != null) {
- if (archiveSizeObject instanceof INT32) {
- int archiveSize = ((INT32) archiveSizeObject).getData()[0];
- if (archiveSize != countInputStream.getCount()) {
- new IOException("ARCHIVESIZE not correct");
- }
- }
- }
- store.setTag("J_ARCHIVESIZE", TypeFactory
- .createINT64(new long[] { countInputStream.getCount() }));
- } else {
- throw new IOException("Unsupported Payload type " + payloadFormat);
- }
+ 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";
- // 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("DSAHEADER", "DSA");
- setHeaderTagFromSignature("RSAHEADER", "RSA");
- setHeaderTagFromSignature("SHA1HEADER", "SHA1");
+ if (payloadFormat.equals("cpio")) {
+ if (logger.isLoggable(Level.FINER)) {
+ logger.finer("PAYLOADCOMPRESSOR: " + payloadCompressor);
+ }
- store.setTag("J_FILESIZE", TypeFactory
- .createINT64(new long[] { allCountInputStream.getCount() }));
+ if (payloadCompressor.equals("gzip")) {
+ inputStream = new GZIPInputStream(allCountInputStream);
+ } else if (payloadCompressor.equals("bzip2")) {
+ inputStream = new CBZip2InputStream(allCountInputStream);
+ } else if (payloadCompressor.equals("lzma")) {
+ try {
+ final PipedOutputStream pout = new PipedOutputStream();
+ inputStream = new PipedInputStream(pout);
+ byte[] properties = new byte[5];
+ if (allCountInputStream.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 = allCountInputStream.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;
- rpmInputStream.close();
- }
+ Decode decoderRunnable = new Decode(decoder,
+ allCountInputStream, 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 = allCountInputStream;
+ } else {
+ throw new IOException("Unsupported compressor type "
+ + payloadCompressor);
+ }
- private void setHeaderTagFromSignature(String headerTag, String signatureTag) {
- if (store.getTag(headerTag) == null)
- store.setTag(headerTag, store.getTag(signatureTag));
- }
+ 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);
+ }
+ }
+ store.setTag("FILENAMES", TypeFactory
+ .createSTRING_ARRAY((String[]) fileNamesList
+ .toArray(new String[0])));
- /**
- * Release locked resources.
- */
- public void close() {
- reset();
- }
+ setHeaderTagFromSignature("ARCHIVESIZE", "PAYLOADSIZE");
+ // check ARCHIVESIZE with countInputStream.getCount();
+ Object archiveSizeObject = getTag("ARCHIVESIZE");
+ if (archiveSizeObject != null) {
+ if (archiveSizeObject instanceof INT32) {
+ int archiveSize = ((INT32) archiveSizeObject).getData()[0];
+ if (archiveSize != countInputStream.getCount()) {
+ new IOException("ARCHIVESIZE not correct");
+ }
+ }
+ }
+ store.setTag("J_ARCHIVESIZE", TypeFactory
+ .createINT64(new long[] { countInputStream.getCount() }));
+ } else {
+ throw new IOException("Unsupported Payload type " + payloadFormat);
+ }
- /**
- * 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);
- }
- }
+ // 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("DSAHEADER", "DSA");
+ setHeaderTagFromSignature("RSAHEADER", "RSA");
+ setHeaderTagFromSignature("SHA1HEADER", "SHA1");
- /**
- * 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);
- }
- }
+ store.setTag("J_FILESIZE", TypeFactory
+ .createINT64(new long[] { allCountInputStream.getCount() }));
- /**
- * 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
- }
-
- private class ByteCountInputStream extends FilterInputStream {
- private int count = 0;
-
- public ByteCountInputStream(InputStream is) {
- super(is);
+ rpmInputStream.close();
}
- public int getCount() {
- return count;
+ private void setHeaderTagFromSignature(String headerTag, String signatureTag) {
+ if (store.getTag(headerTag) == null)
+ store.setTag(headerTag, store.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;
- static final class Decode implements Runnable {
- private SevenZip.Compression.LZMA.Decoder decoder;
+ public ByteCountInputStream(InputStream is) {
+ super(is);
+ }
- private InputStream inputStream;
+ public int getCount() {
+ return count;
+ }
- private OutputStream outputStream;
+ public int read() throws IOException {
+ count++;
+ return in.read();
+ }
- private long size;
+ public int read(byte b[]) throws IOException {
+ int size = read(b, 0, b.length);
+ count += size;
+ return 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 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;
+ }
}
- 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) {
- }
+ /**
+ * 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/Store.java
===================================================================
--- trunk/src/java/com/jguild/jrpm/io/Store.java 2009-01-11 21:53:25 UTC (rev 23)
+++ trunk/src/java/com/jguild/jrpm/io/Store.java 2009-01-11 22:00:35 UTC (rev 24)
@@ -25,180 +25,180 @@
*
*/
public class Store {
- public static final Logger logger = Logger.getLogger("jrpm.io");
+ public static final Logger logger = Logger.getLogger("jrpm.io");
- private HashMap store = new HashMap();
+ private HashMap store = new HashMap();
- /**
- * 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 DataTypeIf getTag(Long tag) {
- return (DataTypeIf) store.get(tag);
- }
+ /**
+ * 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 DataTypeIf getTag(Long tag) {
+ return (DataTypeIf) store.get(tag);
+ }
- /**
- * 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 DataTypeIf getTag(long tag) {
- return getTag(new Long(tag));
- }
+ /**
+ * 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 DataTypeIf getTag(long tag) {
+ return getTag(new Long(tag));
+ }
- /**
- * Get a tag by name
- *
- * @param tagname
- * A tag name
- * @return A data struct containing the data of this tag
- */
- public DataTypeIf getTag(String tagname) {
- return getTag(getTagIdForName(tagname));
- }
+ /**
+ * Get a tag by name
+ *
+ * @param tagname
+ * A tag name
+ * @return A data struct containing the data of this tag
+ */
+ public DataTypeIf getTag(String tagname) {
+ return getTag(getTagIdForName(tagname));
+ }
- /**
- * Set a tag by id as a Long
- *
- * @param tag
- * A tag id as a Long
- * @param data
- * A data struct containing the data of this tag
- */
- public void setTag(Long tag, DataTypeIf data) {
- isValidTag(tag.longValue());
- store.put(tag, data);
- }
+ /**
+ * Set a tag by id as a Long
+ *
+ * @param tag
+ * A tag id as a Long
+ * @param data
+ * A data struct containing the data of this tag
+ */
+ public void setTag(Long tag, DataTypeIf data) {
+ isValidTag(tag.longValue());
+ store.put(tag, data);
+ }
- /**
- * Set a tag by id as a long
- *
- * @param tag
- * A tag id as a long
- * @param data
- * A data struct containing the data of this tag
- */
- public void setTag(long tag, DataTypeIf data) {
- setTag(new Long(tag), data);
- }
+ /**
+ * Set a tag by id as a long
+ *
+ * @param tag
+ * A tag id as a long
+ * @param data
+ * A data struct containing the data of this tag
+ */
+ public void setTag(long tag, DataTypeIf data) {
+ setTag(new Long(tag), data);
+ }
- /**
- * Set a tag by id as a string
- *
- * @param tagname
- * A tag id as a string
- * @param data
- * A data struct containing the data of this tag
- */
- public void setTag(String tagname, DataTypeIf data) {
- setTag(getTagIdForName(tagname), data);
- }
+ /**
+ * Set a tag by id as a string
+ *
+ * @param tagname
+ * A tag id as a string
+ * @param data
+ * A data struct containing the data of this tag
+ */
+ public void setTag(String tagname, DataTypeIf data) {
+ setTag(getTagIdForName(tagname), data);
+ }
- /**
- * Get all tag ids contained in this rpm file.
- *
- * @return All tag ids contained in this rpm file.
- */
- public long[] getTagIds() {
- Long[] tmp = (Long[]) store.keySet().toArray(new Long[0]);
- long[] ret = new long[tmp.length];
+ /**
+ * Get all tag ids contained in this rpm file.
+ *
+ * @return All tag ids contained in this rpm file.
+ */
+ public long[] getTagIds() {
+ Long[] tmp = (Long[]) store.keySet().toArray(new Long[0]);
+ long[] ret = new long[tmp.length];
- for (int i = 0; i < tmp.length; i++) {
- ret[i] = tmp[i].longValue();
+ for (int i = 0; i < tmp.length; i++) {
+ ret[i] = tmp[i].longValue();
+ }
+
+ return ret;
}
- return ret;
- }
+ /**
+ * Get all tag names contained in this rpm file.
+ *
+ * @return All tag names contained in this rpm file.
+ */
+ public String[] getTagNames() {
+ Long[] tmp = (Long[]) store.keySet().toArray(new Long[0]);
+ String[] ret = new String[tmp.length];
- /**
- * Get all tag names contained in this rpm file.
- *
- * @return All tag names contained in this rpm file.
- */
- public String[] getTagNames() {
- Long[] tmp = (Long[]) store.keySet().toArray(new Long[0]);
- String[] ret = new String[tmp.length];
+ for (int i = 0; i < tmp.length; i++) {
+ ret[i] = getTagNameForId(tmp[i].longValue());
+ }
- for (int i = 0; i < tmp.length; i++) {
- ret[i] = getTagNameForId(tmp[i].longValue());
+ return ret;
}
- return ret;
- }
+ /**
+ * Read a tag with a given tag name. The tag will be read out of the class
+ * defined in getTagEnum().
+ *
+ * @param tagname
+ * A RPM tag name
+ * @return The id of the RPM tag
+ * @throws IllegalArgumentException
+ * if the tag name was not found
+ */
+ public long getTagIdForName(String tagname) {
+ EnumIf e = RPMHeaderTag.getEnumByName(tagname);
- /**
- * Read a tag with a given tag name. The tag will be read out of the
- * class defined in getTagEnum().
- *
- * @param tagname
- * A RPM tag name
- * @return The id of the RPM tag
- * @throws IllegalArgumentException
- * if the tag name was not found
- */
- public long getTagIdForName(String tagname) {
- EnumIf e = RPMHeaderTag.getEnumByName(tagname);
+ if (e == null) {
+ throw new IllegalArgumentException("unknown tag with name <"
+ + tagname + ">");
+ }
- if (e == null) {
- throw new IllegalArgumentException("unknown tag with name <"
- + tagname + ">");
+ return e.getId();
}
- return e.getId();
- }
+ /**
+ * Read a tag with a given tag id. The tag will be read out of the class
+ * defined in getTagEnum().
+ *
+ * @param tagid
+ * A RPM tag id
+ * @return The name of the RPM tag
+ * @throws IllegalArgumentException
+ * if the tag id was not found
+ */
+ public String getTagNameForId(long tagid) {
+ EnumIf e = RPMHeaderTag.getEnumById(tagid);
+ if (e == null) {
+ throw new IllegalArgumentException("unknown tag with id <" + tagid
+ + ">");
+ }
+ return e.getName();
+ }
- /**
- * Read a tag with a given tag id. The tag will be read out of the class
- * defined in getTagEnum().
- *
- * @param tagid
- * A RPM tag id
- * @return The name of the RPM tag
- * @throws IllegalArgumentException
- * if the tag id was not found
- */
- public String getTagNameForId(long tagid) {
- EnumIf e = RPMHeaderTag.getEnumById(tagid);
- if (e == null) {
- throw new IllegalArgumentException("unknown tag with id <" + tagid
- + ">");
+ /**
+ * Test if the given tagid is associated with a valid tag
+ *
+ * @param tagid
+ * The id of a tag
+ * @return TRUE if the tagid is valid
+ */
+ public boolean isValidTag(long tagid) {
+ return RPMHeaderTag.getEnumById(tagid) != null;
}
- return e.getName();
- }
- /**
- * Test if the given tagid is associated with a valid tag
- *
- * @param tagid
- * The id of a tag
- * @return TRUE if the tagid is valid
- */
- public boolean isValidTag(long tagid) {
- return RPMHeaderTag.getEnumById(tagid) != null;
- }
+ /**
+ * Test if the given tagname is associated with a valid tag
+ *
+ * @param tagname
+ * The name of a tag
+ * @return TRUE if the tagname is valid
+ */
+ public boolean isValidTag(String tagname) {
+ return RPMHeaderTag.getEnumByName(tagname) != null;
+ }
- /**
- * Test if the given tagname is associated with a valid tag
- *
- * @param tagname
- * The name of a tag
- * @return TRUE if the tagname is valid
- */
- public boolean isValidTag(String tagname) {
- return RPMHeaderTag.getEnumByName(tagname) != null;
- }
-
- /**
- * Read all known tag names for this header structure.
- *
- * @return An array of tag names
- */
- public static String[] getKnownTagNames() {
- return RPMHeaderTag.getEnumNames();
- }
+ /**
+ * Read all known tag names for this header structure.
+ *
+ * @return An array of tag names
+ */
+ public static String[] getKnownTagNames() {
+ return RPMHeaderTag.getEnumNames();
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB