本文整理汇总了C#中Stream.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Stream.GetType方法的具体用法?C# Stream.GetType怎么用?C# Stream.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stream
的用法示例。
在下文中一共展示了Stream.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProtectedConsoleStream
public ProtectedConsoleStream(Stream stream)
{
if ((stream.GetType() != Type.GetType("System.IO.__ConsoleStream")) &&
(stream.GetType() != Type.GetType("System.IO.FileStream")))
{
throw new ArgumentException("Not ConsoleStream");
}
m_stream = stream;
}
示例2: ProtectedConsoleStream
public ProtectedConsoleStream(Stream s)
{
if((s.GetType() != Type.GetType("System.IO.__ConsoleStream"))&&
(s.GetType() != Type.GetType("System.IO.FileStream")))//for mono
{
throw new ArgumentException("Not ConsoleStream");
}
this.s=s;
}
示例3: Connect
public void Connect()
{
Uri uri = new Uri("http://" + settings.Server + ":" + settings.Port + settings.Mount);
req = (HttpWebRequest)WebRequest.Create(uri);
//req.Proxy = proxy;
//req.UserAgent = userAgent;
req.ProtocolVersion = HttpVersion.Version10; // new Version("ICE/1.0");
req.Method = "SOURCE";
req.ContentType = "audio/mpeg";
req.Headers.Add("ice-name", settings.Name ?? "no name");
req.Headers.Add("ice-public", "1");
if ((settings.Url ?? "") != "") req.Headers.Add("ice-url", settings.Url);
if ((settings.Genre ?? "") != "") req.Headers.Add("ice-genre", settings.Genre);
if ((settings.Desctiption ?? "") != "") req.Headers.Add("ice-description", settings.Desctiption);
req.Headers.Add("Authorization", string.Format("Basic {0}", Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format("source:{0}", settings.Password)))));
req.Timeout = System.Threading.Timeout.Infinite;
req.ReadWriteTimeout = System.Threading.Timeout.Infinite;
//req.ContentLength = 999999999;
req.KeepAlive = false;
req.SendChunked = true;
req.AllowWriteStreamBuffering = false;
req.CachePolicy = new System.Net.Cache.HttpRequestCachePolicy(System.Net.Cache.HttpRequestCacheLevel.BypassCache);
System.Reflection.PropertyInfo pi = typeof(ServicePoint).GetProperty("HttpBehaviour", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
pi.SetValue(req.ServicePoint, pi.PropertyType.GetField("Unknown").GetValue(null), null);
reqStream = req.GetRequestStream();
System.Reflection.FieldInfo fi = reqStream.GetType().GetField("m_HttpWriteMode", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
fi.SetValue(reqStream, fi.FieldType.GetField("Buffer").GetValue(null));
System.Reflection.MethodInfo mi = reqStream.GetType().GetMethod("CallDone", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic, null, new Type[0], null);
mi.Invoke(reqStream, null);
try
{
resp = req.GetResponse() as HttpWebResponse;
if (resp.StatusCode == HttpStatusCode.OK)
{
encoder = new CUETools.Codecs.LAME.LAMEEncoderCBR("", reqStream, AudioPCMConfig.RedBook);
(encoder.Settings as CUETools.Codecs.LAME.LAMEEncoderCBRSettings).StereoMode = settings.JointStereo ?
CUETools.Codecs.LAME.Interop.MpegMode.JOINT_STEREO : CUETools.Codecs.LAME.Interop.MpegMode.STEREO;
(encoder.Settings as CUETools.Codecs.LAME.LAMEEncoderCBRSettings).CustomBitrate = settings.Bitrate;
}
}
catch (WebException ex)
{
if (ex.Status == WebExceptionStatus.ProtocolError)
resp = ex.Response as HttpWebResponse;
else
throw ex;
}
}
示例4: BinaryReader
public BinaryReader(Stream input, Encoding encoding, bool leaveOpen) {
if (input==null) {
throw new ArgumentNullException(nameof(input));
}
if (encoding==null) {
throw new ArgumentNullException(nameof(encoding));
}
if (!input.CanRead)
throw new ArgumentException(Environment.GetResourceString("Argument_StreamNotReadable"));
Contract.EndContractBlock();
m_stream = input;
m_decoder = encoding.GetDecoder();
m_maxCharsSize = encoding.GetMaxCharCount(MaxCharBytesSize);
int minBufferSize = encoding.GetMaxByteCount(1); // max bytes per one char
if (minBufferSize < 16)
minBufferSize = 16;
m_buffer = new byte[minBufferSize];
// m_charBuffer and m_charBytes will be left null.
// For Encodings that always use 2 bytes per char (or more),
// special case them here to make Read() & Peek() faster.
m_2BytesPerChar = encoding is UnicodeEncoding;
// check if BinaryReader is based on MemoryStream, and keep this for it's life
// we cannot use "as" operator, since derived classes are not allowed
m_isMemoryStream = (m_stream.GetType() == typeof(MemoryStream));
m_leaveOpen = leaveOpen;
Contract.Assert(m_decoder!=null, "[BinaryReader.ctor]m_decoder!=null");
}
示例5: StreamToBuffer
internal byte[] StreamToBuffer (Stream assemblyStream)
{
byte [] buffer;
using (assemblyStream) {
// avoid extra step for MemoryStream (but not any stream that inherits from it)
if (assemblyStream.GetType () == MemoryStreamType)
return (assemblyStream as MemoryStream).ToArray ();
// it's normally bad to depend on Stream.Length since some stream (e.g. NetworkStream)
// don't implement them. However it is safe in this case (i.e. SL2 depends on Length too)
buffer = new byte [assemblyStream.Length];
int length = buffer.Length;
int offset = 0;
while (length > 0) {
int read = assemblyStream.Read (buffer, offset, length);
if (read == 0)
break;
length -= read;
offset += read;
}
}
return buffer;
}
示例6: ShouldWrapStream
private static bool ShouldWrapStream( Stream stream )
{
return
( stream != null
&& !_knownMemoryOrBufferingStreams.Contains( stream.GetType().FullName ) )
#if DEBUG
|| _alwaysWrap
#endif // DEBUG
;
}
示例7: Add
public override void Add(long key, Stream value)
{
String name = value.GetType().Name;
m_NamedMountPoints.Add(key, name);
logger.Debug(String.Format("Stream Mount: {0} -> {1}", key.ToString("X8"), name));
base.Add(key, value);
}
示例8: Marshall
/**
* Save the specified part.
*
* @throws OpenXml4NetException
* Throws if an internal exception is thrown.
*/
public bool Marshall(PackagePart part, Stream os)
{
if (!(os is ZipOutputStream))
{
logger.Log(POILogger.ERROR,"Unexpected class " + os.GetType().Name);
throw new OpenXml4NetException("ZipOutputStream expected !");
// Normally should happen only in developement phase, so just throw
// exception
}
ZipOutputStream zos = (ZipOutputStream)os;
string name = ZipHelper
.GetZipItemNameFromOPCName(part.PartName.URI
.OriginalString);
ZipEntry partEntry = new ZipEntry(name);
try
{
// Create next zip entry
zos.PutNextEntry(partEntry);
// Saving data in the ZIP file
Stream ins = part.GetInputStream();
byte[] buff = new byte[ZipHelper.READ_WRITE_FILE_BUFFER_SIZE];
int totalRead = 0;
while (true)
{
int resultRead = ins.Read(buff, 0, buff.Length);
if (resultRead == 0)
{
// End of file reached
break;
}
zos.Write(buff, 0, resultRead);
totalRead += resultRead;
}
zos.CloseEntry();
}
catch (IOException ioe)
{
logger.Log(POILogger.ERROR, "Cannot write: " + part.PartName + ": in ZIP", ioe);
return false;
}
// Saving relationship part
if (part.HasRelationships)
{
PackagePartName relationshipPartName = PackagingUriHelper
.GetRelationshipPartName(part.PartName);
MarshallRelationshipPart(part.Relationships,
relationshipPartName, zos);
}
return true;
}
示例9: WriteBeyondEndTest
public static bool WriteBeyondEndTest(Stream s)
{
Console.WriteLine("Write Beyond End test on "+s.GetType().Name);
FileStream fs = s as FileStream;
if (fs != null)
Console.WriteLine("FileStream type is: "+(fs.IsAsync ? "asynchronous" : "synchronous"));
long origLength = s.Length;
byte[] bytes = new byte[10];
for(int i=0; i<bytes.Length; i++)
bytes[i] = (byte) i;
int spanPastEnd = 5;
s.Seek(spanPastEnd, SeekOrigin.End);
if (s.Position != s.Length + spanPastEnd)
throw new Exception("Position is incorrect! Seek(5, SeekOrigin.End) should leave us at s.Length + spanPastEnd ("+(s.Length + spanPastEnd)+"), but got: "+s.Position);
Console.WriteLine("Original Length: "+origLength);
s.Write(bytes, 0, bytes.Length);
long pos = s.Position;
if (pos != origLength + spanPastEnd + bytes.Length)
throw new Exception(String.Format("After asynchronously writing beyond end of the stream, position is now incorrect! origLength: {0} pos: {1}", origLength, pos));
if (s.Length != origLength + spanPastEnd + bytes.Length)
throw new Exception(String.Format("After asynchronously writing beyond end of the stream, Length is now incorrect! origLength: {0} pos: {1}", origLength, pos));
WritePastEndHelper(s, bytes, origLength, spanPastEnd, false);
origLength = s.Length;
s.Position = s.Length + spanPastEnd;
s.WriteByte(0x42);
long expected = origLength + spanPastEnd + 1;
if (s.Position != expected)
{
iCountErrors++ ;
throw new Exception("After WriteByte, Position was wrong! got: "+s.Position+" expected: "+expected);
}
if (s.Length != expected)
{
iCountErrors++ ;
throw new Exception("After WriteByte, Length was wrong! got: "+s.Length+" expected: "+expected);
}
origLength = s.Length;
s.Position = s.Length + spanPastEnd;
IAsyncResult ar = s.BeginWrite(bytes, 0, bytes.Length, null, null);
s.EndWrite(ar);
pos = s.Position;
if (pos != origLength + spanPastEnd + bytes.Length)
{
iCountErrors++ ;
throw new Exception(String.Format("After writing beyond end of the stream, position is now incorrect! origLength: {0} pos: {1}", origLength, pos));
}
if (s.Length != origLength + spanPastEnd + bytes.Length)
{
iCountErrors++;
throw new Exception(String.Format("After writing beyond end of the stream, Length is now incorrect! origLength: {0} pos: {1}", origLength, pos));
}
WritePastEndHelper(s, bytes, origLength, spanPastEnd, true);
return true;
}
示例10: TrackGcs
static void TrackGcs(Stream input)
{
int gen0 = GC.CollectionCount(0), gen1 = GC.CollectionCount(1), gen2 = GC.CollectionCount(2);
for (int i = 0; i < ITERS; i++)
{
input.Position = 0;
input.CopyToAsync(Stream.Null).Wait();
}
int newGen0 = GC.CollectionCount(0), newGen1 = GC.CollectionCount(1), newGen2 = GC.CollectionCount(2);
Console.WriteLine("{0}\tGen0:{1} Gen1:{2} Gen2:{3}", input.GetType().Name, newGen0 - gen0, newGen1 - gen1, newGen2 - gen2);
}
示例11: Decode
/// <summary>
/// Codes the data from the input chunk into the output chunk.
/// </summary>
/// <param name="input">Input stream (encoded data).</param><param name="output">Output stream (decoded data).</param><param name="args">Variable number of extra arguments.</param>
/// <returns>
/// An object that holds data specific to the media format which this codec deal with.
/// For example, an image codec might return a structure that has image related details,
/// such as height, width, etc.
/// </returns>
public override object Decode( Stream input, Stream output, params object[] args )
{
byte[] data = new byte[ input.Length ];
input.Read( data, 0, (int)input.Length );
output.Write( data, 0, (int)input.Length );
if ( input.GetType() == typeof( XnaImageCodecStream ) )
{
return ( (XnaImageCodecStream)input ).ImageData;
}
return null;
}
示例12: Decode
public override Codec.DecodeResult Decode( Stream input )
{
var data = new byte[ input.Length ];
input.Read( data, 0, (int)input.Length );
var output = new MemoryStream();
output.Write( data, 0, (int)input.Length );
if ( input.GetType() == typeof( XnaImageCodecStream ) )
return new Codec.DecodeResult( output, ( (XnaImageCodecStream)input ).ImageData );
return null;
}
示例13: setInputStream
public void setInputStream(Stream ins)
{
//ConsoleStream low buffer patch
if (ins != null)
{
if (ins.GetType() == Type.GetType("System.IO.__ConsoleStream"))
ins = new Streams.ProtectedConsoleStream(ins);
else if (ins.GetType() == Type.GetType("System.IO.FileStream"))
ins = new Streams.ProtectedConsoleStream(ins);
m_ins = new JStream(ins);
}
else
m_ins = null;
}
示例14: StreamFramer
private NetworkStream m_NetworkStream; //optimizing writes
public StreamFramer(Stream Transport) {
if (Transport == null || Transport == Stream.Null) {
throw new ArgumentNullException("Transport");
}
m_Transport = Transport;
if(m_Transport.GetType() == typeof(NetworkStream)){
m_NetworkStream = Transport as NetworkStream;
}
m_ReadHeaderBuffer = new byte[m_CurReadHeader.Size];
m_WriteHeaderBuffer = new byte[m_WriteHeader.Size];
m_ReadFrameCallback = new AsyncCallback(ReadFrameCallback);
m_BeginWriteCallback = new AsyncCallback(BeginWriteCallback);
}
示例15: ByteTest
public static void ByteTest(Stream s)
{
Console.WriteLine(" (01) ByteTest on "+s.GetType( ).Name);
int size = 0x25000;
int r;
for(int i=0;i<size;i++) s.WriteByte((byte)i);
s.Position=0;
for(int i=0;i<size;i++)
{
r=s.ReadByte( );
if(r!=i%256)
throw new Exception("Didn't get the correct value for i at: "
+i+" expected: "+(i%256)+" got: "+r);
}
}