本文整理汇总了C#中Stream.Close方法的典型用法代码示例。如果您正苦于以下问题:C# Stream.Close方法的具体用法?C# Stream.Close怎么用?C# Stream.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stream
的用法示例。
在下文中一共展示了Stream.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DisposeObject
private static void DisposeObject(ref HttpWebRequest request, ref HttpWebResponse response,
ref Stream responseStream, ref StreamReader reader)
{
if (request != null)
{
request = null;
}
if (response != null)
{
response.Close();
response = null;
}
if (responseStream != null)
{
responseStream.Close();
responseStream.Dispose();
responseStream = null;
}
if (reader != null)
{
reader.Close();
reader.Dispose();
reader = null;
}
}
示例2: Sims3Pack
public Sims3Pack(string FileName)
: this()
{
IsEncrypted = false;
DataStore = File.Open(FileName, FileMode.Open, FileAccess.Read,FileShare.Read);
try
{
Import();
}
catch (InvalidDataException e)
{
DataStore.Close();
if (e.Message == "DBPP Not Supported") IsEncrypted = true;
//throw e;
}
catch (XmlException)
{
DataStore.Close();
IsCorrupt = true;
// throw e;
}
catch (EndOfStreamException)
{
DataStore.Close();
IsCorrupt = true;
//throw e;
}
}
示例3: CopyAsync
private static void CopyAsync(byte[] buffer, FileStream inputStream, Stream outputStream, TaskCompletionSource<object> tcs)
{
inputStream.ReadAsync(buffer).Then(read =>
{
if (read > 0)
{
outputStream.WriteAsync(buffer, 0, read)
.Then(() => CopyAsync(buffer, inputStream, outputStream, tcs))
.Catch(ex =>
{
inputStream.Close();
outputStream.Close();
tcs.SetException(ex);
});
}
else
{
inputStream.Close();
outputStream.Close();
tcs.SetResult(null);
}
})
.Catch(ex =>
{
inputStream.Close();
outputStream.Close();
tcs.SetException(ex);
});
}
示例4: PckFile
public PckFile(Stream pckFile, Stream tabFile,int bpp,Palette pal,int imgHeight,int imgWidth)
{
if(tabFile!=null)
tabFile.Position=0;
pckFile.Position=0;
byte[] info = new byte[pckFile.Length];
pckFile.Read(info,0,info.Length);
pckFile.Close();
this.bpp=bpp;
Pal=pal;
uint[] offsets;
if(tabFile!=null)
{
offsets= new uint[(tabFile.Length/bpp)+1];
BinaryReader br = new BinaryReader(tabFile);
if(bpp==2)
for(int i=0;i<tabFile.Length/bpp;i++)
offsets[i] = br.ReadUInt16();
else
for(int i=0;i<tabFile.Length/bpp;i++)
offsets[i] = br.ReadUInt32();
br.Close();
}
else
{
offsets = new uint[2];
offsets[0]=0;
}
offsets[offsets.Length-1] = (uint)info.Length;
for(int i=0;i<offsets.Length-1;i++)
{
byte[] imgDat = new byte[offsets[i+1]-offsets[i]];
for(int j=0;j<imgDat.Length;j++)
imgDat[j] = info[offsets[i]+j];
Add(new PckImage(i,imgDat,pal,this,imgHeight,imgWidth));
}
pckFile.Close();
if(tabFile!=null)
tabFile.Close();
}
示例5: loadDDS
public void loadDDS(Stream input)
{
this.lockImage = true;
ddsFile.Load(input);
pictureBox1.Image = ddsFile.Image();
toolStripStatusLabel1.Text = "";
toolStripStatusLabel2.Text = "W: " + ddsFile.m_header.m_width.ToString();
toolStripStatusLabel3.Text = "H: " + ddsFile.m_header.m_height.ToString();
if (ddsFile.m_header.m_pixelFormat.m_rgbBitCount.ToString() != "0" && ddsFile.m_header.m_pixelFormat.m_rgbBitCount.ToString() != "")
{
toolStripStatusLabel4.Text = ddsFile.m_header.m_pixelFormat.m_rgbBitCount.ToString() + "bit";
toolStripStatusLabel4.Visible = true;
}
else
{
toolStripStatusLabel4.Visible = false;
}
toolStripStatusLabel5.Text = ddsFile.m_header.fileFormat;
chkShowRed.Checked = true;
chkShowGreen.Checked = true;
chkShowBlue.Checked = true;
chkShowAlpha.Checked = false;
input.Close();
this.lockImage = false;
}
示例6: CopyWithLambda
private void CopyWithLambda(Stream s, Stream d, ref long total)
{
var buffer = new byte[4096];
try
{
while (true)
{
var read = s.Read(buffer, 0, 4096);
if (read == 0)
break;
var tmpTotal = Interlocked.Add(ref total, read);
if (VetoTransfer(tmpTotal, new ArraySegment<byte>(buffer, 0, read)))
{
//force close of both streams
s.Close();
d.Close();
throw new Exception("Transfer vetoed!");
}
d.Write(buffer, 0, read);
if (IsEndOfChunkEncoding(buffer, 0, read))
{
break;
}
}
}
catch (IOException)
{
}
}
示例7: sendMessage_ToServer
public bool sendMessage_ToServer(String message)
{
bool state = false;
try
{
tcpClient.Connect(IPAddress.Parse("127.0.0.1"), 6000);
if (tcpClient.Connected)
{
stm = tcpClient.GetStream();
byte[] buffer = ascii.GetBytes(message);
stm.Write(buffer, 0, buffer.Length);
stm.Close();
state = true;
}
else
{
Console.WriteLine("Server is unreachable.....");
state = false;
}
}
catch (Exception e)
{
Console.WriteLine("Message Sending Failed...... \n" + e.StackTrace);
}
finally {
tcpClient.Close();
}
return state;
}
示例8: CloseStream
public void CloseStream(Stream stream)
{
Debug.Assert(stream != null);
Debug.Assert(stream is FileStream);
stream.Close();
}
示例9: StreamVideo
public async Task StreamVideo(Stream stream, HttpContent content, TransportContext transport)
{
try
{
var buffer = new byte[65536];
var filename = Path.Combine(String.Format("{0}{1}video.{2}", System.Web.HttpContext.Current.Server.MapPath("~"), Constants.FilePath, _fileExtension));
using (var file = File.Open(filename, FileMode.Open, FileAccess.Read))
{
var videoLength = (int)file.Length;
var placeInFile = 1;
while (videoLength > 0 && placeInFile > 0)
{
placeInFile = file.Read(buffer, 0, Math.Min(videoLength, buffer.Length));
await stream.WriteAsync(buffer, 0, placeInFile);
videoLength -= placeInFile;
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.InnerException);
}
finally
{
stream.Close();
}
}
示例10: RenderDataTableFromExcel
public static DataTable RenderDataTableFromExcel(Stream ExcelFileStream, string SheetName, int HeaderRowIndex)
{
HSSFWorkbook workbook = new HSSFWorkbook(ExcelFileStream);
HSSFSheet sheet = workbook.GetSheet(SheetName);
DataTable table = new DataTable();
HSSFRow headerRow = sheet.GetRow(HeaderRowIndex);
int cellCount = headerRow.LastCellNum;
for (int i = headerRow.FirstCellNum; i < cellCount; i++)
{
DataColumn 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++)
{
HSSFRow row = sheet.GetRow(i);
DataRow 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;
}
示例11: UploadDocument
public static string UploadDocument(Stream stream, string filePath, string fileName)
{
int pos = fileName.LastIndexOf('.');
string extFile = string.Empty;
extFile = fileName.Substring(pos);
string uploadFilename = Guid.NewGuid().ToString();
try
{
stream.Seek(0, SeekOrigin.Begin);
using (FileStream fileStream = new FileStream(filePath + uploadFilename + extFile, FileMode.Create, FileAccess.Write))
{
byte[] buffer = new byte[Constants.BUFFER_SIZE];
int bufferSize = 0;
do
{
bufferSize = stream.Read(buffer, 0, buffer.Length);
fileStream.Write(buffer, 0, bufferSize);
} while (bufferSize > 0);
stream.Close();
fileStream.Close();
}
}
catch (ApplicationException)
{
throw;
}
catch (Exception ex)
{
log4net.Util.LogLog.Error(ex.Message, ex);
}
return uploadFilename + extFile;
}
示例12: Decode
// Source: http://blogs.msdn.com/b/feroze_daud/archive/2004/03/30/104440.aspx
public static String Decode(WebResponse response, Stream stream)
{
String charset = null;
String contentType = response.Headers["content-type"];
if(contentType != null)
{
int index = contentType.IndexOf("charset=");
if(index != -1)
{
charset = contentType.Substring(index + 8);
}
}
MemoryStream data = new MemoryStream();
byte[] buffer = new byte[1024];
int read = stream.Read(buffer, 0, buffer.Length);
while(read > 0)
{
data.Write(buffer, 0, read);
read = stream.Read(buffer, 0, buffer.Length);
}
stream.Close();
Encoding encoding = Encoding.UTF8;
try
{
if(charset != null)
encoding = Encoding.GetEncoding(charset);
}
catch { }
data.Seek(0, SeekOrigin.Begin);
StreamReader streamReader = new StreamReader(data, encoding);
return streamReader.ReadToEnd();
}
示例13: WriteToStream
public async void WriteToStream(Stream outputStream, HttpContent content, TransportContext context)
{
try
{
var buffer = new byte[65536];
using (var media = File.Open(_filename, FileMode.Open, FileAccess.Read))
{
var length = (int)media.Length;
var bytesRead = 1;
while (length > 0 && bytesRead > 0)
{
bytesRead = media.Read(buffer, 0, Math.Min(length, buffer.Length));
await outputStream.WriteAsync(buffer, 0, bytesRead);
length -= bytesRead;
}
}
}
catch (Exception ex)
{
throw new BlogException(ex.Message, ex);
}
finally
{
outputStream.Close();
}
}
示例14: Close
public void Close(Stream stream)
{
if (stream != null)
{
stream.Close();
}
}
示例15: EasyWebRequest
public EasyWebRequest(string method, string userName, string password, string authID, string masterKey, string baseURL, string contraint)
{
request = WebRequest.Create(baseURL);
request.ContentType = "text/xml";
request.Credentials = new NetworkCredential(userName, password);
request.Headers.Add("X-Parse-Application-Id: " + authID);
request.Headers.Add("X-Parse-Master-Key: " + masterKey);
if (method.Equals("GET") || method.Equals("POST"))
request.Method = method;
else
throw new Exception("Invalid Method Type");
string postData = contraint;
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
}