public int Read(sbyte[] toRead, int offset, int length) { // Read int currentByte = 0; bool canReadStream = true; while (currentByte < length && canReadStream) { if (NumForwardBytesInBuffer > 0) { // from mem NumForwardBytesInBuffer--; toRead[offset + currentByte] = (sbyte)COB[NumForwardBytesInBuffer]; currentByte++; } else { // from stream int newBytes = length - currentByte; int numRead = S.Read(Temp, 0, newBytes); canReadStream = numRead >= newBytes; for (int i = 0; i < numRead; i++) { COB.Push(Temp[i]); toRead[offset + currentByte + i] = (sbyte)Temp[i]; } currentByte += numRead; } } return(currentByte); }
public int Read(sbyte[] toRead, int offset, int length) { // Read ////System.Diagnostics.Trace.WriteLine("BackStream - Read "); int currentByte = 0; bool canReadStream = true; while (currentByte < length && canReadStream) { ////System.Diagnostics.Trace.WriteLine("BackStream - Read - looping"); if (NumForwardBytesInBuffer > 0) { // from mem ////System.Diagnostics.Trace.WriteLine("BackStream - Read - there are bytes in the buffer"); NumForwardBytesInBuffer--; toRead[offset + currentByte] = (sbyte)COB[NumForwardBytesInBuffer]; currentByte++; } else { // from stream ////System.Diagnostics.Trace.WriteLine("BackStream - Read - reading for numRead"); int newBytes = 0; int numRead = 0; try { ////System.Diagnostics.Trace.WriteLine("BackStream - Read - reading for numRead - set newBytes"); newBytes = length - currentByte; ////System.Diagnostics.Trace.WriteLine("newBytes=" + newBytes.ToString()); ////System.Diagnostics.Trace.WriteLine("BackStream - Read - reading for numRead - set numRead"); numRead = 0; ////System.Diagnostics.Trace.WriteLine("BackStream - Read - reading for numRead - testing Stream"); if (S.CanRead) { ////System.Diagnostics.Trace.WriteLine("BackStream - Read - reading for numRead - reading from stream"); ////System.Diagnostics.Trace.WriteLine("Temp length=" + Temp.Length.ToString()); ////System.Diagnostics.Trace.WriteLine("newBytes length:" + newBytes.ToString()); numRead = S.Read(Temp, 0, newBytes); } if (numRead == 0) { numRead = 0; } //System.Diagnostics.Trace.WriteLine("BackStream - Read - reading for numRead - have read " + numRead.ToString() + " bytes from stream"); } catch (Exception e2) { string s = e2.Message; } canReadStream = numRead >= newBytes; ////System.Diagnostics.Trace.WriteLine("BackStream - Read - there aren't bytes in the buffer "); for (int i = 0; i < numRead; i++) { //System.Diagnostics.Trace.WriteLine(Temp[i].ToString()); COB.Push(Temp[i]); toRead[offset + currentByte + i] = (sbyte)Temp[i]; } currentByte += numRead; } } ////System.Diagnostics.Trace.WriteLine("BackStream - Read - End"); return(currentByte); }