Posts

java - Stream file from URL to File without storing it in the memory -

i want download file url , store file system. have memory limitation , don't want store in memory before. not java expert , bit lost class inputstream, bufferedreader, fileoutputstream, etc. me please ? for have: urlconnection ucon = url.openconnection(); ucon.connect(); inputstream = ucon.getinputstream(); // create reader input stream. bufferedreader br = new bufferedreader(isr); // ? fileoutputstream fos = context.openfileoutput(filename, context.mode_private); // here content can big memory... fos.write(content.getbytes()); fos.close(); please, give me clue ? thinking read chunk chunk, not sure easiest java... you can use apache commons org.apache.commons.io.fileutils.copyurltofile(url, file) i guess may not work on android use code inputstream input = connection.getinputstream(); byte[] buffer = new byte[4096]; int cnt = - 1; outputstream output = new fileoutputstream(file); while ( (cnt = input.read(buffer)) != -1) { output.write(buffer, 0, cnt);...

objective c - iOS: Don't return from function until multiple background threads complete -

this seems should simple i'm having lot of trouble. have function fires off bunch of other functions run in background , have completion blocks. want function wait until of completion blocks have been called before returns. i not have control of function calling executes in background. otherwise modify use dispatch_async own queue , wait on queue finish. example of situation looks like: - (void)functionthatshouldbesynchronous { (int = 0; < 10; i++) { [self dosomethinginbackground:^{ nslog(@"completed!"); }]; } // how wait until 10 threads have completed before returning? } - (void)dosomethinginbackground:(void(^)())completion { dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_background, 0), ^{ [nsthread sleepfortimeinterval:1.0f]; // stuff completion(); // execute completion block }); } thanks in advance. use dispatch group this: - (void)functionthatshouldbesynchro...

html5 - Why is my PHP/HTML Header color/border not showing in OLD IE Browsers/ And it's not the CSS -

the below header: following cookie in php <header> <div id="first"> <?php if ($visits > 1) { echo "thanks coming more laughs!!!"; } else { // first visit echo 'welcome website!'; } ?> </div> this h1, h2, images, link, , image <h1>the clean jokes , riddles website!</h1> <h2>add & search jokes or riddles</h2> <div> <img id ="funny" img src="images/funny.jpg" alt="funny"/> <img id ="dog" img src="images/pet.jpg" alt="dog"/> </div> <div id="a"> <a href="?add" >add new joke or riddle</a> <img id="bell" img src="images/bell1-c.gif" alt="bell"> </div> </header> older versions of ie not apply css rules elements don...

pug - What are the pros and cons of both Jade and EJS for Node.js templating? -

jade versus ejs, pros , cons of each , purposes each designed for? are there any other express-compatible template engines , why? i used jade before. nice thing jade have shorter syntax means can type faster. block in jade pretty powerful can me lot when dealing complex html code. on other hand, hard simple stuff in jade, thing adding classes div based on simple if condition. need put - if (isadmin) div.admin.user - else div.user jade don't differentiate between tags , variables make code confusing (at least me) a(href='/user/' + user.id)= user.name jade not designer-friendly. designer friends give me html , css (they switched less still want use html), , reason if use jade need convert html jade. in jade, need use indentations, if html structure gets complicated, code horrible (especially tables). sometimes, don't know level at table thead tr td img tr td tbody tr td recently, made ...

How to use android media player play radio streaming in asx format -

i want play streaming url: http://www.mediacorpradio.sg/radioliveplayer/asx/class95/fm950.asx what tried: public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); ... // player player = new mediaplayer(); player.setaudiostreamtype(audiomanager.stream_music); player.setonpreparedlistener(new onpreparedlistener() { public void onprepared(mediaplayer mp) { mp.start(); button.setimageresource(r.drawable.pause); } }); try { player.setdatasource(radio_url); } catch (exception e) { toast("unable play radio. please email if see constantly."); return; } player.prepareasync(); } private void togglestate(){ if (player.isplaying()) { player.pause(); button.setimageresource(r.drawable.play); }else{ player.prepareasync(); } } @override public void ondestroy() { super.ondestroy(); player.r...

javascript - Entering values into a jquery-select2 that are not in the select list -

i have use case allow people type values text box of select2 plugin not appear in select list. in 1 case providing validation , not submit unless user has valid item selected until do not want clear values. select box might contain 1.00, 1.50, 1.75, na, abs , user has typed 1.80. invalid value don't want lose changes, flag box invalid , allow them fix changes. not want add 1.80 select box invalid value, don't want clear either. how possible achieve this? if you're validating in js, select2 has example dynamic loading/generating data overrides query() repeats user's input. see: http://ivaynberg.github.io/select2/ 'loading data' i solved similar problem (server-side) jquery ui 'autocomplete'. here, took approach of returning objects wrapping both label possible explanatory message, text value without decoration, , combined id value & status flag . overrode select store text & id hidden fields. in case, distinguishing b...

keyboard - How to catch global keyPress events in Ember -

i'm sure i'm missing obvious, but: how respond keypress event anywhere on page? for example, had video player , wanted pause if user pressed spacebar @ point. or, i'm writing game , want arrow keys direct character, without regard specific views or subviews. defining app.applicationview = ember.view.create({ keypress: whatever }) doesn't seem work. have thought keypress events bubble that. i guess want is: $(document).keypress(function(e) { alert('you pressed key!'); }); except through ember. if looking global keypress code example above best solution. ember application attached body (or root element you've defined) , require sort of focus on view. example do: app.applicationview = em.view.extend({ keyup: function(){ alert(1); } }); this work, application view or child need have focus. useful, example, if wanted capture key event of input fields.