Exemplo n.º 1
0
        /**
         * Constructs a IndexEntry out of a InputStream. This will read the tag id,
         * the data type, the offset of the data and the number of elements of
         * data. Note that the number of elements varies in its meaning depending
         * on the data type.
         *
         * @param inputStream An InputStream containing a rpm file.
         * @throws IOException If an error occurs during reading from stream
         */
        public IndexEntry(java.io.DataInputStream inputStream)
        {//throws IOException {
            tag = inputStream.readInt();

            if (logger.isLoggable(java.util.logging.Level.FINER))
            {
                logger.finer("tag:" + tag);
            }

            type = RPMIndexType.getRPMIndexType(inputStream.readInt());

            if (logger.isLoggable(java.util.logging.Level.FINER))
            {
                logger.finer("type: " + type);
            }

            offset = inputStream.readInt();

            if (logger.isLoggable(java.util.logging.Level.FINER))
            {
                logger.finer("offset: " + offset);
            }

            count = inputStream.readInt();

            if (logger.isLoggable(java.util.logging.Level.FINER))
            {
                logger.finer("count: " + count);
            }

            check(!type.equals(RPMIndexType.UNKNOWN));
        }
Exemplo n.º 2
0
        /**
         * Constructs a type froma stream
         *
         * @param inputStream An input stream
         * @param indexEntry  The index informations
         * @return The size of the read data
         * @throws IOException if an I/O error occurs.
         */
        public static INT32 readFromStream(java.io.DataInputStream inputStream,
                                           IndexEntry indexEntry)
        {//throws IOException {
            if (indexEntry.getType() != RPMIndexType.INT32)
            {
                throw new java.lang.IllegalArgumentException("Type <" + indexEntry.getType()
                                                             + "> does not match <" + RPMIndexType.INT32 + ">");
            }

            int[] data = new int[(int)indexEntry.getCount()];

            for (int pos = 0; pos < indexEntry.getCount(); pos++)
            {
                data[pos] = inputStream.readInt();
            }

            INT32 int32Object = new INT32(data);

            if (logger.isLoggable(java.util.logging.Level.FINER))
            {
                logger.finer(int32Object.toString());
            }

            // int32Object.size = indexEntry.getType().getSize()
            // * indexEntry.getCount();

            return(int32Object);
        }
Exemplo n.º 3
0
        /**
         * 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");
            }
        }