public static SqlBytes ReadSqlBytes(this Stream stream, Int64 count) { if (stream == null) { throw new ArgumentNullException("stream"); } if (count < 0) { throw new ArgumentOutOfRangeException("count"); } var bytes = new SqlBytes(new byte[count]); var buffer = new byte[Comparable.Min(SqlRuntime.IoBufferSize, count)]; long index = 0L; bytes.SetLength(0); while (count > 0) { int read = stream.Read(buffer, 0, (int)Comparable.Min(buffer.Length, count)); if (read == 0) { break; } bytes.SetLength(index + read); bytes.Write(index, buffer, 0, read); index += read; count -= read; } return(bytes); }
public void SqlBytesSetLength() { byte [] b1 = new byte [10]; SqlBytes bytes = new SqlBytes(); try { bytes.SetLength(20); Assert.Fail("Should throw SqlTypeException"); } catch (Exception ex) { Assert.AreEqual(typeof(SqlTypeException), ex.GetType(), "Should throw SqlTypeException"); } bytes = new SqlBytes(b1); Assert.AreEqual(bytes.Length, 10, "#1 Should be same"); try { bytes.SetLength(-1); Assert.Fail("Should throw ArgumentOutOfRangeException"); } catch (Exception ex) { Assert.AreEqual(typeof(ArgumentOutOfRangeException), ex.GetType(), "Should throw ArgumentOutOfRangeException"); } try { bytes.SetLength(11); Assert.Fail("Should throw ArgumentOutOfRangeException"); } catch (Exception ex) { Assert.AreEqual(typeof(ArgumentOutOfRangeException), ex.GetType(), "Should throw ArgumentOutOfRangeException"); } bytes.SetLength(2); Assert.AreEqual(bytes.Length, 2, "#2 Should be same"); }
public void SqlBytesSetLength() { byte[] b1 = new byte[10]; SqlBytes bytes = new SqlBytes(); Assert.Throws <SqlTypeException>(() => bytes.SetLength(20)); bytes = new SqlBytes(b1); Assert.Equal(10, bytes.Length); Assert.Throws <ArgumentOutOfRangeException>(() => bytes.SetLength(-1)); Assert.Throws <ArgumentOutOfRangeException>(() => bytes.SetLength(11)); bytes.SetLength(2); Assert.Equal(2, bytes.Length); }
public void FillBytes(SqlBytes value) { if (fIsNull) { if (value.IsNull) { return; } else { value.SetNull(); return; } } byte[] bigbytes = new byte[9]; byte[] bytes = BitConverter.GetBytes(x); bytes.CopyTo(bigbytes, 0); bytes = BitConverter.GetBytes(y); bytes.CopyTo(bigbytes, 4); int i; for (i = 0; i < bigbytes.Length; i++) { value[i] = bigbytes[i]; } value.SetLength(i); return; }
public void FillBytes(SqlBytes data) { if (fIsNull) { if (data.IsNull) { return; } else { data.SetNull(); return; } } byte[] bigbytes = new byte[16]; byte[] bytes = BitConverter.GetBytes(start.X); bytes.CopyTo(bigbytes, 0); bytes = BitConverter.GetBytes(start.Y); bytes.CopyTo(bigbytes, 4); bytes = BitConverter.GetBytes(end.X); bytes.CopyTo(bigbytes, 8); bytes = BitConverter.GetBytes(end.Y); bytes.CopyTo(bigbytes, 12); int i; for (i = 0; i < bigbytes.Length; i++) { data[i] = bigbytes[i]; } data.SetLength(i); }
public override void SetLength(long value) { CheckIfStreamClosed(); _sb.SetLength(value); if (_lPosition > value) { _lPosition = value; } }
public void SqlBytesSetLength() { byte[] b1 = new byte[10]; SqlBytes bytes = new SqlBytes(); try { bytes.SetLength(20); Assert.False(true); } catch (Exception ex) { Assert.Equal(typeof(SqlTypeException), ex.GetType()); } bytes = new SqlBytes(b1); Assert.Equal(bytes.Length, 10); try { bytes.SetLength(-1); Assert.False(true); } catch (Exception ex) { Assert.Equal(typeof(ArgumentOutOfRangeException), ex.GetType()); } try { bytes.SetLength(11); Assert.False(true); } catch (Exception ex) { Assert.Equal(typeof(ArgumentOutOfRangeException), ex.GetType()); } bytes.SetLength(2); Assert.Equal(bytes.Length, 2); }
public void FillBytes(SqlBytes value) { if (IsNull) { if (value.IsNull) { return; } else { value.SetNull(); return; } } SqlString str; if ((object)m_secondline == null || m_secondline.IsNull) { str = m_firstline; } else { str = string.Concat(m_firstline, "|"); str = string.Concat(str, m_secondline); } byte[] stringData = str.GetUnicodeBytes(); int i; for (i = 0; i < stringData.Length; i++) { value[i] = stringData[i]; } value.SetLength(i); return; }