本文整理汇总了C#中DeflateStream.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# DeflateStream.Dispose方法的具体用法?C# DeflateStream.Dispose怎么用?C# DeflateStream.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DeflateStream
的用法示例。
在下文中一共展示了DeflateStream.Dispose方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompressCanWrite
public void CompressCanWrite()
{
var ms = new MemoryStream();
var zip = new DeflateStream(ms, CompressionMode.Compress);
Assert.True(zip.CanWrite);
zip.Dispose();
Assert.False(zip.CanWrite);
}
示例2: DecompressCanRead
public void DecompressCanRead()
{
var ms = new MemoryStream();
var zip = new DeflateStream(ms, CompressionMode.Decompress);
Assert.True(zip.CanRead);
zip.Dispose();
Assert.False(zip.CanRead);
}
示例3: CanReadBaseStreamAfterDispose
public async Task CanReadBaseStreamAfterDispose()
{
var ms = await LocalMemoryStream.readAppFileAsync(gzTestFile("GZTestDocument.txt.gz"));
var newMs = StripHeaderAndFooter.Strip(ms);
var zip = new DeflateStream(newMs, CompressionMode.Decompress, true);
var baseStream = zip.BaseStream;
zip.Dispose();
int size = 1024;
byte[] bytes = new byte[size];
baseStream.Read(bytes, 0, size); // This will throw if the underlying stream is not writable as expected
baseStream.Position = 0;
await baseStream.ReadAsync(bytes, 0, size);
}
示例4: CanDisposeDeflateStream
public void CanDisposeDeflateStream()
{
var ms = new MemoryStream();
var zip = new DeflateStream(ms, CompressionMode.Compress);
zip.Dispose();
// Base Stream should be null after dispose
Assert.Null(zip.BaseStream);
zip.Dispose(); // Should be a no-op
}
示例5: FlushAsyncFailsAfterDispose
public async Task FlushAsyncFailsAfterDispose()
{
var ms = new MemoryStream();
var ds = new DeflateStream(ms, CompressionMode.Compress);
ds.Dispose();
await Assert.ThrowsAsync<ObjectDisposedException>(async () =>
{
await ds.FlushAsync();
});
}
示例6: CopyToAsyncArgumentValidation
public void CopyToAsyncArgumentValidation()
{
using (DeflateStream ds = new DeflateStream(new MemoryStream(), CompressionMode.Decompress))
{
Assert.Throws<ArgumentNullException>("destination", () => { ds.CopyToAsync(null); });
Assert.Throws<ArgumentOutOfRangeException>("bufferSize", () => { ds.CopyToAsync(new MemoryStream(), 0); });
Assert.Throws<NotSupportedException>(() => { ds.CopyToAsync(new MemoryStream(new byte[1], writable: false)); });
ds.Dispose();
Assert.Throws<ObjectDisposedException>(() => { ds.CopyToAsync(new MemoryStream()); });
}
using (DeflateStream ds = new DeflateStream(new MemoryStream(), CompressionMode.Compress))
{
Assert.Throws<NotSupportedException>(() => { ds.CopyToAsync(new MemoryStream()); });
}
}
示例7: FlushFailsAfterDispose
public void FlushFailsAfterDispose()
{
var ms = new MemoryStream();
var ds = new DeflateStream(ms, CompressionMode.Compress);
ds.Dispose();
Assert.Throws<ObjectDisposedException>(() => { ds.Flush(); });
}
示例8: FlushThenDispose
public void FlushThenDispose()
{
var ms = new MemoryStream();
var ds = new DeflateStream(ms, CompressionMode.Compress);
ds.Flush();
ds.Dispose();
}
示例9: DoubleDispose
public void DoubleDispose()
{
var ms = new MemoryStream();
var ds = new DeflateStream(ms, CompressionMode.Compress);
ds.Dispose();
ds.Dispose();
}
示例10: DecompressFailsWithRealGzStream
public async Task DecompressFailsWithRealGzStream()
{
string[] files = { gzTestFile("GZTestDocument.doc.gz"), gzTestFile("GZTestDocument.txt.gz") };
foreach (string fileName in files)
{
var baseStream = await LocalMemoryStream.readAppFileAsync(fileName);
var zip = new DeflateStream(baseStream, CompressionMode.Decompress);
int _bufferSize = 2048;
var bytes = new byte[_bufferSize];
Assert.Throws<InvalidDataException>(() => { zip.Read(bytes, 0, _bufferSize); });
zip.Dispose();
}
}
示例11: FromXML
public override void FromXML(XmlNode node)
{
if (node != null && node.Name == "layer")
{
XmlAttributeCollection attrs = node.Attributes;
m_name = attrs["name"].Value;
m_layerDimensions.first = Convert.ToInt32(attrs["width"].Value);
m_layerDimensions.second = Convert.ToInt32(attrs["height"].Value);
foreach(XmlNode child in node.ChildNodes)
{
if (child.Name == "properties")
{
foreach (XmlNode propertyNode in child)
{
if (propertyNode.Name != "property")
continue;
XmlAttributeCollection propertyAtts = propertyNode.Attributes;
m_properties[propertyAtts["name"].Value] = propertyAtts["value"].Value;
}
}
else if (child.Name == "data")
{
m_data = new TileData();
attrs = child.Attributes;
if (attrs["encoding"]!= null)
{
string[] encodings = { "", "csv", "base64" };
string encodingValue = attrs["encoding"].Value;
int encodingIdx = Array.IndexOf(encodings, encodingValue);
if (encodingIdx >= 0)
{
m_data.m_encoding = (TileEncodingType)encodingIdx;
}
string[] compressions = { "", "gzip", "zlib" };
string compression = attrs["compression"].Value;
int compressionIdx = Array.IndexOf(compressions, compression);
if (compressionIdx >= 0)
{
m_data.m_compression = (TileCompressionType)compressionIdx;
}
switch(m_data.m_encoding)
{
case TileEncodingType.kCSV:
{
string text = child.InnerText;
string[] values = text.Split(',');
foreach (string v in values)
{
uint value = Convert.ToUInt32(v);
TileInfo info = new TileInfo();
info.m_horizontalFlip = (value & FLIPPED_HORIZONTALLY_FLAG) != 0;
info.m_verticalFlip = (value & FLIPPED_VERTICALLY_FLAG) != 0;
info.m_diagonalFlip = (value & FLIPPED_DIAGONALLY_FLAG) != 0;
value = value & ~(FLIPPED_DIAGONALLY_FLAG | FLIPPED_HORIZONTALLY_FLAG | FLIPPED_VERTICALLY_FLAG);
info.m_gid = value;
m_data.m_tiles.Add(info);
}
break;
}
case TileEncodingType.kBase64:
{
byte[] bytes = null;
switch(m_data.m_compression)
{
case TileCompressionType.kNone:
{
bytes = Convert.FromBase64String(child.InnerText);
break;
}
case TileCompressionType.kGzip:
{
//Transform string into byte[]
string str = child.InnerText;
byte[] byteArray = new byte[str.Length];
int indexBA = 0;
foreach (char item in str.ToCharArray())
{
byteArray[indexBA++] = (byte)item;
}
MemoryStream ms = new MemoryStream(byteArray);
GZipStream gzip = new GZipStream(ms, CompressionMode.Decompress);
byteArray = new byte[byteArray.Length];
int rBytes = gzip.Read(byteArray, 0, byteArray.Length);
StringBuilder sb = new StringBuilder(rBytes);
for (int i = 0; i < rBytes; ++i)
{
sb.Append((char)byteArray[i]);
}
gzip.Close();
ms.Close();
gzip.Dispose();
ms.Dispose();
bytes = Convert.FromBase64String(sb.ToString());
//.........这里部分代码省略.........