本文整理汇总了C#中System.IO.Stream.Close方法的典型用法代码示例。如果您正苦于以下问题:C# Stream.Close方法的具体用法?C# Stream.Close怎么用?C# Stream.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Stream
的用法示例。
在下文中一共展示了Stream.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteXFormToXmlFile
/// <summary>
/// Write data from form to output stream.
/// </summary>
/// <param name="stream">Output stream.</param>
/// <param name="xForm">XForm with data.</param>
public void WriteXFormToXmlFile(Stream stream, XForm xForm)
{
var settings = new XmlWriterSettings();
settings.Indent = true;
settings.NamespaceHandling = NamespaceHandling.OmitDuplicates;
using (var writer = System.Xml.XmlWriter.Create(stream, settings))
{
writer.WriteStartElement(xForm.Root.Name);
writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
foreach (var xAttribute in xForm.Root.Attributes)
{
writer.WriteAttributeString(xAttribute.Name, xAttribute.GetStringXmlValue());
}
foreach (var xElement in xForm.Root.Elements)
{
xElement.WriteXml(writer);
}
foreach (var xContainer in xForm.Root.Containers)
{
xContainer.WriteXml(writer);
}
writer.WriteEndElement();
}
stream.Close();
}
示例2: Get
public static string Get(Stream fs)
{
HashAlgorithm ha = HashAlgorithm.Create();
byte[] bytes = ha.ComputeHash(fs);
fs.Close();
return ToHexString(bytes);
}
示例3: Art
public Art(Stream input)
{
ImageData=new byte[input.Length];
input.Read(ImageData, 0, ImageData.Length);
input.Close();
input.Dispose();
}
示例4: load
/// <summary>
/// Reads a generic Pokémon container from a Stream.
/// Those containers are the ones that starts with "GR", "MM", "AD" and so on...
/// </summary>
/// <param name="data">Stream with container data</param>
/// <returns></returns>
public static OContainer load(Stream data)
{
BinaryReader input = new BinaryReader(data);
OContainer output = new OContainer();
IOUtils.readString(input, 0, 2); //Magic
ushort sectionCount = input.ReadUInt16();
for (int i = 0; i < sectionCount; i++)
{
OContainer.fileEntry entry = new OContainer.fileEntry();
data.Seek(4 + (i * 4), SeekOrigin.Begin);
uint startOffset = input.ReadUInt32();
uint endOffset = input.ReadUInt32();
uint length = endOffset - startOffset;
data.Seek(startOffset, SeekOrigin.Begin);
byte[] buffer = new byte[length];
input.Read(buffer, 0, (int)length);
entry.data = buffer;
output.content.Add(entry);
}
data.Close();
return output;
}
示例5: RenderFromExcel
public static DataTable RenderFromExcel(Stream ExcelFileStream, string SheetName, int HeaderRowIndex)
{
var workbook = new HSSFWorkbook(ExcelFileStream);
var sheet = workbook.GetSheet(SheetName);
var table = new DataTable();
var headerRow = sheet.GetRow(HeaderRowIndex);
int cellCount = headerRow.LastCellNum;
for (int i = headerRow.FirstCellNum; i < cellCount; i++)
{
var column = new DataColumn(headerRow.GetCell(i).StringCellValue);
table.Columns.Add(column);
}
int rowCount = sheet.LastRowNum;
for (int i = (sheet.FirstRowNum + 1); i < sheet.LastRowNum; i++)
{
var row = sheet.GetRow(i);
var dataRow = table.NewRow();
for (int j = row.FirstCellNum; j < cellCount; j++)
dataRow[j] = row.GetCell(j).ToString();
}
ExcelFileStream.Close();
workbook = null;
sheet = null;
return table;
}
示例6: CloseStream
public void CloseStream(Stream stream)
{
if (stream != null)
{
stream.Close();
}
}
示例7: OpenAndAddToWordprocessingStream
private static void OpenAndAddToWordprocessingStream(Stream stream, string txt)
{
Document doc = new Document(stream);
stream.Close();
DocumentBuilder db = new DocumentBuilder(doc);
db.Writeln(txt);
doc.Save(FileName);
}
示例8: ReadToEnd
public byte[] ReadToEnd(string path)
{
Stream = new FileStream(path, FileMode.Open);
var memoryStream = new MemoryStream();
Stream.CopyTo(memoryStream);
Stream.Close();
return memoryStream.ToArray();
}
示例9: Check
public bool Check(Stream stream, bool closeStream = false)
{
var buffer = new byte[5];
stream.Read(buffer, 0, 5);
if (closeStream)
stream.Close();
return Check(buffer, 5);
}
示例10: load
/// <summary>
/// Reads a DARC archive.
/// </summary>
/// <param name="data">Stream of the data</param>
/// <returns>The container data</returns>
public static OContainer load(Stream data)
{
OContainer output = new OContainer();
BinaryReader input = new BinaryReader(data);
string darcMagic = IOUtils.readStringWithLength(input, 4);
ushort endian = input.ReadUInt16();
ushort headerLength = input.ReadUInt16();
uint version = input.ReadUInt32();
uint fileSize = input.ReadUInt32();
uint tableOffset = input.ReadUInt32();
uint tableLength = input.ReadUInt32();
uint dataOffset = input.ReadUInt32();
data.Seek(tableOffset, SeekOrigin.Begin);
fileEntry root = getEntry(input);
int baseOffset = (int)data.Position;
int namesOffset = (int)(tableOffset + root.length * 0xc);
string currDir = null;
for (int i = 0; i < root.length - 1; i++)
{
data.Seek(baseOffset + i * 0xc, SeekOrigin.Begin);
fileEntry entry = getEntry(input);
if ((entry.flags & 1) > 0)
{
//Folder
int index = i;
currDir = null;
for (;;)
{
uint parentIndex = entry.offset;
currDir = getName(input, entry.nameOffset + namesOffset) + "/" + currDir;
if (parentIndex == 0 || parentIndex == index) break;
data.Seek(baseOffset + parentIndex * 0xc, SeekOrigin.Begin);
entry = getEntry(input);
index = (int)parentIndex;
}
continue;
}
data.Seek(entry.offset, SeekOrigin.Begin);
byte[] buffer = new byte[entry.length];
data.Read(buffer, 0, buffer.Length);
OContainer.fileEntry file = new OContainer.fileEntry();
file.name = currDir + getName(input, entry.nameOffset + namesOffset);
file.data = buffer;
output.content.Add(file);
}
data.Close();
return output;
}
示例11: SubirFichero
public void SubirFichero(Stream fichero, string nombre, string contenedor = null)
{
ComprobarContenedor();
var cliente = _cuenta.CreateCloudBlobClient();
var cont = cliente.GetContainerReference(_contenedor);
var blob = cont.GetBlockBlobReference(nombre);
blob.UploadFromStream(fichero);
fichero.Close();
}
示例12: CleanTo
public void CleanTo(Stream strDest)
{
using (DocxDocumentProcessor dp = new DocxDocumentProcessor(m_data.AsStream()))
{
dp.Output = strDest;
dp.Process(DocumentProcessingActions.Clean);
strDest.Close();
}
}
示例13: CorrectView
private Stream CorrectView(string virtualPath, Stream stream)
{
if (_viewFixer == null)
return stream;
var outStream = _viewFixer.CorrectView(virtualPath, stream);
stream.Close();
return outStream;
}
示例14: SubirFichero
public void SubirFichero(Stream fichero, string nombre, string contenedor = null)
{
ComprobarContenedor(contenedor);
var cliente = _cuenta.CreateCloudBlobClient();
var cont = cliente.GetContainerReference(_contenedor);
var blob = cont.GetBlockBlobReference(nombre);
blob.UploadFromStream(fichero); //podría hacerse upload de array binario, texto, etc
fichero.Close();
}
示例15: load
/// <summary>
/// Loads a Fantasy Life ZTEX texture from a Stream.
/// </summary>
/// <param name="data">The Stream with the data</param>
/// <returns>The list of textures</returns>
public static List<RenderBase.OTexture> load(Stream data)
{
List<RenderBase.OTexture> textures = new List<RenderBase.OTexture>();
BinaryReader input = new BinaryReader(data);
string ztexMagic = IOUtils.readString(input, 0, 4);
ushort textureCount = input.ReadUInt16();
input.ReadUInt16();
input.ReadUInt32();
List<textureEntry> entries = new List<textureEntry>();
for (int i = 0; i < textureCount; i++)
{
textureEntry entry = new textureEntry();
entry.name = IOUtils.readString(input, (uint)(0xc + (i * 0x58)));
data.Seek(0xc + (i * 0x58) + 0x40, SeekOrigin.Begin);
input.ReadUInt32();
entry.offset = input.ReadUInt32();
input.ReadUInt32();
entry.length = input.ReadUInt32();
entry.width = input.ReadUInt16();
entry.height = input.ReadUInt16();
input.ReadByte();
entry.format = input.ReadByte();
input.ReadUInt16();
entries.Add(entry);
}
foreach (textureEntry entry in entries)
{
data.Seek(entry.offset, SeekOrigin.Begin);
byte[] buffer = new byte[entry.length];
data.Read(buffer, 0, buffer.Length);
Bitmap bmp = null;
switch (entry.format)
{
case 1: bmp = TextureCodec.decode(buffer, entry.width, entry.height, RenderBase.OTextureFormat.rgb565); break;
case 5: bmp = TextureCodec.decode(buffer, entry.width, entry.height, RenderBase.OTextureFormat.rgba4); break;
case 9: bmp = TextureCodec.decode(buffer, entry.width, entry.height, RenderBase.OTextureFormat.rgba8); break;
case 0x18: bmp = TextureCodec.decode(buffer, entry.width, entry.height, RenderBase.OTextureFormat.etc1); break;
case 0x19: bmp = TextureCodec.decode(buffer, entry.width, entry.height, RenderBase.OTextureFormat.etc1a4); break;
}
textures.Add(new RenderBase.OTexture(bmp, entry.name));
}
data.Close();
return textures;
}