本文整理汇总了C#中ChunkedMemoryStream类的典型用法代码示例。如果您正苦于以下问题:C# ChunkedMemoryStream类的具体用法?C# ChunkedMemoryStream怎么用?C# ChunkedMemoryStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ChunkedMemoryStream类属于命名空间,在下文中一共展示了ChunkedMemoryStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendRequest
internal void SendRequest(IMessage msg, ITransportHeaders headers, Stream contentStream)
{
IMethodCallMessage message = (IMethodCallMessage) msg;
int length = (int) contentStream.Length;
string uri = message.Uri;
this._bOneWayRequest = RemotingServices.IsOneWay(message.MethodBase);
ChunkedMemoryStream outputStream = new ChunkedMemoryStream(CoreChannel.BufferPool);
base.WritePreambleAndVersion(outputStream);
if (!this._bOneWayRequest)
{
base.WriteUInt16(0, outputStream);
}
else
{
base.WriteUInt16(1, outputStream);
}
base.WriteUInt16(0, outputStream);
base.WriteInt32(length, outputStream);
base.WriteUInt16(4, outputStream);
base.WriteByte(1, outputStream);
base.WriteCountedString(uri, outputStream);
base.WriteHeaders(headers, outputStream);
outputStream.WriteTo(base.NetStream);
outputStream.Close();
StreamHelper.CopyStream(contentStream, base.NetStream);
contentStream.Close();
}
示例2: Write_100_bytes
public void Write_100_bytes()
{
byte[] bytes = GetBytes(100);
var stream = new ChunkedMemoryStream();
stream.Write(bytes, 0, bytes.Length);
Assert.AreEqual(100, stream.Length);
}
示例3: TestCreateTextDataFromStream
public void TestCreateTextDataFromStream()
{
var stream = new ChunkedMemoryStream();
var str = Encoding.ASCII.GetBytes("string");
stream.Write(str, 0, str.Length);
stream.Position = 0L;
var text = ImapData.CreateTextData(stream);
Assert.AreEqual(ImapDataFormat.Text, text.Format);
Assert.AreEqual(6, text.GetTextLength());
Assert.AreEqual(Encoding.ASCII.GetBytes("string"), text.GetTextAsByteArray());
Assert.AreEqual(new ByteString(str), text.GetTextAsByteString());
Assert.AreEqual("string", text.GetTextAsString());
Assert.AreSame(stream, text.GetTextAsStream());
FileAssert.AreEqual(new MemoryStream(str, false), text.GetTextAsStream());
var buffer = new byte[3];
text.CopyText(buffer, 0, buffer.Length);
Assert.AreEqual(str.Slice(0, 3), buffer);
}
示例4: ImapAppendMessageBodyStream
protected internal ImapAppendMessageBodyStream(int readTimeout, int writeTimeout)
{
this.ReadTimeout = readTimeout;
this.WriteTimeout = writeTimeout;
buffer = new ChunkedMemoryStream();
}
示例5: GetRequestStream
public Stream GetRequestStream(IMessage msg, int contentLength, ITransportHeaders headers)
{
IMethodCallMessage message = (IMethodCallMessage) msg;
string uri = message.Uri;
this._bOneWayRequest = RemotingServices.IsOneWay(message.MethodBase);
ChunkedMemoryStream outputStream = new ChunkedMemoryStream(CoreChannel.BufferPool);
base.WritePreambleAndVersion(outputStream);
if (!this._bOneWayRequest)
{
base.WriteUInt16(0, outputStream);
}
else
{
base.WriteUInt16(1, outputStream);
}
base.WriteUInt16(0, outputStream);
base.WriteInt32(contentLength, outputStream);
base.WriteUInt16(4, outputStream);
base.WriteByte(1, outputStream);
base.WriteCountedString(uri, outputStream);
base.WriteHeaders(headers, outputStream);
outputStream.WriteTo(base.NetStream);
outputStream.Close();
this._requestStream = base.NetStream;
return this._requestStream;
}
示例6: Static
/// <summary>
/// Create reusable stream.
/// Disposing the stream only has the effect of resetting it.
/// </summary>
/// <returns></returns>
public static ChunkedMemoryStream Static()
{
var cms = new ChunkedMemoryStream(new byte[BlockSize]);
cms.GetReader();
cms.GetWriter();
cms.UseBufferedReader(string.Empty);
return cms;
}
示例7: Read_from_an_initialized_buffer
public void Read_from_an_initialized_buffer()
{
var originalBytes = GetBytes(100);
var stream = new ChunkedMemoryStream(originalBytes);
var readBytes = new byte[100];
stream.Read(readBytes, 0, readBytes.Length);
Assert.AreEqual(originalBytes, readBytes);
}
示例8: Write_100_bytes_100_times
public void Write_100_bytes_100_times()
{
byte[] bytes = GetBytes(100);
var stream = new ChunkedMemoryStream();
for(int i = 0; i < 100; ++i) {
stream.Write(bytes, 0, bytes.Length);
}
}
示例9: Serialize
public static void Serialize(this IJsonObject instance, ChunkedMemoryStream stream)
{
stream.Reset();
var sw = stream.GetWriter();
instance.Serialize(sw, false, null);
sw.Flush();
stream.Position = 0;
}
示例10: ResourceContentBE
public ResourceContentBE(XDoc doc)
: this(true) {
if(doc == null) {
throw new ArgumentNullException("doc");
}
_stream = new ChunkedMemoryStream();
doc.WriteTo(_stream);
_mimeType = MimeType.TEXT_XML;
_size = (uint)_stream.Length;
}
示例11: Context
public Context(IServiceProvider service)
{
Stream = ChunkedMemoryStream.Static();
Writer = Stream.GetWriter();
var dqm = service.Resolve<IDatabaseQueryManager>();
var factory = service.Resolve<IObjectFactory>().CreateInnerFactory();
factory.RegisterInterfaces(dqm.StartQuery(false));
Repository = factory.Resolve<IPersistableRepository<World>>();
BulkReader = factory.BulkRead(ChunkedMemoryStream.Static());
}
示例12: Write_100_bytes_100_times_Read_10000_bytes
public void Write_100_bytes_100_times_Read_10000_bytes()
{
byte[] bytes = GetBytes(100);
byte[][] arrays = new byte[100][];
var stream = new ChunkedMemoryStream();
for(int i = 0; i < 100; ++i) {
stream.Write(bytes, 0, bytes.Length);
arrays[i] = bytes;
}
stream.Position = 0;
byte[] buffer = new byte[100 * bytes.Length];
int read = stream.Read(buffer, 0, buffer.Length);
Assert.AreEqual(buffer.Length, read);
Assert.AreEqual(ArrayUtil.Concat(arrays), buffer);
Assert.AreEqual(0, stream.Read(buffer, 0, buffer.Length));
}
示例13: Write_64k_bytes_Read_64k_bytes
public void Write_64k_bytes_Read_64k_bytes()
{
byte[] bytes = GetBytes(64 * 1024);
var stream = new ChunkedMemoryStream();
stream.Write(bytes, 0, bytes.Length);
stream.Position = 0;
byte[] buffer = new byte[bytes.Length];
int read = stream.Read(buffer, 0, buffer.Length);
Assert.AreEqual(buffer.Length, read);
Assert.AreEqual(bytes, buffer);
Assert.AreEqual(0, stream.Read(buffer, 0, buffer.Length));
}
示例14: GetPreparedCommandStream
private Stream GetPreparedCommandStream()
{
NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "GetPreparedCommandText");
if (parameters.Count == 0)
return new MemoryStream(Encoding.UTF8.GetBytes("execute " + planName));
var cms = new ChunkedMemoryStream();
var sw = new StreamWriter(cms);
sw.Write("execute " + planName);
sw.Write('(');
for (int i = 0; i < parameters.Count; i++)
{
var p = parameters[i];
// Add parentheses wrapping parameter value before the type cast to avoid problems with Int16.MinValue, Int32.MinValue and Int64.MinValue
// See bug #1010543
sw.Write('(');
//TODO fix LOH issue
sw.Write(p.TypeInfo.ConvertToBackend(p.Value, false));
sw.Write('(');
if (p.UseCast)
{
sw.Write("::");
sw.Write(p.TypeInfo.CastName);
if (p.TypeInfo.UseSize && (p.Size > 0))
{
sw.Write('(');
sw.Write(p.Size);
sw.Write(')');
}
}
if (i < parameters.Count - 1)
sw.Write(',');
}
sw.Write(')');
sw.Flush();
return cms;
}
示例15: SerializeMessage
} // AsyncProcessMessage
// helper function to serialize the message
private void SerializeMessage(IMessage msg,
out ITransportHeaders headers, out Stream stream)
{
BaseTransportHeaders requestHeaders = new BaseTransportHeaders();
headers = requestHeaders;
// add other http soap headers
requestHeaders.ContentType = CoreChannel.BinaryMimeType;
if (_channelProtocol == SinkChannelProtocol.Http)
headers["__RequestVerb"] = "POST";
bool bMemStream = false;
stream = _nextSink.GetRequestStream(msg, headers);
if (stream == null)
{
stream = new ChunkedMemoryStream(CoreChannel.BufferPool);
bMemStream = true;
}
CoreChannel.SerializeBinaryMessage(msg, stream, _includeVersioning);
if (bMemStream)
stream.Position = 0;
} // SerializeMessage