ReadUTF() публичный Метод

Reads in a string that has been encoded using a modified UTF-8 format.
public ReadUTF ( ) : string
Результат string
Пример #1
0
        /// <summary>
        /// Find the specified name in the index and load a time zone
        /// definition.  If the name is not found then return null.
        /// </summary>
        static TimeZone loadTimeZone(string x)
        {
            string name = x;
              int slash = x.LastIndexOf('/');
              if (slash > 0) name = name.Substring(slash+1);

              // find index, which maps the file offset
              // TODO: why doesn't BinarySearch work?
              // int ix = Array.BinarySearch(indexNames, name);
              int ix = -1;
              for (int i=0; i<indexNames.Length; ++i)
            if (name == indexNames[i]) { ix = i; break; }
              if (ix < 0) return null;

              // map full name
              string fullName = name;
              string prefix = prefixes[indexPrefixes[ix] & 0xff];
              if (prefix.Length != 0) fullName = prefix + "/" + name;
              if (slash > 0 && x != fullName) return null;

              // create time zone instance
              TimeZone tz = new TimeZone();
              tz.m_name      = name;
              tz.m_fullName  = fullName;

              // read time zone definition from database file
              FileStream f = dbFile.OpenRead();
              DataReader d = new DataReader(f);
              try
              {
            f.Seek(indexOffsets[ix], SeekOrigin.Begin);
            int numRules  = d.ReadUnsignedShort();
            tz.rules = new Rule[numRules];
            for (int i=0; i<numRules; ++i)
            {
              Rule r = tz.rules[i] = new Rule();
              r.startYear = d.ReadUnsignedShort();
              r.offset    = d.ReadInt();
              r.stdAbbr   = d.ReadUTF();
              r.dstOffset = d.ReadInt();
              if (r.dstOffset == 0) continue;
              r.dstAbbr   = d.ReadUTF();
              r.dstStart  = loadDstTime(d);
              r.dstEnd    = loadDstTime(d);
              if (i != 0 && tz.rules[i-1].startYear <= r.startYear)
            throw new IOException("TimeZone rules not sorted: " + name);
            }
              }
              finally
              {
            f.Close();
              }
              return tz;
        }
Пример #2
0
        //////////////////////////////////////////////////////////////////////////
        // Database
        //////////////////////////////////////////////////////////////////////////
        //
        // TimeZone database format:
        //
        // ftz
        // {
        //   u8    magic ("fantz 02")
        //   utf   summary
        //   u1    numPrefixes
        //   utf[] prefixes
        //   u2    numIndexItems
        //   indexItems[]   // sorted by name
        //   {
        //     u1   prefix id
        //     utf  name
        //     u4   fileOffset
        //   }
        //   timeZones[]
        //   {
        //     u2   numRules
        //     rules[]
        //     {
        //       u2   startYear
        //       i4   utcOffset (seconds)
        //       utf  stdAbbr
        //       i4   dstOffset (seconds); if zero rest is skipped
        //       [
        //         utf       dstAbbr
        //         dstTime   dstStart
        //         dstTime   dstEnd
        //       ]
        //     }
        //   }
        //
        //   dstTime
        //   {
        //     u1  month
        //     u1  onMode 'd', 'l', '>', '<' (date, last, >=, and <=)
        //     u1  onWeekday (0-6)
        //     u1  onDay
        //     i4  atTime (seconds)
        //     u1  atMode 'w' , 's', 'u' (wall, standad, universal)
        //   }
        //
        //  The timezone database is generated by the "/adm/buildtz.fan"
        //  script.  Refer to the "zic.8.txt" source file the code
        //  distribution of the Olson database to further describe
        //  model of the original data.
        //
        /// <summary>
        /// Load the name and file offset list from file into memory.
        /// </summary>
        static void loadIndex()
        {
            DataReader reader = new DataReader(new BufferedStream(dbFile.OpenRead()));
              try
              {
            // check magic "fantz 02"
            long magic = reader.ReadLong();
            if (magic != 0x66616e747a203032L)
              throw new IOException("Invalid magic 0x" + magic.ToString("X").ToLower());
            reader.ReadUTF();

            // load prefixes
            int numPrefixes = reader.ReadByte();
            prefixes = new string[numPrefixes];
            for (int i=0; i<numPrefixes; ++i)
              prefixes[i] = reader.ReadUTF();

            // load the zones and verify in sort order
            int num = reader.ReadUnsignedShort();
            indexPrefixes = new byte[num];
            indexNames    = new string[num];
            indexOffsets  = new int[num];
            for (int i=0; i<num; ++i)
            {
              indexPrefixes[i] = reader.ReadByte();
              indexNames[i]    = reader.ReadUTF();
              indexOffsets[i]  = reader.ReadInt();
              if (i != 0 && String.Compare(indexNames[i-1], indexNames[i], StringComparison.Ordinal) >= 0)
            throw new IOException("Index not sorted");
            }
              }
              finally
              {
            reader.Close();
              }
        }