本文整理匯總了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();
}
}