bool IResourceHandler.Read(Stream dataOut, out int bytesRead, IResourceReadCallback callback) { bytesRead = 0; //We don't need the callback, as it's an unmanaged resource we should dispose it (could wrap it in a using statement). callback.Dispose(); if (Stream == null) { return(false); } //Data out represents an underlying unmanaged buffer (typically 64kb in size). //We reuse a temp buffer where possible if (tempBuffer == null || tempBuffer.Length < dataOut.Length) { tempBuffer = new byte[dataOut.Length]; } bytesRead = Stream.Read(tempBuffer, 0, tempBuffer.Length); // To indicate response completion set bytesRead to 0 and return false if (bytesRead == 0) { return(false); } //We need to use bytesRead instead of tempbuffer.Length otherwise //garbage from the previous copy would be written to dataOut dataOut.Write(tempBuffer, 0, bytesRead); return(bytesRead > 0); }
bool IResourceHandler.Read(Stream dataOut, out int bytesRead, IResourceReadCallback callback) { bytesRead = 0; //We don't need the callback, as it's an unmanaged resource we should dispose it (could wrap it in a using statement). callback.Dispose(); if (Stream == null) { return(false); } //Data out represents an underlying buffer (typically 32kb in size). var buffer = new byte[dataOut.Length]; bytesRead = Stream.Read(buffer, 0, buffer.Length); // To indicate response completion set bytesRead to 0 and return false if (bytesRead == 0) { return(false); } dataOut.Write(buffer, 0, buffer.Length); return(bytesRead > 0); }
bool IResourceHandler.Read(Stream dataOut, out int bytesRead, IResourceReadCallback callback) { //Legacy behaviour bytesRead = -1; return(false); }
// // Summary: // Read response data. If data is available immediately copy up to dataOut.Length // bytes into dataOut, set bytesRead to the number of bytes copied, and return true. // To read the data at a later time keep a pointer to dataOut, set bytesRead to // 0, return true and execute callback when the data is available (dataOut will // remain valid until the callback is executed). To indicate response completion // set bytesRead to 0 and return false. To indicate failure set bytesRead to < 0 // (e.g. -2 for ERR_FAILED) and return false. This method will be called in sequence // but not from a dedicated thread. For backwards compatibility set bytesRead to // -1 and return false and the ReadResponse method will be called. // // Parameters: // dataOut: // If data is available immediately copy up to System.IO.Stream.Length bytes into // dataOut. // // bytesRead: // To indicate response completion set bytesRead to 0 and return false. // // callback: // set bytesRead to 0, return true and execute callback when the data is available // (dataOut will remain valid until the callback is executed). If you have no need // of the callback then Dispose of it immeduately. // // Returns: // return true or false depending on the criteria, see summary. public bool Read(Stream dataOut, out int bytesRead, IResourceReadCallback callback) { // For backwards compatibility set bytesRead to // -1 and return false and the ReadResponse method will be called. bytesRead = -1; return(false); }
bool IResourceHandler.Read(Stream dataOut, out int bytesRead, IResourceReadCallback callback) { bytesRead = 0; callback.Dispose(); if (_stream == null) { return(false); } if (_buffer == null || _buffer.Length < dataOut.Length) { _buffer = new byte[dataOut.Length]; } bytesRead = _stream.Read(_buffer, 0, _buffer.Length); if (bytesRead == 0) { return(false); } dataOut.Write(_buffer, 0, bytesRead); return(bytesRead > 0); }
public bool Read(Stream dataOut, out int bytesRead, IResourceReadCallback callback) { if (this.fileStream.Position < this.fileStream.Length) { Debug.Assert(fileStream.Length <= int.MaxValue, "File stream length has to be smaller or equal to int max value"); fileStream.CopyTo(dataOut); bytesRead = (int)fileStream.Length; return(true); } bytesRead = 0; return(false); }
bool IResourceHandler.Read(Stream dataOut, out int bytesRead, IResourceReadCallback callback) { if (!callback.IsDisposed) { callback.Dispose(); } if (_data == null) { bytesRead = 0; return(false); } bytesRead = _data.CopyTo(dataOut, (int)dataOut.Length, 8192); return(bytesRead > 0); }
public bool Read(Stream dataOut, out int bytesRead, IResourceReadCallback callback) { int leftToRead = this._localResourceData.Length - this._dataReadCount; if (leftToRead == 0) { bytesRead = 0; return(false); } int needRead = Math.Min((int)dataOut.Length, leftToRead); dataOut.Write(this._localResourceData, this._dataReadCount, needRead); this._dataReadCount += needRead; bytesRead = needRead; return(true); }
bool IResourceHandler.Read(Stream dataOut, out int bytesRead, IResourceReadCallback callback) { callback?.Dispose(); // TODO unnecessary null check once ReadResponse is removed try{ byte[] buffer = new byte[Math.Min(dataIn.Length - dataIn.Position, dataOut.Length)]; int length = buffer.Length; dataIn.Read(buffer, 0, length); dataOut.Write(buffer, 0, length); bytesRead = length; }catch { // catch IOException, possibly NullReferenceException if dataIn is null bytesRead = 0; } return(bytesRead > 0); }
bool IResourceHandler.Read(Stream dataOut, out int bytesRead, IResourceReadCallback callback) { if (!callback.IsDisposed) { callback.Dispose(); } if (_response == null) { bytesRead = 0; return(false); } using (var s = new MemoryStream(_response)) { bytesRead = s.CopyTo(dataOut, (int)dataOut.Length, 8192); return(bytesRead > 0); } }
bool IResourceHandler.Read(Stream dataOut, out int bytesRead, IResourceReadCallback callback) { //Should never be called throw new NotImplementedException("This method should never be called"); }
bool IResourceHandler.Read(Stream dataOut, out int bytesRead, IResourceReadCallback callback) { return(ResourceHandler.Read(dataOut, out bytesRead, callback)); }
public bool Read(Stream dataOut, out int bytesRead, IResourceReadCallback callback) { bytesRead = 0; return(true); }
public bool Read(Stream dataOut, out int bytesRead, IResourceReadCallback callback) { throw new NotImplementedException(); }
bool IResourceHandler.Read(Stream dataOut, out int bytesRead, IResourceReadCallback callback) { return(logic.Read(WriteToOut, dataOut, dataOut.Length, out bytesRead, callback)); }