Which i/o approach is better and why?

can someone please explain which i/o approach is better for obtain the data from the InputStream and why? and consequences for reading streams that contain 2-byte characters?
thank you.
InputStream in = conn.openInputStream();
approach 1
byte[] byteData = new byte[(int)conn.getLength()];
in.read(byteData);
String rawdata = new String(byteData);
approach 2
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buf = new byte[128];
int t;
while( (t=in.read(buf)) != -1) {
baos.write(buf,0,t);
String rawdata = new String(baos.toByteArray());

First way will be best in terms of performance: you do all the reading procedure in one sentence, avoiding the chequing of the loop condition check and invoking less times the method read, and you too sabe the memory space required for the object baos you employ in the second approach.
In performance terms I would say second option saves CPU and memory, so it's better.
Abraham.

Similar Messages

  • Which is better and why: Safari or Firefox?

    Which is better and why: Safari or Firefox?

    Thx, I've been using FF on my MacBook, as I did with PowerMacs before that. I used to work in the industry and stay up on current trends; but, I'm just a regular user with a new MacAir now and hate to bother my SF/SJ peeps with trivial questions.
    As I start to load up the Air, I'm just a bit overwhelmed with the volume of bookmarks I've collected and organzied in FF on my MB.

  • Which is better and why a = new String("AA") or a = "AA"

    Hi,
    Which is better and why
    String a = new String("AA") or
    String a = "AA"
    Does invoking a construtor waste memory? Please explain in detail.
    Thanks in advance
    Deepak

    > So in case "AA" not there in string pool,
    That is not correct.
    does new creates "AA" on string pool as well as heap memory?Yes. The literal "AA" points to a pooled String object. The new operator creates a new String object with the same character sequence ("AA"). You can verify this with a little code...
    String s = new String("AA");
    assert s != "AA";
    assert s.equals("AA");
    assert s.intern() == "AA";~

  • SAP BW or BO ? Which is better and why

    Hi,
    I dont know much about SAP BW so I am not able to compare which one is better.
    It would be great if someone could help me comparing these tools.
    Which one is better and why ?
    If a user is already using SAP BW and planning to start using SAP BO what could be the features he would go for ?
    I am thinking from the sales perspective for Business Objects to a BW user.
    Regards,
    Chinmay

    Hi,
    Someone might be able to provide you with the comparitive chart or a tabular format to make you understand the differences but I would say that SAP itself has designed the roadmap for the product integration wherever it suited the needs.
    I would like you go through the roadmap of SAP BI and BO integration and you would be able to yourself compare what is in and what is out and why.
    Please give the below link a look:-
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/b00a1a75-c49d-2b10-0ebb-ecc80ab88994
    Happy reading.
    Please let us know if you need any further explanation to this.
    Cheers.

  • If i have two option to select between XI or BW which one in better and why

    if i have two option to select between XI or BW which one in better and why
    both in terms of money and in terms of my career growth.......

    Sheetika,
    XI if you  are good in JAVA.The rest is same for both XI and BW.
    K.Kiran.

  • Which email service would you recommend and why? Google's or BC's?

    Which email service would you recommend and why? Google's or BC's?

    Easy Answer. Google. Hands down Google is better. BC has had issues in the past and while I think the issue is a little bit better I would choose Google. Do remember that Google Apps is $50 (USD) per year per user.
    I have used Google Apps since they were still offering 50 free users and has worked great ever since. If there have been downtimes I have not noticed or has been so slight that is hasn't effected me in anyway. This is not the case with BC.
    I am not trying to knock BC mail but it isn't the best.

  • In BDC, I Have 10,000 Records Which Method do I Select? and Why?

    Hi all,
    In BDC , I Have 10,000 Records of Material Master Application. I have go through by Session Method or Call Transaction Method. Which Method do I Select? and Why?

    Hi..
    There you hav to go for sessions method....
    because...
    1. session methos has auto matic error handling option. so if there is any error in last but 100 th reocrd it will just threws that record and remaining part willl complete.
    2. And it was offline method.. means formatting of the data and assigning to Sap lay can be done in two steps... So you  10000 recors can update in expected time comaper with Calltransaction method...
    Get back to me if you are not satisfy with above reasons.
    Thanks,
    Naveen.I

  • In and EXISTS??which is better and why

    hi...
    Performance wise which is better IN or EXISTS and why..

    user8469486 wrote:
    hi...
    Performance wise which is better IN or EXISTS and why..DomBrooks pointed out that it may not matter due to query optimization rewrites.
    In theory it depends on circumstances.
    Correlated EXISTS subqueries tend to be efficient if the lookup is properly indexed. If the list of values is very small (especially if you only get one value) an IN subquery might be more efficient.

  • DECODE OR CASE - Which is better and why

    Oracle version: 11.2
    Problem: We have a huge table with 10M records, which needs to be processed daily.
    While loading data in table we have to handle condition if flag is =1 then '111' else '000'
    To implement this which one is efficient solution? .. using CASE or DECODE and why?
    Example:
    SQL> select flag,case when flag='Y' then '111' else '000' end from (select 'Y' as flag from dual union all select 'N' from dual);
    F CAS
    Y 111
    N 000
    SQL> select flag,decode(flag,'Y','111','000') from (select 'Y' as flag from dual union all select 'N' from dual);
    F DEC
    Y 111
    N 000

    Hi,
    For this job, they're equally efficient.
    For any job, where DECODE doesn't require a lot more code than CASE, they will be equally efficient.
    I recommend (almost) always using CASE. It's easier to understand and debug, and, if written correctly, will never be slower than DECODE.
    The only situation where I use DECODE is for very simple tasks (like the one you posted) where this is used inside a very complicated expression, and the slightly less coding needed for DECODE makes the larger statement easier to read.

  • LSMW: Idoc or BAPI; which one is better and why ?

    Hi All,
    In LSMW, given the choices between Idoc and BAPI,which processing method is good and why?
    Please do reply asap. Its urgent.
    Best regards.
    Ram

    The preferece of Import Techniques are:
    1)Batch Input
    2)Direct Input
    3)BAPI's
    4)IDOCS's
    5)Recording
    6)Custom Program
    <b>
    Refer these Links:</b>
    Re: LSMW with Recording or LSMW with BAPI?????
    Regards,
    AS

  • Question: Which is better and why....RMAN catalog or Flashback Recovery

    Hey All,
    Newly testing and reading up on 10g. I am on information overload and would appreciate pro's advice on which to choose and why.
    Thanks,
    d.

    Different things, not necessarily alternative. That is, RMAN catalog is normally (at least should be) on another machine, and does not contain physical backups, but only information about them : physical backups are normally stored on external devices, like tapes.
    Flashback Recovery technique is based on Flashback logs in Flash Recovery Area, which is a disk area on local machine, and so cannot be unlimited.
    Therefore, Flashback Recovery is much faster than Media Recovery, since you don't need to restore anything, but you have limits in using that : your disks size.
    On the other hand, RMAN backups are safer, being physically elsewhere.
    See http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14220/backrec.htm#g1023042

  • Hey, I want to buy a macbook pro or imac mini, I want to know which is better and why, is their going to be new macbooks ect released in 2-3 months thats better that i should rather wait for? Or buy one now ?

    Please help me i dont know which one to buy, and ive never owned one before but i have used my friends quite alot. Why is macbook's worth buying if you can get many products for the same price with better specs ?What makes it unique that it dominates basically the whole world.

    Hey,
    Thank's 4 the advice , but one of my main problems is I live in South Africa and apple products is x2 as much as what the usa doller is for it. Eg Macbook pro starting price $1199 american dollars and directley converted to South African currency is R9160.30.... but the problem is if i want to buy it in my country it has been marked up alot and a Macbook pro starting price for me will be R13000 for 13 inch and if you directley convert our price into american dollers its $1704.30 american dollars, so thats +600 dollers more.
    So its much more expensive to buy products in my country and thats just the starting price.
    I want mobality but i was also thinking (imac mini) is kinda portable and can plug into any1  T.V u know.
    So like i really do t know what to get and that, because its alot more money to spend than the US dollar.
    So i really want you to put your self in my position you know...
    And what is classified as a good monitor???
    And i want to know why my friends say that the imac mini is pathetic , but i think it losts longer than most windows laptops, what do you think ??
    And can i who lives in south africa buy products directley from apple them selves ??
    Thank's man , hope you can help me out here!
    Hope other people can c this 2
    Brent

  • Which Is Better, and Why?

    I still have some questions about iCloud. I'm not entirely sure why this is an improvment over MobileMe. I used to be able to upload and share any type of file. Now I can't. Why should I be excited about iCloud?

    among other features, icloud is most improved in that it has pushing services that push changes on one device to another device you may have. if you start a book on one device, continue from where you left off on another. buy a song on your ipod, it's waiting for you on your ipad. same with apps downloaded, photos taken, and certain game scores. and for those of us (like myself) who only have one idevice, it backs up all these things on both the computer you sync it with and in the cloud for free (or, 5gbs of it anyway).
    while icloud is replacing mobileme, it's a new service with many new features and uses. that being said, due to the high volume of usage, i'm sure you've heard complaints of icloud not being so "seamless." while this is not the case for me (knock on wood) thus far, it is for many others so i see where you're coming from when you say you're not excited about it. that being said, like pvonk said, you have until mid 2012 to continue to enjoy mobileme, and by that time i would be shocked if icloud wasn't working seamlessly as an easy replacement and quick adjustment from mobileme.
    i'm sorry for your frustration, and i hope this helps
    cheers,
    zach

  • What is different between asp and jsp, which is better and why

    hi, i would like to know which script language is better (ASP or JSP). if you can give me a detail comparison. Thank in advance
    zhe

    What do you expect small-time loser?

  • Which MacBook Pro is better and why?

    I'm planning on downsizing to a 15". I've got the 17" and love it, but my new company insists I use a PC so, because I'm addicted, I'll be traveling with two - a PC and a MBP.
    So which to get, the 2.0 mhz or the 2.16? Is there really that big a difference in the computing power?
    Likewise, what is the difference between the video memory being 256mb and 128? My main use will be to run graphics apps (Photoshop, Lightroom).
    Thanks in advance for any advice. Oh by the way I'll have the full 2GB of ram, of course...

    My understanding is that all mac book pros come with the 256MB video memory...
    I've had a 2.0ghz since February and it came standard with 256.
    Honestly, if you're getting a 2.0 with 2GB ram, I dont' think you'll notice much difference between the 0.16 the latter will offer you.
    I guess mine has 256 because in Feb 06 the 2.0 was the "2nd tier" MBP, and the 1.83 was 128MB video.
    Oh wow, I'm mistaken... It seems that the current 2.0 DOES have 128MB video...
    I think you should get the 2.16. Based on current rumors you may want to wait until the 25th... I don't think anything will happen, but I still think the hype may be worth the wait.

Maybe you are looking for

  • Unable to connect to Server  Error in Essbase 11.1.2

    Hi, We are working on Essbase 11.1.2.2. Our applications are in Production and suddenly the  some of the BSO Application are down. We tried to re start the applications but not restarted. So  we restarted the Essbase Hyperion Services in the Server. 

  • IPhone 6 plus screen cracked. Please advise best course of action.

    Hi all, hope someone can help. My son has a iPhone plus and has just cracked the screen. He is very careful with all his devices and has never broken any thing like this before hes very careful. But what I'm asking is what is the best way to get this

  • Airport Utility doens't see aiport express after reconfiguring

    I have my airport express connected through bridge mode to a 2Wire 2701 HG-B modem. I just bought this Airport Express and whenever I try to modify settings, Airport Utility can't see it after the restart, even though I'm still connected through wifi

  • USB Superdrive will not burn my cd

    I have a macbook pro Retina display and the USB Superdrive.  For some reason the superdrive will not burn cd's. Help please...US

  • Linking files on my iDisk

    Hi, I need to create a simple page with links to some files residing on my iDisk. How do i do that? There are templates with video, photos and podcasts, but no templates to include links to music files. How can I solve that? Thank you.