buffering

Perl: avoid greedy reading from stdin?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 12:22:46
问题 Consider the following perl script ( read.pl ): my $line = <STDIN>; print "Perl read: $line"; print "And here's what cat gets: ", `cat -`; If this script is executed from the command line, it will get the first line of input, while cat gets everything else until the end of input ( ^D is pressed). However, things are different when the input is piped from another process or read from a file: $ echo "foo\nbar" | ./read.pl Perl read: foo And here's what cat gets: Perl seems to greadily buffer

Java-Sockets: InputStream.read() vs BufferedReader.read()

人走茶凉 提交于 2019-12-23 11:59:13
问题 I'm reading from a Socket's InputStream. Because I'm parsing the incoming data on the fly, I'm required to read character by character. Does BufferedReader.read() the same thing as InputStream.read() does ? (assuming that BufferedReader has been constructed with the InputStream as base) Is it more efficient to use InputStream.read() when reading each character separately? Or is there any better way? 回答1: BufferedReader will read multiple characters from an underlying Reader. An InputStream is

unbuffered urllib2.urlopen

烂漫一生 提交于 2019-12-23 02:32:32
问题 I have client for web interface to long running process. I'd like to have output from that process to be displayed as it comes. Works great with urllib.urlopen() , but it doesn't have timeout parameter. On the other hand with urllib2.urlopen() the output is buffered. Is there a easy way to disable that buffer? 回答1: A quick hack that has occurred to me is to use urllib.urlopen() with threading.Timer() to emulate timeout. But that's only quick and dirty hack. 回答2: urllib2 is buffered when you

How can we play/buffer only few minutes of a video in Android?

Deadly 提交于 2019-12-22 12:08:28
问题 I need to play first 2 mins of a video. Using onBufferingUpdate() i get the percentage that is buffered. But by the time onPrepared is called i get buffered % as 40. Which is more than 2 mins of a video. (Considering i have a video of 30 mins) Is there any way i can play/buffer video for only 2 mins ? Thanks. 回答1: The buffer size is pre-set into the firmware. All you can do is keep tabs on how much the buffer is filled, and even that is just on a percentage basis. The size is set in

Does ob_start affect performance of files stored on CDN?

こ雲淡風輕ζ 提交于 2019-12-22 05:53:30
问题 I use object buffering to buffer the output of my php pages using ob_start('ob_gzhandler'); . Does this affect the performance of the files stored in CDN? The reason for asking this question is because, one of the site indicated the following about "Output buffering is a simple way to greatly improve the performance and speed of your PHP script. Without output buffering, your script will show the HTML on the page as it’s processed – in pieces. Adding output buffering allows the PHP to store

PHP: <<< vs ob_start

醉酒当歌 提交于 2019-12-22 04:44:08
问题 In PHP sometimes I see this: $html = <<<HTML <p>Hello world</p> HTML; Normally I would have used ob_start() : ob_start(); ?> <p>Hello world</p> <?php $html = ob_get_contents(); ob_clean(); Can you tell me what the difference between these two ways to write to the buffer and their advantages? 回答1: HEREDOC ( <<< ) is just another way to write a string data into a variable. The output buffer, on the other hand, will catch all output that takes place after ob_start() including (HTML) output of

read huge text file line by line in C++ with buffering

蹲街弑〆低调 提交于 2019-12-22 03:41:39
问题 I need to read huge 35G file from disc line by line in C++. Currently I do it the following way: ifstream infile("myfile.txt"); string line; while (true) { if (!getline(infile, line)) break; long linepos = infile.tellg(); process(line,linepos); } But it gives me about 2MB/sec performance, though file manager copies the file with 100Mb/s speed. I guess that getline() is not doing buffering correctly. Please propose some sort of buffered line-by-line reading approach. UPD: process() is not a

stdbuf with setuid/capabilities

喜你入骨 提交于 2019-12-21 20:38:31
问题 I am reading output from another process which generates output (slow and infinite). Because I want to read this data in real-time I use "stdbuf -oL" (line-buffered, data is text). I do not have control of the generating process so I cannot modify the source to force flushing. So far stdbuf works just fine, however the process uses SOCK_RAW and needs either to be run as root, have setuid(0) or the cap_net_raw capability. When running as non-root with setuid or capabilities stdbuf seems to be

Detect when video is buffering, if so display gif

谁说我不能喝 提交于 2019-12-20 14:44:21
问题 I'am wondering if there's a way to display a .gif while the video is buffering. I'am using the HTML5 Video Tag, within this is there a way to detect when a video is buffering, if not is there an alternative? I've looked at: How to detect when video is buffering? However I don't think this would help me out.. as I have no clue what NetStream is or what actionscript-3 is. html: <div id="popup-box" class="popupInfo"> <img src="button/loading.gif" id="loadingGif" /> <video src="fragmenten/real

How to stream a media file using PHP?

允我心安 提交于 2019-12-20 10:46:58
问题 I am trying to build an application in which i have to stream the media files (audio and video) to the browser. I am reading the file through php and send the data to browser. I am using the following code. header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("Content-Type: {$file->getMimetype()}"); header("Content-Disposition: inline; filename=".$filename.";"); header("Content-Length: ".strlen($file