Example #1
0
        /**
         * This method creates a rpm data type out of a input stream and an
         * IndexEntry. The object must at the current position of the input stream.
         * The length is only needed for string objects; the string objects will
         * read length bytes of the input stream and will try to convert the data
         * into a rpm data type.
         *
         * @param inputStream
         *            The input stream
         * @param indexEntry
         *            The IndexEntry that should be read
         * @param length
         *            The number of bytes to read for string objects
         *
         * @return One of the rpm data types coresponding with the type contained in
         *         the IndexEntry.
         *
         * @throws IOException
         *             if something was wrong during reading of the input stream
         */
        public static DataTypeIf createFromStream(
            java.io.DataInputStream inputStream, IndexEntry indexEntry,
            long length)
        {//throws IOException {
            DataTypeIf ret = null;

            switch ((int)indexEntry.getType().getId())
            {
            case RPMIndexType._NULL:
                ret = NULL.readFromStream(indexEntry);
                break;

            case RPMIndexType._CHAR:
                ret = CHAR.readFromStream(inputStream, indexEntry);
                break;

            case RPMIndexType._INT8:
                ret = INT8.readFromStream(inputStream, indexEntry);
                break;

            case RPMIndexType._INT16:
                ret = INT16.readFromStream(inputStream, indexEntry);
                break;

            case RPMIndexType._INT32:
                ret = INT32.readFromStream(inputStream, indexEntry);
                break;

            case RPMIndexType._INT64:
                ret = INT64.readFromStream(inputStream, indexEntry);
                break;

            case RPMIndexType._STRING:
                ret = STRING.readFromStream(inputStream, indexEntry, length);
                break;

            case RPMIndexType._BIN:
                ret = BIN.readFromStream(inputStream, indexEntry);
                break;

            case RPMIndexType._STRING_ARRAY:
                ret = STRING_ARRAY.readFromStream(inputStream, indexEntry, length);
                break;

            case RPMIndexType._I18NSTRING:
                ret = I18NSTRING.readFromStream(inputStream, indexEntry, length);
                break;

            default:
                // TODO: UNKNOWN
                break;
            }

            return(ret);
        }
Example #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_ARRAY readFromStream(
            java.io.DataInputStream inputStream, IndexEntry indexEntry,
            long length)
        {// throws IOException {
            if (indexEntry.getType() != RPMIndexType.STRING_ARRAY)
            {
                throw new java.lang.IllegalArgumentException("Type <" + indexEntry.getType()
                                                             + "> does not match <" + RPMIndexType.STRING_ARRAY + ">");
            }

            // 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);

                // add 1 for \0 in C strings
                off += (data[pos].length() + 1);

                // throw an exception if we have read out of the data space
                if (off > stringData.Length)
                {
                    throw new java.lang.IllegalStateException(
                              "Index wrong; Strings doesn't fit into data area. ["
                              + off + ", " + stringData.Length + "]");
                }
            }

            STRING_ARRAY stringObject = new STRING_ARRAY(data);

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

            return(stringObject);
        }