示例#1
0
文件: INT8.cs 项目: bastie/NetVampire
        /**
         * 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 INT8 readFromStream(java.io.DataInputStream inputStream,
                                          IndexEntry indexEntry)
        {//throws IOException {
            if (indexEntry.getType() != RPMIndexType.INT8)
            {
                throw new java.lang.IllegalArgumentException("Type <" + indexEntry.getType()
                                                             + "> does not match <" + RPMIndexType.INT8 + ">");
            }

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

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

            INT8 int8Object = new INT8(data);

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

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

            return(int8Object);
        }
示例#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 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);
        }
示例#3
0
        /**
         * Constructs a type froma stream
         *
         * @param indexEntry The index informations
         * @return The size of the read data
         */
        public static NULL readFromStream(IndexEntry indexEntry)
        {
            if (indexEntry.getType() != RPMIndexType.NULL)
            {
                throw new java.lang.IllegalArgumentException("Type <" + indexEntry.getType()
                                                             + "> does not match <" + RPMIndexType.NULL + ">");
            }

            NULL nullObject = new NULL((int)indexEntry.getCount());

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

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

            return(nullObject);
        }
示例#4
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);
        }