/// <summary> /// Verifies that there is a sufficient number of bytes to read. /// </summary> /// <param name="count">Required number of bytes.</param> /// <param name="callback">Byte source callback.</param> /// <param name="state">Callback state.</param> /// <returns>true if source contains sufficient number of remaining bytes, false otherwise.</returns> public bool Require(uint count, ByteSourceCallback callback, object state) { lock (_lock) { return((_stream.Length - _stream.Position) >= count); } }
/// <summary> /// Verifies that there is a sufficient number of bytes to read. /// </summary> /// <param name="count">Required number of bytes.</param> /// <param name="callback">Byte source callback.</param> /// <param name="state">Callback state.</param> /// <returns>true if source contains sufficient number of remaining bytes, false otherwise.</returns> public bool Require(uint count, ByteSourceCallback callback, object state) { lock (_lock) { if ((_position + count) <= _length) { return(true); } if (_fixed) { throw new DicomIoException("Requested {0} bytes past end of byte source.", count); } if (callback == null) { throw new DicomIoException( "Requested {0} bytes past end of byte source without providing a callback.", count); } _required = count; _callback = callback; _callbackState = state; return(false); } }
/// <summary> /// Add byte buffer to byte source. /// </summary> /// <param name="buffer">Byte buffer to add.</param> /// <param name="last">true if added buffer is the last to add, false otherwise.</param> public void Add(IByteBuffer buffer, bool last) { lock (_lock) { if (_fixed) { throw new DicomIoException("Tried to extend fixed length byte source."); } if (buffer != null && buffer.Size > 0) { _buffers.Add(buffer); _length += buffer.Size; if (_callback != null) { if ((_length - _position) >= _required) { _callback.BeginInvoke(this, _callbackState, Callback, _callback); _callback = null; _callbackState = null; _required = 0; } } } _fixed = last; } }
private void Callback(IAsyncResult result) { try { ByteSourceCallback cb = (ByteSourceCallback)result.AsyncState; cb.EndInvoke(result); } catch { } }
public bool Require(uint count, ByteSourceCallback callback, object state) { lock (_lock) { if ((_stream.Length - _stream.Position) >= count) { return(true); } throw new DicomIoException("Requested {0} bytes past end of file.", count); } }
/// <summary> /// Add byte buffer to byte source. /// </summary> /// <param name="buffer">Byte buffer to add.</param> /// <param name="last">true if added buffer is the last to add, false otherwise.</param> public void Add(IByteBuffer buffer, bool last) { lock (_lock) { if (_fixed) throw new DicomIoException("Tried to extend fixed length byte source."); if (buffer != null && buffer.Size > 0) { _buffers.Add(buffer); _length += buffer.Size; if (_callback != null) { if ((_length - _position) >= _required) { _callback.BeginInvoke(this, _callbackState, Callback, _callback); _callback = null; _callbackState = null; _required = 0; } } } _fixed = last; } }
/// <summary> /// Verifies that there is a sufficient number of bytes to read. /// </summary> /// <param name="count">Required number of bytes.</param> /// <param name="callback">Byte source callback.</param> /// <param name="state">Callback state.</param> /// <returns>true if source contains sufficient number of remaining bytes, false otherwise.</returns> public bool Require(uint count, ByteSourceCallback callback, object state) { lock (_lock) { if ((_position + count) <= _length) return true; if (_fixed) throw new DicomIoException("Requested {0} bytes past end of byte source.", count); if (callback == null) throw new DicomIoException( "Requested {0} bytes past end of byte source without providing a callback.", count); _required = count; _callback = callback; _callbackState = state; return false; } }
/// <summary> /// Verifies that there is a sufficient number of bytes to read. /// </summary> /// <param name="count">Required number of bytes.</param> /// <param name="callback">Byte source callback.</param> /// <param name="state">Callback state.</param> /// <returns>true if source contains sufficient number of remaining bytes, false otherwise.</returns> public bool Require(uint count, ByteSourceCallback callback, object state) { lock (_lock) { return (_stream.Length - _stream.Position) >= count; } }
public bool Require(uint count, ByteSourceCallback callback, object state) { lock (_lock) { if ((_stream.Length - _stream.Position) >= count) return true; throw new DicomIoException("Requested {0} bytes past end of file.", count); } }
public bool Require(uint count, ByteSourceCallback callback, object state) => throw new NotImplementedException();