当前位置: 首页>>代码示例>>C#>>正文


C# BufferedStream类代码示例

本文整理汇总了C#中BufferedStream的典型用法代码示例。如果您正苦于以下问题:C# BufferedStream类的具体用法?C# BufferedStream怎么用?C# BufferedStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BufferedStream类属于命名空间,在下文中一共展示了BufferedStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Example_19

    public Example_19()
    {
        try {

            FileStream fos = new FileStream("Example_19.pdf", FileMode.Create);
            BufferedStream bos = new BufferedStream(fos);

            PDF pdf = new PDF( bos );

            FileStream fis = new FileStream( "Example_03.pdf", FileMode.Open );

            // FileInputStream fis = new FileInputStream( "PDF32000_2008.pdf" );

            BufferedStream bis = new BufferedStream( fis );
            List< PDFobj > objects = pdf.read(bis);
            for ( int j = 0; j < objects.Count; j++ ) {
                PDFobj obj = ( PDFobj ) objects[j];
                for ( int i = 0; i < obj.dict.Count; i++ ) {
                    Console.WriteLine(obj.dict[i]);
                }
                Console.WriteLine();
            }
            bis.Close();

            pdf.Flush();
            bos.Close();
        }
        catch ( Exception e ) {
            Console.WriteLine(e.StackTrace);
        }
    }
开发者ID:pauljs,项目名称:Justin-Paul-s-Projects,代码行数:31,代码来源:Example_19.cs

示例2: ShouldNotFlushUnderlyingStreamIfReadOnly

        public async Task ShouldNotFlushUnderlyingStreamIfReadOnly(bool underlyingCanSeek)
        {
            var underlying = new DelegateStream(
                canReadFunc: () => true,
                canWriteFunc: () => false,
                canSeekFunc: () => underlyingCanSeek,
                readFunc: (_, __, ___) => 123,
                writeFunc: (_, __, ___) =>
                {
                    throw new NotSupportedException();
                },
                seekFunc: (_, __) => 123L
            );

            var wrapper = new CallTrackingStream(underlying);

            var buffered = new BufferedStream(wrapper);
            buffered.ReadByte();

            buffered.Flush();
            Assert.Equal(0, wrapper.TimesCalled(nameof(wrapper.Flush)));

            await buffered.FlushAsync();
            Assert.Equal(0, wrapper.TimesCalled(nameof(wrapper.FlushAsync)));
        }
开发者ID:chcosta,项目名称:corefx,代码行数:25,代码来源:BufferedStream.FlushTests.cs

示例3: SetPositionToNegativeValue_Throws_ArgumentOutOfRangeException

 public static void SetPositionToNegativeValue_Throws_ArgumentOutOfRangeException()
 {
     using (BufferedStream stream = new BufferedStream(new MemoryStream()))
     {
         Assert.Throws<ArgumentOutOfRangeException>(() => stream.Position = -1);
     }
 }
开发者ID:geoffkizer,项目名称:corefx,代码行数:7,代码来源:BufferedStream.InvalidParameters.cs

示例4: Main

    public static void Main()
    {
        var bs = new BufferedStream(Console.OpenStandardInput());
        StreamReader reader = new StreamReader(bs);
        Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

        string[] ss = reader.ReadLine().Split();
        double t = double.Parse(ss[0]);

        List<int> w = reader.ReadLine().Split().Select(x => int.Parse(x)).OrderBy(x => x).ToList();
        int res = max_cuts + 47, left = int.Parse(ss[1]);
        foreach (int q in w)
        {
            for (int i = 1; i <= max_cuts; i++)
            {
                double big = q / (double)i;
                var cut = w.Select(x => new {Count = Math.Ceiling(x / big), Length = x});
                if (cut.Min(y => y.Length / y.Count) >= t * big)
                {
                    double cnt = cut.Sum(y => y.Count - 1);
                    if (cnt < res) res = (int)cnt;
                }
            }
            left--;
        }
        Console.WriteLine(res);
    }
开发者ID:Bophin,项目名称:ncpc_practice,代码行数:27,代码来源:vegetables_lukas.cs

示例5: writeFile

    /**
       	 * Writes a file from the contents of a String
       	 * @param filename The name of the file.
       	 * @return The String to write to the file.
       	 */
    public static void writeFile(string filename, string contents)
    {
        FileStream fs = null;
        BufferedStream bs = null;
        StreamWriter sw = null;

        try
        {
            fs = new FileStream(filename, FileMode.Open);

            // Here BufferedInputStream is added for fast writing.
            bs = new BufferedStream(fs);
            sw = new StreamWriter(bs);
            sw.Write(contents);

            // dispose all the resources after using them.
            fs.Close();
            bs.Close();
            sw.Close();
        }

        catch (FileNotFoundException e)
        {
            System.Console.WriteLine(e.ToString());
        }

        catch (IOException e)
        {
            System.Console.WriteLine(e.ToString());
        }
    }
开发者ID:sylvainhalle,项目名称:BeepBeepCSharp,代码行数:36,代码来源:SimpleFileWriter.cs

示例6: Main

 static void Main(string[] args)
 {
     using (FileStream fs = new FileStream(input, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
     {
         using (BufferedStream bs = new BufferedStream(fs))
         {
             using (StreamReader _in = new StreamReader(bs))
             {
                 using (StreamWriter _out = new StreamWriter(output))
                 {
                     string line;
                     while ((line = _in.ReadLine()) != null)
                     {
                         if (wholeWordOnly)
                         {
                             _out.WriteLine(Regex.Replace(line, @"\bstart\b", "finish"));
                         }
                         else
                         {
                             _out.WriteLine(line.Replace("start", "finish"));
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:VyaraGGeorgieva,项目名称:TelerikAcademy,代码行数:27,代码来源:Program.cs

示例7: invokeGetRequest

 protected string invokeGetRequest(string requestUrl, string contentType)
 {
     string completeUrl = requestUrl;
     string responseString;
     try
     {
         HttpWebRequest request1 = WebRequest.Create(completeUrl) as HttpWebRequest;
         request1.ContentType = contentType;
         request1.Method = @"GET";
         HttpWebResponse httpWebResponse = (HttpWebResponse)request1.GetResponse();
         using (BufferedStream buffer = new BufferedStream(httpWebResponse.GetResponseStream()))
         {
             using (StreamReader reader = new StreamReader(buffer))
             {
                 responseString = reader.ReadToEnd();
             }
         }
         //StreamReader reader = new StreamReader(httpWebResponse.GetResponseStream());
         //string responseString = reader.ReadToEnd();
         return responseString;
     }
     catch (WebException ex)
     {
         //reading the custom messages sent by the server
         using (var reader = new StreamReader(ex.Response.GetResponseStream()))
         {
             return reader.ReadToEnd();
         }
     }
     catch (Exception ex)
     {
         return "Failed with exception message:" + ex.Message;
     }
 }
开发者ID:srisai339,项目名称:LoveJourney_Working,代码行数:34,代码来源:Default.aspx.cs

示例8: TestBuffering

        public void TestBuffering(long length, int internalBufferCount, int clientBufferCount)
        {
            var random = new Random();
            var remoteData = new byte[length];
            random.NextBytes(remoteData);
            var buffer = new byte[clientBufferCount];
            var clientData = new List<byte>();
            Func<long, byte[], int> reader = (remoteOffset, buff) =>
            {
                int toRead = Math.Min(buff.Length, (int)(length - remoteOffset));
                Buffer.BlockCopy(remoteData, (int) remoteOffset, buff, 0, toRead);
                return  toRead;
            };
            var bufferedStream = new BufferedStream(length, reader, internalBufferCount);
            while (true)
            {
                int read = bufferedStream.Read(buffer, 0, buffer.Length);
                clientData.AddRange(buffer.Take(read));
                if(read==0)
                    break;
                
            }

            Assert.Equal(remoteData, clientData);
        }
开发者ID:FeodorFitsner,项目名称:BeeHive,代码行数:25,代码来源:BufferedStreamTests.cs

示例9: ShouldAlwaysFlushUnderlyingStreamIfWritable

        public async Task ShouldAlwaysFlushUnderlyingStreamIfWritable(bool underlyingCanRead, bool underlyingCanSeek)
        {
            var underlying = new DelegateStream(
                canReadFunc: () => underlyingCanRead,
                canWriteFunc: () => true,
                canSeekFunc: () => underlyingCanSeek,
                readFunc: (_, __, ___) => 123,
                writeFunc: (_, __, ___) => { },
                seekFunc: (_, __) => 123L
            );

            var wrapper = new CallTrackingStream(underlying);

            var buffered = new BufferedStream(wrapper);
            
            buffered.Flush();
            Assert.Equal(1, wrapper.TimesCalled(nameof(wrapper.Flush)));

            await buffered.FlushAsync();
            Assert.Equal(1, wrapper.TimesCalled(nameof(wrapper.FlushAsync)));

            buffered.WriteByte(0);
            
            buffered.Flush();
            Assert.Equal(2, wrapper.TimesCalled(nameof(wrapper.Flush)));

            await buffered.FlushAsync();
            Assert.Equal(2, wrapper.TimesCalled(nameof(wrapper.FlushAsync)));
        }
开发者ID:chcosta,项目名称:corefx,代码行数:29,代码来源:BufferedStream.FlushTests.cs

示例10: runTest

	public bool runTest()
	{
		Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
		int iCountErrors = 0;
		int iCountTestcases = 0;
		String strLoc = "Loc_000oo";
		String strValue = String.Empty;
		try
		{
			BinaryWriter sr2;
		    MemoryStream ms2;
			FileStream fs2;
			BufferedStream bs2;
			String filName = s_strTFAbbrev+"Test.tmp";
			if(File.Exists(filName))
				File.Delete(filName);			
			strLoc = "Loc_98hg7";
			ms2 = new MemoryStream();
			sr2 = new BinaryWriter(ms2);
			iCountTestcases++;
			if(sr2.BaseStream != ms2) {
				iCountErrors++;
				printerr( "Error_g57hb! Incorrect basestream");
			}
			sr2.Close();
			ms2 = new MemoryStream();
			bs2 = new BufferedStream(ms2);
			sr2 = new BinaryWriter(bs2);
			iCountTestcases++;
			if(sr2.BaseStream != bs2) {
				iCountErrors++;
				printerr( "Error_988hu! Incorrect basestream");
			}
			sr2.Close();
			fs2 = new FileStream(filName, FileMode.Create);
			sr2 = new BinaryWriter(fs2);
			iCountTestcases++;
			if(sr2.BaseStream != fs2) {
				iCountErrors++;
				printerr( "Error_29g87! Incorrect baseStream");
			}
			sr2.Close();
			if(File.Exists(filName))
				File.Delete(filName);
		} catch (Exception exc_general ) {
			++iCountErrors;
			Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
		}
		if ( iCountErrors == 0 )
		{
			Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString());
			return true;
		}
		else
		{
			Console.WriteLine("FAiL! "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums );
			return false;
		}
	}
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:59,代码来源:co5738get_basestream.cs

示例11: Connect

		private void Connect()
		{
			socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
			{
				SendTimeout = SendTimeout,
				ReceiveTimeout = ReceiveTimeout
			};
			try
			{
                if (ConnectTimeout == 0)
                {
                    socket.Connect(Host, Port);
                }
                else
                {
                    var connectResult = socket.BeginConnect(Host, Port, null, null);
                    connectResult.AsyncWaitHandle.WaitOne(ConnectTimeout, true);
                }

				if (!socket.Connected)
				{
					socket.Close();
					socket = null;
					return;
				}
				Bstream = new BufferedStream(new NetworkStream(socket), 16 * 1024);

				if (Password != null)
					SendExpectSuccess(Commands.Auth, Password.ToUtf8Bytes());

				db = 0;
				var ipEndpoint = socket.LocalEndPoint as IPEndPoint;
				clientPort = ipEndpoint != null ? ipEndpoint.Port : -1;
				lastCommand = null;
				lastSocketException = null;
				LastConnectedAtTimestamp = Stopwatch.GetTimestamp();

				if (isPreVersion1_26 == null)
				{
					isPreVersion1_26 = this.ServerVersion.CompareTo("1.2.6") <= 0;
				}

                if (ConnectionFilter != null)
                {
                    ConnectionFilter(this);
                }
			}
			catch (SocketException ex)
			{
                if (socket != null)
                    socket.Close();
                socket = null;

				HadExceptions = true;
				var throwEx = new RedisException("could not connect to redis Instance at " + Host + ":" + Port, ex);
				log.Error(throwEx.Message, ex);
				throw throwEx;
			}
		}
开发者ID:cbarbara,项目名称:ServiceStack.Redis,代码行数:59,代码来源:RedisNativeClient_Utils.cs

示例12: StreamThroughWaveFile

 public static void StreamThroughWaveFile(string sFileName,IReadWaveData objCallback)
 {
     using (FileStream fs = new FileStream(sFileName,FileMode.Open,FileAccess.Read))
     using (BufferedStream bs = new BufferedStream(fs, nBufferSize))
     using (BinaryReader r = new BinaryReader(bs))
     {
         StreamThroughWaveFile(r, objCallback);
     }
 }
开发者ID:kleopatra999,项目名称:downpoured_midi_audio,代码行数:9,代码来源:WavStreams.cs

示例13: StartWavAnalyze

 private static void StartWavAnalyze(string strFileName,long nLength)
 {
     using (FileStream fs = new FileStream(strFileName,FileMode.Open,FileAccess.Read))
     using (BufferedStream bs = new BufferedStream(fs,nBufferSize))
     using (BinaryReader r = new BinaryReader(bs))
     {
         StartWavAnalyze(r,nLength);
     }
 }
开发者ID:kleopatra999,项目名称:downpoured_midi_audio,代码行数:9,代码来源:WavAnalyze.cs

示例14: Example_01

    public Example_01()
    {
        FileStream fos = new FileStream("Example_01.pdf", FileMode.Create);
        BufferedStream bos = new BufferedStream(fos);

        PDF pdf = new PDF(bos);
        pdf.setCompressor(Compressor.ORIGINAL_ZLIB);

        Page page = new Page(pdf, Letter.PORTRAIT);

        Box flag = new Box();
        flag.SetPosition(100.0, 100.0);
        flag.SetSize(190.0, 100.0);
        flag.SetColor(RGB.WHITE);
        flag.DrawOn(page);

        double sw = 7.69;   // stripe width
        Line stripe = new Line(0.0, sw/2, 190.0, sw/2);
        stripe.SetWidth(sw);
        stripe.SetColor(RGB.OLD_GLORY_RED);
        for (int row = 0; row < 7; row++) {
            stripe.PlaceIn(flag, 0.0, row * 2 * sw);
            stripe.DrawOn(page);
        }

        Box union = new Box();
        union.SetSize(76.0, 53.85);
        union.SetColor(RGB.OLD_GLORY_BLUE);
        union.SetFillShape(true);
        union.PlaceIn(flag, 0.0, 0.0);
        union.DrawOn(page);

        double h_si = 12.6; // horizontal star interval
        double v_si = 10.8; // vertical star interval
        Point star = new Point(h_si/2, v_si/2);
        star.SetShape(Point.STAR);
        star.SetRadius(3.0);
        star.SetColor(RGB.WHITE);
        star.SetFillShape(true);

        for (int row = 0; row < 6; row++) {
            for (int col = 0; col < 5; col++) {
                star.PlaceIn(union, row * h_si, col * v_si);
                star.DrawOn(page);
            }
        }
        star.SetPosition(h_si, v_si);
        for (int row = 0; row < 5; row++) {
            for (int col = 0; col < 4; col++) {
                star.PlaceIn(union, row * h_si, col * v_si);
                star.DrawOn(page);
            }
        }

        pdf.Flush();
        bos.Close();
    }
开发者ID:pauljs,项目名称:Justin-Paul-s-Projects,代码行数:57,代码来源:Example_01.cs

示例15: Example_04

    public Example_04()
    {
        String fileName = "data/happy-new-year.txt";

        FileStream fos = new FileStream("Example_04.pdf", FileMode.Create);
        BufferedStream bos = new BufferedStream(fos);

        PDF pdf = new PDF(bos);
        pdf.setCompressor(Compressor.ORIGINAL_ZLIB);

        Font f1 = new Font(
                pdf,
                "AdobeMingStd-Light",       // Chinese (Traditional) font
                CodePage.UNICODE);
        Font f2 = new Font(
                pdf,
                "AdobeSongStd-Light",       // Chinese (Simplified) font
                CodePage.UNICODE);
        Font f3 = new Font(
                pdf,
                "KozMinProVI-Regular",      // Japanese font
                CodePage.UNICODE);
        Font f4 = new Font(
                pdf,
                "AdobeMyungjoStd-Medium",   // Korean font
                CodePage.UNICODE);

        Page page = new Page(pdf, Letter.PORTRAIT);

        f1.SetSize(14);
        f2.SetSize(14);
        f3.SetSize(14);
        f4.SetSize(14);

        double x_pos = 100.0;
        double y_pos = 20.0;
        StreamReader reader = new StreamReader(
                new FileStream(fileName, FileMode.Open));
        TextLine text = new TextLine(f1);
        String line = null;
        while ((line = reader.ReadLine()) != null) {
            if (line.IndexOf("Simplified") != -1) {
                text.SetFont(f2);
            } else if (line.IndexOf("Japanese") != -1) {
                text.SetFont(f3);
            } else if (line.IndexOf("Korean") != -1) {
                text.SetFont(f4);
            }
            text.SetText(line);
            text.SetPosition(x_pos, y_pos += 24);
            text.DrawOn(page);
        }
        reader.Close();

        pdf.Flush();
        bos.Close();
    }
开发者ID:pauljs,项目名称:Justin-Paul-s-Projects,代码行数:57,代码来源:Example_04.cs


注:本文中的BufferedStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。