/** * Creates a new RPMSignature object from an input stream * * @param inputStream * The input stream * @throws IOException * if an error occurs on reading informations out of the * stream */ public RPMSignature(java.io.DataInputStream inputStream, Store store) ://throws IOException { base(inputStream, store) { // Make signature size modulo 8 = 0 long fill = (size % 8L); if (fill != 0) { fill = 8 - fill; } if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("skip " + fill + " bytes for signature"); } size += inputStream.skip(fill); }
/** * Create a header structure from an input stream. <p/> The header * structure of a signature or a header can be read and also the index * entries containing the tags for this rpm section (signature or * header). <p/> Unless we have a raw header from headerUnload or the * database, a header is read consisting of the following fields: * <code><pre> * byte magic[3]; (3 byte) (8e ad e8) * int version; (1 byte) * byte reserved[4]; (4 byte) * long num_index; (4 byte) * long num_data; (4 byte) * </pre></code> <p/> Afterwards the index entries are read and then the tags * and the correspondig data entries are read. * * @param inputStream * An inputstream containing rpm file informations * @param rawHeader * Are we a raw header (from headerUnload or rpmdb) * @throws IOException * if an error occurs on reading informations out of the * stream */ public Header(java.io.DataInputStream inputStream, bool rawHeader, Store store) {//throws IOException { this.store = store; if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("Start Reading Header"); } if (!rawHeader) { // Read header size = HEADER_LENGTH; int magic = 0; do { magic = inputStream.readUnsignedByte(); if (magic == 0) { inputStream.skip(7); } } while (magic == 0); check(magic == 0x8E, "Header magic 0x" + java.lang.Integer.toHexString(magic) + " != 0x8E"); magic = inputStream.readUnsignedByte(); check(magic == 0xAD, "Header magic 0x" + java.lang.Integer.toHexString(magic) + " != 0xAD"); magic = inputStream.readUnsignedByte(); check(magic == 0xE8, "Header magic 0x" + java.lang.Integer.toHexString(magic) + " != 0xE8"); version = inputStream.readUnsignedByte(); if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("version: " + version); } // skip reserved bytes inputStream.skipBytes(4); } indexNumber = inputStream.readInt(); if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("indexes available: " + indexNumber); } indexDataSize = inputStream.readInt(); if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("index data size: " + indexDataSize); } // Read indexes // make sure to sort them in order of offset to // be able to read the store without jumping arround in // the file java.util.TreeSet <IndexEntry> _indexes = new java.util.TreeSet <IndexEntry>(new IAC_IndexesComparator()); for (int i = 0; i < this.indexNumber; i++) { IndexEntry index = new IndexEntry(inputStream); _indexes.add(index); size += index.getSize(); } indexes = new IndexEntry[0]; indexes = (IndexEntry[])_indexes.toArray(indexes); // Read store for (int i = 0; i < indexes.Length; i++) { IndexEntry index = indexes[i]; // if (index.getType().equals(RPMIndexType.STRING_ARRAY) || // index.getType().equals(RPMIndexType.STRING) || // index.getType().equals(RPMIndexType.I18NSTRING)) { // if (i < (indexes.length - 1)) { // IndexEntry next = indexes[i + 1]; // // length = next.getOffset() - index.getOffset(); // } else { // length = indexDataSize - index.getOffset(); // } // // // and initialize temporary space for data // stringData = new byte[(int) length]; // // // and read it from stream // inputStream.readFully(stringData); // } DataTypeIf dataObject = null; if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("Reading for tag '" + store.getTagNameForId(index.getTag()) + "' '" + index.getCount() + "' entries of type '" + index.getType().getName() + "'"); } dataObject = TypeFactory .createFromStream(inputStream, index, (i < (indexes.Length - 1)) ? (indexes[i + 1] .getOffset() - index.getOffset()) : (indexDataSize - index.getOffset())); // adjust size size += dataObject.getSize(); store.setTag(index.getTag(), dataObject); } if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer(""); } if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("Finished Reading Header"); } }