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

            // initialize temporary space for data
            byte[] stringData = new byte[(int)length];

            // and read it from stream
            inputStream.readFully(stringData);

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

            int off = 0;

            for (int pos = 0; pos < indexEntry.getCount(); pos++)
            {
                data[pos] = RPMUtil.cArrayToString(stringData, off);

                // offset for new string is stringlength + 1 for the \0 in c
                // strings
                if (data[pos].length() == 0)
                {
                    off += data[pos].length();
                }
                else
                {
                    off += (data[pos].length() + 1);
                }

                if (off > stringData.Length)
                {
                    throw new java.lang.IllegalStateException(
                              "Index wrong; Strings doesn't fit into data area. ["
                              + off + ", " + stringData.Length + "]");
                }
            }

            I18NSTRING stringObject = new I18NSTRING(data);

            if (logger.isLoggable(java.util.logging.Level.FINER))
            {
                logger.finer(stringObject.toString());
                if (stringObject.size != stringData.Length)
                {
                    logger.warning("STRING size differs (is:" + stringData.Length
                                   + ";should:" + stringObject.size + ")");
                }
            }

            stringObject.size = stringData.Length;

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

            if (indexEntry.getCount() != 1)
            {
                throw new java.lang.IllegalArgumentException(
                          "There can be only one string per tag of type STRING");
            }

            // initialize temporary space for data
            byte[] stringData = new byte[(int)length];

            // and read it from stream
            inputStream.readFully(stringData);

            String str          = RPMUtil.cArrayToString(stringData, 0);
            STRING stringObject = new STRING(str);

            if (logger.isLoggable(java.util.logging.Level.FINER))
            {
                logger.finer(stringObject.toString());
                if (stringObject.size != stringData.Length)
                {
                    logger.warning("STRING size differs (is:" + stringData.Length
                                   + ";should:" + stringObject.size + ")");
                }
            }

            stringObject.size = stringData.Length;

            return(stringObject);
        }
示例#3
0
        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");
                }
            }
        }