/// <summary> /// Initializes a new instance of the PbfReader class that read data form specified file. /// </summary> /// <param name="path">The path to the input file.</param> /// <param name="settings">The OsmReaderSettings object that determines behaviour of PbfReader.</param> public PbfReader(string path, OsmReaderSettings settings) { _input = new FileStream(path, FileMode.Open, FileAccess.Read); _cache = new Queue <IEntityInfo>(); this.Settings = settings; this.Settings.IsReadOnly = true; BlobHeader blobHeader = null; while ((blobHeader = this.ReadBlobHeader()) != null) { try { if (blobHeader.Type == "OSMHeader") { OsmHeader osmHeader = (OsmHeader)this.ReadBlob(blobHeader); this.ProcessOsmHeader(osmHeader); return; } else if (blobHeader.Type == "OSMData") { throw new InvalidDataException("Input stream doesn't contain an 'OSMHeader' block before 'OSMData' block."); } else { _input.Seek(blobHeader.DataSize, SeekOrigin.Current); } } catch (ProtoException ex) { throw new InvalidDataException("Input stream contains unsupported data", ex); } } throw new InvalidDataException("Input stream doesn't contain an 'OSMHeader' block."); }
/// <summary> /// Initializes a new instance of the PbfReader class that read data form specified file. /// </summary> /// <param name="path">The path to the input file.</param> /// <param name="settings">The OsmReaderSettings object that determines behaviour of PbfReader.</param> public PbfReader(string path, OsmReaderSettings settings) { _input = new FileStream(path, FileMode.Open, FileAccess.Read); _cache = new Queue<IEntityInfo>(); this.Settings = settings; this.Settings.IsReadOnly = true; BlobHeader blobHeader = null; while ((blobHeader = this.ReadBlobHeader()) != null) { if (blobHeader.Type == "OSMHeader") { OsmHeader osmHeader = (OsmHeader)this.ReadBlob(blobHeader); this.ProcessOsmHeader(osmHeader); return; } else if (blobHeader.Type == "OSMData") { throw new InvalidDataException("Input stream doesn't contain an 'OSMHeader' block before 'OSMData' block."); } else { _input.Seek(blobHeader.DataSize, SeekOrigin.Current); } } throw new InvalidDataException("Input stream doesn't contain an 'OSMHeader' block."); }
/// <summary> /// Initializes a new instance of the PbfReader class that read data form specified stream. /// </summary> /// <param name="input">The input stream.</param> /// <param name="settings">The OsmReaderSettings object that determines behaviour of PbfReader.</param> public PbfReader(Stream input, OsmReaderSettings settings) { _input = input; _cache = new Queue <IEntityInfo>(); this.Settings = settings; this.Settings.IsReadOnly = true; BlobHeader blobHeader = null; while ((blobHeader = this.ReadBlobHeader()) != null) { if (blobHeader.Type == "OSMHeader") { OsmHeader osmHeader = (OsmHeader)this.ReadBlob(blobHeader); this.ProcessOsmHeader(osmHeader); return; } else if (blobHeader.Type == "OSMData") { throw new InvalidDataException("Input stream doesn't contain an 'OSMHeader' block before 'OSMData' block."); } else { _input.Seek(blobHeader.DataSize, SeekOrigin.Current); } } throw new InvalidDataException("Input stream doesn't contain an 'OSMHeader' block."); }
public void ReadMetadataSetter_ThrowInvaldOperationExceptionIfSettingsIsReadOnly() { OsmReaderSettings target = new OsmReaderSettings(); target.IsReadOnly = true; Assert.Throws<InvalidOperationException>(() => target.ReadMetadata = true); }
public void Constructor_StreamSettings_SetsSettingsAndMakesThemIsReadOnly() { MemoryStream dataStream = new MemoryStream(PbfTestData.pbf_n_node); OsmReaderSettings settings = new OsmReaderSettings(); using (PbfReader target = new PbfReader(dataStream, settings)) { Assert.Same(settings, target.Settings); Assert.True(settings.IsReadOnly); } }
public void Constructor__CreatesSettingsWithDefaultValues() { OsmReaderSettings target = new OsmReaderSettings(); Assert.Equal(true, target.ReadMetadata); }
public void Constructor_StringSettings_SetsSettingsAndMakesThemIsReadOnly() { string filename = "..\\..\\src\\Tests.SpatialLite.Osm\\Data\\Pbf\\pbf-n-node.pbf"; OsmReaderSettings settings = new OsmReaderSettings(); using (PbfReader target = new PbfReader(filename, settings)) { Assert.Same(settings, target.Settings); Assert.True(settings.IsReadOnly); } }
public void Dispose_ClosesOutputStreamIfWritingToStream() { MemoryStream stream = new MemoryStream(PbfTestData.pbf_n_node); OsmReaderSettings settings = new OsmReaderSettings() {ReadMetadata = true}; PbfReader target = new PbfReader(stream, settings); target.Dispose(); Assert.False(stream.CanRead); }
public void Dispose_ClosesOutputStreamIfWritingToFiles() { string filename = "..\\..\\src\\Tests.SpatialLite.Osm\\Data\\Pbf\\pbf-n-node.pbf"; OsmReaderSettings settings = new OsmReaderSettings() {ReadMetadata = true}; PbfReader target = new PbfReader(filename, settings); target.Dispose(); FileStream testStream = null; Assert.DoesNotThrow(() => testStream = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite)); testStream.Dispose(); }