本文整理汇总了C#中System.Stream.Write方法的典型用法代码示例。如果您正苦于以下问题:C# Stream.Write方法的具体用法?C# Stream.Write怎么用?C# Stream.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Stream
的用法示例。
在下文中一共展示了Stream.Write方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtractFile
/// <summary>
/// Copy the contents of a stored file into an opened stream
/// </summary>
/// <param name="_zfe">Entry information of file to extract</param>
/// <param name="_stream">Stream to store the uncompressed data</param>
/// <returns>True if success, false if not.</returns>
/// <remarks>Unique compression methods are Store and Deflate</remarks>
public bool ExtractFile(ZipFileEntry _zfe, Stream _stream)
{
if (!_stream.CanWrite)
throw new InvalidOperationException("Stream cannot be written");
// check signature
byte[] signature = new byte[4];
this.ZipFileStream.Seek(_zfe.HeaderOffset, SeekOrigin.Begin);
this.ZipFileStream.Read(signature, 0, 4);
if (BitConverter.ToUInt32(signature, 0) != 0x04034b50)
return false;
// Select input stream for inflating or just reading
Stream inStream;
if (_zfe.Method == Compression.Store)
inStream = this.ZipFileStream;
else if (_zfe.Method == Compression.Deflate)
inStream = new DeflateStream(this.ZipFileStream, CompressionMode.Decompress, true);
else
return false;
// Buffered copy
byte[] buffer = new byte[16384];
this.ZipFileStream.Seek(_zfe.FileOffset, SeekOrigin.Begin);
uint bytesPending = _zfe.FileSize;
while (bytesPending > 0)
{
int bytesRead = inStream.Read(buffer, 0, (int)Math.Min(bytesPending, buffer.Length));
_stream.Write(buffer, 0, bytesRead);
bytesPending -= (uint)bytesRead;
}
_stream.Flush();
if (_zfe.Method == Compression.Deflate)
inStream.Dispose();
return true;
}
示例2: GetRes
//.........这里部分代码省略.........
StringUtil.RemoveFromInList("metadata",
true,
ref strStyle);
bHasMetadataStyle = false;
}
lTotalLength = result.Value;
if (StringUtil.IsInList("timestamp", strStyle) == true
/*
&& lTotalLength > 0
* */ ) // 2012/1/11
{
if (input_timestamp != null)
{
if (ByteArray.Compare(input_timestamp, timestamp) != 0)
{
strError = "下载过程中发现时间戳和input_timestamp参数中的时间戳不一致,下载失败 ...";
return -1;
}
}
if (old_timestamp != null)
{
if (ByteArray.Compare(old_timestamp, timestamp) != 0)
{
strError = "下载过程中发现时间戳变化,下载失败 ...";
return -1;
}
}
}
old_timestamp = timestamp;
if (fileTarget == null)
break;
// 写入文件
if (StringUtil.IsInList("attachment", strStyle) == true)
{
Debug.Assert(false, "attachment style暂时不能使用");
/*
Attachment attachment = ws.ResponseSoapContext.Attachments[id];
if (attachment == null)
{
strError = "id为 '" +id+ "' 的attachment在WebService响应中没有找到...";
return -1;
}
StreamUtil.DumpStream(attachment.Stream, fileTarget);
nStart += (int)attachment.Stream.Length;
Debug.Assert(attachment.Stream.Length <= result.Value, "每次返回的包尺寸["+Convert.ToString(attachment.Stream.Length)+"]应当小于result.Value["+Convert.ToString(result.Value)+"]");
*/
}
else
{
Debug.Assert(StringUtil.IsInList("content", strStyle) == true,
"不是attachment风格,就应是content风格");
Debug.Assert(baContent != null, "返回的baContent不能为null");
Debug.Assert(baContent.Length <= result.Value, "每次返回的包尺寸[" + Convert.ToString(baContent.Length) + "]应当小于result.Value[" + Convert.ToString(result.Value) + "]");
fileTarget.Write(baContent, 0, baContent.Length);
if (flushOutputMethod != null)
{
if (flushOutputMethod() == false)
{
strError = "FlushOutputMethod()用户中断";
return -1;
}
}
lStart += baContent.Length;
}
if (lStart >= result.Value)
break; // 结束
} // end try
catch (Exception ex)
{
/*
strError = ConvertWebError(ex);
return -1;
* */
int nRet = ConvertWebError(ex, out strError);
if (nRet == 0)
return -1;
goto REDO;
}
} // end of for
baOutputTimeStamp = timestamp;
this.ClearRedoCount();
return 0;
}
示例3: WriteString
public static void WriteString(Stream s, string v)
{
MemoryStream baos = new MemoryStream();
for (int index = 0; index < v.Length; index++)
{
#if CODE_ANALYSIS
char c = v.CharAt(index);
#else
char c = v[index];
#endif
if ((c > 0) && (c < 80))
baos.WriteByte((byte)c);
else if (c < '\u0800')
{
baos.WriteByte((byte)(0xc0 | (0x1f & (c >> 6))));
baos.WriteByte((byte)(0x80 | (0x3f & c)));
}
else
{
baos.WriteByte((byte)(0xe0 | (0x0f & (c >> 12))));
baos.WriteByte((byte)(0x80 | (0x3f & (c >> 6))));
baos.WriteByte((byte)(0x80 | (0x3f & c)));
}
}
WriteUInt16(s, (ushort)baos.Length);
s.Write(baos.GetBuffer(), 0, (int)baos.Length);
}
示例4: WriteTo
/// <summary>
/// Convenience method which writes the contents of the ZipEntry
/// to the specified stream and returns the number of bytes written.
/// </summary>
/// <param name="stream">The stream.</param>
/// <returns></returns>
public int WriteTo(Stream stream)
{
byte[] buffer = new byte[GlobalConstants.DefaultStreamBlockSize];
int bytesRead, totalBytesRead = 0;
while ((bytesRead = Read(buffer, 0, GlobalConstants.DefaultStreamBlockSize)) > -1)
{
stream.Write(buffer, 0, bytesRead);
totalBytesRead += bytesRead;
}
return totalBytesRead;
}