本文整理汇总了C#中IWriter.WriteObject方法的典型用法代码示例。如果您正苦于以下问题:C# IWriter.WriteObject方法的具体用法?C# IWriter.WriteObject怎么用?C# IWriter.WriteObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IWriter
的用法示例。
在下文中一共展示了IWriter.WriteObject方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Write
internal void Write(IWriter writer)
{
Signature = ZipConstants.ZipEntrySignature;
// 取得数据流位置
RelativeOffsetOfLocalHeader = (UInt32)writer.Stream.Position;
if (IsDirectory)
{
// 写入头部
writer.WriteObject(this);
return;
}
Int32 dsLen = (Int32)DataSource.Length;
//if (dsLen <= 0) CompressionMethod = CompressionMethod.Stored;
// 计算签名和大小
if (Crc == 0) Crc = DataSource.GetCRC();
if (UncompressedSize == 0) UncompressedSize = (UInt32)dsLen;
if (CompressionMethod == CompressionMethod.Stored) CompressedSize = UncompressedSize;
if (DataSource.IsCompressed) CompressedSize = (UInt32)dsLen;
// 写入头部
writer.WriteObject(this);
// 没有数据,直接跳过
if (dsLen <= 0) return;
#region 写入文件数据
#if DEBUG
var ts = writer.Stream as NewLife.Log.TraceStream;
if (ts != null) ts.UseConsole = false;
#endif
// 数据源。只能用一次,因为GetData的时候把数据流移到了合适位置
Stream source = DataSource.GetData();
switch (CompressionMethod)
{
case CompressionMethod.Stored:
// 原始数据流直接拷贝到目标。必须指定大小,否则可能读过界
source.CopyTo(writer.Stream, 0, dsLen);
break;
case CompressionMethod.Deflated:
if (DataSource.IsCompressed)
{
// 可能数据源是曾经被压缩过了的,比如刚解压的实体
source.CopyTo(writer.Stream, 0, dsLen);
}
else
{
// 记录数据流位置,待会用来计算已压缩大小
Int64 p = writer.Stream.Position;
using (var stream = new DeflateStream(writer.Stream, CompressionMode.Compress, true))
{
source.CopyTo(stream);
stream.Close();
}
CompressedSize = (UInt32)(writer.Stream.Position - p);
#if DEBUG
if (ts != null) ts.UseConsole = true;
#endif
// 回头重新修正压缩后大小CompressedSize
p = writer.Stream.Position;
// 计算好压缩大小字段所在位置
writer.Stream.Seek(RelativeOffsetOfLocalHeader + 18, SeekOrigin.Begin);
writer.Write(CompressedSize);
writer.Stream.Seek(p, SeekOrigin.Begin);
}
break;
default:
throw new XException("无法处理的压缩算法{0}!", CompressionMethod);
}
#if DEBUG
if (ts != null) ts.UseConsole = true;
#endif
#endregion
}
示例2: WriteDir
internal void WriteDir(IWriter writer)
{
Signature = ZipConstants.ZipDirEntrySignature;
// 写入头部
writer.WriteObject(this);
}
示例3: Write
/// <summary>实体=>外部,从实体对象读取信息并写入外部</summary>
/// <param name="entity">实体对象</param>
/// <param name="eop">实体操作。为空时由内部构建,但可在遍历调用访问器时由外部构造一次传入,以提高性能。</param>
public override void Write(IEntity entity, IEntityOperate eop = null)
{
writer = GetWriter();
writer.Stream = Stream;
writer.Settings.Encoding = Encoding;
try
{
if (AllFields)
writer.WriteObject(entity, null, null);
else
base.Write(entity, eop);
}
finally
{
writer.Flush();
//writer.Dispose();
writer = null;
}
}