public override void Flush() { if (UnderlyingIO == null) { throw new InvalidOperationException( @"UnderlyingI stream missing. Tilepart headers should be written after codestream headers"); } if (!IsOpened) { throw new InvalidOperationException(String.Concat( "Trying to flush to IO stream ", "a closed tile-part")); } if (_offset == OFFSET_NOT_SET) { _offset = (Parent as JP2Codestream).AssignOffset(this); } // SOT marker includes the full tile-part length we should write the // SOT marker after all the packets have been added, and we know in // advance what is the full tile-part length (markers and packets). UnderlyingIO.Seek(Position, SeekOrigin.Begin); _sot.WriteMarkerSegment(UnderlyingIO); foreach (var plt in _pltMarkers) { plt.WriteMarkerSegment(UnderlyingIO); } MarkerSegment.WriteMarker(MarkerType.SOD, UnderlyingIO); // can be safely closed and reopened from the underlying stream. IsFlushed = true; }
public override void Flush() { if (_offset == OFFSET_NOT_SET) { throw new InvalidOperationException( "Should bind CodestreamNode to a stream"); } // Writes the main headers of this codestream The headers include // SOC and every other marker in the Markers collection except TLM. // TLM is written when the codestream is sealed, after all of the // tileparts are generated. To write the TLM and EOC marker invoke // WriteFinalizers(). UnderlyingIO.Seek(Position, SeekOrigin.Begin); int offset = 0; offset += MarkerSegment.WriteMarker(MarkerType.SOC, UnderlyingIO); offset += Markers[MarkerType.SIZ].WriteMarkerSegment(UnderlyingIO); offset += Markers[MarkerType.COD].WriteMarkerSegment(UnderlyingIO); offset += Markers[MarkerType.QCD].WriteMarkerSegment(UnderlyingIO); var optionalMarkers = Markers.Keys.Except(MandatoryMarkers); foreach (var opt in optionalMarkers) { offset += Markers[opt].WriteMarkerSegment(UnderlyingIO); } foreach (var tlm in _tlmMarkers) { offset += tlm.WriteMarkerSegment(UnderlyingIO); } // flush only the ones that were not flushed incrementally // by user code. foreach (var tp in _tileparts.Where(tp => !tp.IsFlushed)) { tp.Flush(); } long tpLength = _tileparts.Sum(tp => tp.Length); // account for all headers, all tile-parts and EOC marker Length = FirstChildOffset + tpLength + MarkerSegment.MarkerLength; long eocOffset = Position + FirstChildOffset + tpLength; UnderlyingIO.Seek(eocOffset, SeekOrigin.Begin); MarkerSegment.WriteMarker(MarkerType.EOC, UnderlyingIO); // can be safely closed an re-opened from the underlying stream IsFlushed = true; }