Пример #1
0
 private MapFile()
 {
     // only to create a dummy empty file.
     databaseIndexCache = null;
     fileSize           = 0;
     inputFile          = null;
     mapFileHeader      = null;
     readBuffer         = null;
     timestamp          = DateTimeHelperClass.CurrentUnixTimeMillis();
 }
Пример #2
0
        /// <summary>
        /// Opens the given map file, reads its header data and validates them.
        /// </summary>
        /// <param name="mapFile"> the map file. </param>
        /// <param name="language"> the language to use (may be null). </param>
        /// <exception cref="MapFileException"> if the given map file is null or invalid. </exception>
        public MapFile(IFile mapFile, string language) : base(language)
        {
            if (mapFile == null)
            {
                throw new MapFileException("mapFile must not be null");
            }
            try
            {
                // open the file in read only mode
                try
                {
                    this.inputFile = mapFile.OpenAsync(FileAccess.Read).Result;

                    if (this.inputFile == null)
                    {
                        throw new MapFileException("cannot read file: " + mapFile);
                    }
                }
                catch
                {
                    throw new MapFileException("cannot read file: " + mapFile);
                }

                this.fileSize = this.inputFile.Length;

                this.readBuffer    = new ReadBuffer(this.inputFile);
                this.mapFileHeader = new MapFileHeader();
                this.mapFileHeader.ReadHeader(this.readBuffer, this.fileSize);
                this.databaseIndexCache = new IndexCache(this.inputFile, INDEX_CACHE_SIZE);

                // TODO: Find the creation date of file
                this.timestamp = DateTimeHelperClass.CurrentUnixTimeMillis();                  // mapFile.lastModified();
            }
            catch (Exception e)
            {
                LOGGER.Log(LogLevel.Fatal, e.Message, e);
                // make sure that the file is closed
                CloseFile();
                throw new MapFileException(e.Message);
            }
        }