/** * 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"); } }
protected internal RPMLead(java.io.DataInputStream inputStream) {//throws IOException { if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("Start Reading Lead"); } try { int magic = inputStream.readUnsignedByte(); check(magic == 0xED, "Lead magic 0x" + java.lang.Integer.toHexString(magic) + " != 0xED"); magic = inputStream.readUnsignedByte(); check(magic == 0xAB, "Lead magic 0x" + java.lang.Integer.toHexString(magic) + " != 0xAB"); magic = inputStream.readUnsignedByte(); check(magic == 0xEE, "Lead magic 0x" + java.lang.Integer.toHexString(magic) + " != 0xEE"); magic = inputStream.readUnsignedByte(); check(magic == 0xDB, "Lead magic 0x" + java.lang.Integer.toHexString(magic) + " != 0xDB"); major = inputStream.readUnsignedByte(); check(major < 5, "Major Number should be less than 5"); if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("major: " + major); } minor = inputStream.readUnsignedByte(); if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("minor: " + minor); } int uS = inputStream.readUnsignedShort(); //LeadType lt; type = LeadType.getLeadType(uS); //type = LeadType.getLeadType(inputStream.readUnsignedShort()); if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("type: " + type.getName()); } arch = LeadArchitecture.getLeadArchitecture(inputStream.readUnsignedShort()); if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("arch: " + arch.getName()); } byte[] nameBuf = new byte[66]; inputStream.readFully(nameBuf); name = RPMUtil.cArrayToString(nameBuf, 0); if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("name: " + name); } os = LeadOS.getLeadOS(inputStream.readUnsignedShort()); if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("os: " + os.getName()); } sigType = LeadSignature.getLeadSignature(inputStream.readUnsignedShort()); if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("sigType: " + sigType.getName()); } inputStream.skipBytes(16); check(!type.equals(LeadType.UNKNOWN), "Type is not specified"); check(!sigType.equals(LeadType.UNKNOWN), "Signaturetype is not specified"); } finally { if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("Finished Reading Lead"); } } }