Esempio n. 1
0
        // ----------------------------------------------------------------
        // Constructor

        /// <summary>
        /// Constructs a UPropertyAliases object. The binary file DATA_FILE_NAME is
        /// read from the jar/classpath and unflattened into member variables of this
        /// object.
        /// </summary>
        ///
        public UPropertyAliases()
        {
            // Open the .icu file from the jar/classpath
            Stream
                           mask0 = IBM.ICU.Impl.ICUData.GetRequiredStream(DATA_FILE_NAME);
            BufferedStream b     = new BufferedStream(mask0, DATA_BUFFER_SIZE);

            // Read and discard Unicode version...
            /* byte unicodeVersion[] = */
            IBM.ICU.Impl.ICUBinary.ReadHeader(b, DATA_FORMAT_ID,
                                              this);
            DataInputStream d = new DataInputStream(b);

            // Record the origin position of the file. Keep enough around
            // to seek back to the start of the header.
            d.Mark(256);

            short enumToName_offset    = d.ReadShort();
            short nameToEnum_offset    = d.ReadShort();
            short enumToValue_offset   = d.ReadShort();
            short total_size           = d.ReadShort();
            short valueMap_offset      = d.ReadShort();
            short valueMap_count       = d.ReadShort();
            short nameGroupPool_offset = d.ReadShort();
            short nameGroupPool_count  = d.ReadShort();
            short stringPool_offset    = d.ReadShort();
            short stringPool_count     = d.ReadShort();

            if (DEBUG)
            {
                System.Console.Out.WriteLine("enumToName_offset=" + enumToName_offset + "\n"
                                             + "nameToEnum_offset=" + nameToEnum_offset + "\n"
                                             + "enumToValue_offset=" + enumToValue_offset + "\n"
                                             + "total_size=" + total_size + "\n" + "valueMap_offset="
                                             + valueMap_offset + "\n" + "valueMap_count="
                                             + valueMap_count + "\n" + "nameGroupPool_offset="
                                             + nameGroupPool_offset + "\n" + "nameGroupPool_count="
                                             + nameGroupPool_count + "\n" + "stringPool_offset="
                                             + stringPool_offset + "\n" + "stringPool_count="
                                             + stringPool_count);
            }

            byte[] raw = new byte[total_size];
            d.Reset();
            d.ReadFully(raw);
            d.Close();

            UPropertyAliases.Builder builder = new UPropertyAliases.Builder(raw);

            stringPool = builder
                         .ReadStringPool(stringPool_offset, stringPool_count);

            nameGroupPool = builder.ReadNameGroupPool(nameGroupPool_offset,
                                                      nameGroupPool_count);

            builder.SetupValueMap_map(valueMap_offset, valueMap_count);

            // Some of the following data structures have to be set up
            // here, _not_ in Builder. That's because they are instances
            // of non-static inner classes, and they contain implicit
            // references to this.

            builder.Seek(enumToName_offset);
            enumToName = new UPropertyAliases.NonContiguousEnumToShort(builder);
            builder.NameGroupOffsetToIndex(enumToName.offsetArray);

            builder.Seek(nameToEnum_offset);
            nameToEnum = new UPropertyAliases.NameToEnum(this, builder);

            builder.Seek(enumToValue_offset);
            enumToValue = new UPropertyAliases.NonContiguousEnumToShort(builder);
            builder.ValueMapOffsetToIndex(enumToValue.offsetArray);

            valueMapArray = new UPropertyAliases.ValueMap [valueMap_count];
            for (int i = 0; i < valueMap_count; ++i)
            {
                // Must seek to the start of each entry.
                builder.Seek(builder.valueMap_map[i]);
                valueMapArray[i] = new UPropertyAliases.ValueMap(this, builder);
            }

            builder.Close();
        }