本文整理汇总了C#中System.IO.BufferedStream.WriteNoAlloc方法的典型用法代码示例。如果您正苦于以下问题:C# BufferedStream.WriteNoAlloc方法的具体用法?C# BufferedStream.WriteNoAlloc怎么用?C# BufferedStream.WriteNoAlloc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BufferedStream
的用法示例。
在下文中一共展示了BufferedStream.WriteNoAlloc方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateFileFormat
private static void UpdateFileFormat(string originalVoxFile)
{
var newFile = Path.ChangeExtension(originalVoxFile, MyVoxelConstants.FILE_EXTENSION);
if (!File.Exists(originalVoxFile))
{
MySandboxGame.Log.WriteLine(string.Format("ERROR: Voxel file '{0}' does not exists!", originalVoxFile));
}
if (Path.GetExtension(originalVoxFile) != "vox")
{
MySandboxGame.Log.WriteLine(string.Format("ERROR: Unexpected voxel file extensions in path: '{0}'", originalVoxFile));
}
using (var decompressFile = new MyCompressionFileLoad(originalVoxFile))
using (var file = MyFileSystem.OpenWrite(newFile))
using (var gzip = new GZipStream(file, CompressionMode.Compress))
using (var buffer = new BufferedStream(gzip))
{
buffer.WriteNoAlloc(STORAGE_TYPE_NAME_CELL);
// File version. New format will store it in 7bit encoded int right after the name of storage.
buffer.Write7BitEncodedInt(decompressFile.GetInt32());
// All remaining data is unchanged. Just copy it to new file.
byte[] tmp = new byte[0x4000];
int bytesRead = decompressFile.GetBytes(tmp.Length, tmp);
while (bytesRead != 0)
{
buffer.Write(tmp, 0, bytesRead);
bytesRead = decompressFile.GetBytes(tmp.Length, tmp);
}
}
}
示例2: Save
public void Save(out byte[] outCompressedData)
{
MyPrecalcComponent.AssertUpdateThread();
ProfilerShort.Begin("MyStorageBase.Save");
try
{
if (m_compressedData == null)
{
MemoryStream ms;
using (ms = new MemoryStream(0x4000))
using (GZipStream gz = new GZipStream(ms, CompressionMode.Compress))
using (BufferedStream buf = new BufferedStream(gz, 0x4000))
{
string name;
int version;
if (GetType() == typeof(MyOctreeStorage))
{
name = STORAGE_TYPE_NAME_OCTREE;
version = STORAGE_TYPE_VERSION_OCTREE;
}
else
{
throw new InvalidBranchException();
}
buf.WriteNoAlloc(name);
buf.Write7BitEncodedInt(version);
SaveInternal(buf);
}
m_compressedData = ms.ToArray();
}
outCompressedData = m_compressedData;
}
finally
{
ProfilerShort.End();
}
}
示例3: SaveCompressedData
protected void SaveCompressedData(out byte[] compressedData)
{
MemoryStream ms;
using (ms = new MemoryStream(0x4000))
using (GZipStream gz = new GZipStream(ms, CompressionMode.Compress))
using (BufferedStream buf = new BufferedStream(gz, 0x4000))
{
string name;
int version;
if (GetType() == typeof(MyOctreeStorage))
{
name = STORAGE_TYPE_NAME_OCTREE;
version = STORAGE_TYPE_VERSION_OCTREE;
}
else
{
throw new InvalidBranchException();
}
buf.WriteNoAlloc(name);
buf.Write7BitEncodedInt(version);
SaveInternal(buf);
}
compressedData = ms.ToArray();
}
示例4: Save
public void Save(out byte[] outCompressedData)
{
Profiler.Begin("MyStorageBase.Save");
try
{
if (m_compressedData == null)
{
MemoryStream ms;
using (ms = new MemoryStream(0x4000))
using (GZipStream gz = new GZipStream(ms, CompressionMode.Compress))
using (BufferedStream buf = new BufferedStream(gz, 0x4000))
{
var attr = m_attributesByType[GetType()];
buf.WriteNoAlloc(attr.SerializedTypeName);
buf.Write7BitEncodedInt(attr.SerializedVersion);
SaveInternal(buf);
}
m_compressedData = ms.ToArray();
}
outCompressedData = m_compressedData;
}
finally
{
Profiler.End();
}
}