Any improvements?

Just being picky, but I don't like the way I had to code this (required too much casting and rounding). Any ideas how I could have done it better?
            FileInputStream fileReader = new FileInputStream(file);
            byte buffer[] = new byte[bufferSize];
            for (int i = 0; i < (file.length() / bufferSize); i++) {
                fileReader.read(buffer);
            byte lastBuffer[] = new byte[(int)file.length() - ((int)(file.length() / bufferSize) * bufferSize)];
            fileReader.read(lastBuffer);The code splits the file into bytes, which are read into a byte array of BufferSize, until there isn't enough bytes to fill a byte array of BufferSize, and then it writes the remaining bytes into a perfectly-sized byte array because I don't want the fileReader.read(buffer) to block.
Thanks in advance.
Message was edited by:
abu5e

Why don't you use the returned int from the method read(byte[] buffer) ?
byte[] buffer = new byte[BUFFER];
int n = 0;
while((n = in.read(buffer)) != -1) {
//TODO (save it on another file or send it through sockets... or whatever)
}Maybe I don't understand what you're trying to achieve.. but if it is a simple lecture from a File, this is the best way of doing it...
Message was edited by:
Ruly-o_O

Similar Messages

  • So I recently upgraded my ram to 8GB but so far I haven't seen any improvement. I ran some tests and everything turned out fine with the ram. What should i do?

    So I recently upgraded my ram to 8GB but so far I haven't seen any improvement. I ran some tests and everything turned out fine with the ram. What should i do?

    What is the problem exactly???
    See if the Disk is issuing any S.M.A.R.T errors in Disk Utility...
    http://support.apple.com/kb/PH7029
    Open Activity Monitor in Applications>Utilities, select All Processes & sort on CPU%, any indications there?
    How much RAM & free space do you have also, click on the Memory & Disk Usage Tabs.
    Open Console in Utilities & see if there are any clues or repeating messages when this happens.
    In the Memory tab of Activity Monitor, are there a lot of Pageouts?

  • LabView 2010: Any improvement in Resolution Independence?

    Hi Everyone,
    My last project I did in LabView was Way back in LV8.5.  Back then, I posted a question concerning screen resolution independence in LabView. Specifically, making a form resizable at run time and properly scaling controls / text properly:
    http://forums.ni.com/t5/LabVIEW/Labview-resizing-control/m-p/577438
    Have any improvements been made on this front in either 2009 or 2010?  I'm getting ready to start another project where the UI must be able to scale (resolution wise) properly, and will probably use VS2008 if not much progress has been made in labview in this area.....
    Thanks for your input!

    tartan5 wrote:
    In this day and age of widely varying (and constantly changing) screen resolutions, you would think this would be a bit higher on the priority list.
    You might, but consider that many programs written in LV (including those built into EXE) are probably run on one or few stations, where it's easier to tell the users "don't change resolution" than to write any code which will handle this.
    I don't have the experience with VS necessary to compare the two, but I assume that VS is still better at this.
    NI is certainly aware of the demand for something like this, but they also announced that LV 2011 would focus on stability and performance improvements, so I wouldn't expect to see any progress in this area in the next couple of years.
    Also, if you go to the idea exchange, search it first. I believe people already posted related ideas.
    Try to take over the world!

  • Airport Express 802.11n not any improvement

    I currently live in a guest house. The landlord has granted me free internet from his wireless router. The problem is the signal is weak (usually around 36-42 according to AirTraffic Control Widget). I posted this problem last week and learned a lot from a person on this board. http://discussions.apple.com/thread.jspa?threadID=1955558&tstart=0. He suggested I get a Airport Express with wireless n powers. I did and set it up. An ethernet cable is coming out of the wireless router into the AE as I was told. Now (according to airtraffic control) the signal is even weaker and I haven't seen any improvements. How is this possible. Any tips? Please help because I would like a refund if this is the case.

    You could try setting the AE to 'n' only 5GHz. That's often better.
    They key factor is what's between the MBP and the AE - walls, struts etc can interfere.

  • Z Series Cards - Any Improvements over XFi?

    I am looking to upgrade my PCI XFi to a PCIe solution.
    Any one have any input on whether one of the Z series cards would be a worthwhile choice over an XFi card? Looking at the specs I'm not seeing any tangible benefits.
    For one there is no 7.1 audio support. I know that 7.1 is becoming rare, but there are still 7.1 Blurays releasing and I think it's a worthwhile upgrade over 5.1. Especially if game developers can be convinced in supporting it. So I'm confused as to why a high end audio card is limited to 5.1
    As for the rest of the features I'm guessing that the SBX suite is the same tech that was on the XFi cards, just renamed. SBX Surround = CMSS3D for example. Have any improvements been made?

    You can Google or Bing the Z series for specs to get an idea of how those cards differ from the X-Fi family. I think the X-Fi cards host more processes in hardware but take this with a grain of salt.

  • Apple Compatibility for QuickTime 7.2 - update - any improvements?

    http://www.versiontracker.com/dyn/moreinfo/macosx/33148
    http://www.macfixit.com/article.php?story=2007091114255593
    I just updated this using Software Update. Does anyone notice any improvements?
    I can't test the DV quality issue right now but I'm curious if anyone can see any differences. I have converted all my DV files to H.264 using VisualHub because of the poor export quality using DV files. Converting the clips resolved these quality issues (described in various threads).

    I just updated this using Software Update. Does anyone notice any improvements?
    Animation source exports from iMovie '08 now have proper frame rates but still export with a "black" display and extremely low video data rates. (DV tests with video data rates maintained at 28+ Mbps seem to indicate that iMovie '08 is actually compressing a "black" image/video stream.) Have not had time to re-run quality comparisons between input and output for various common codes (e.g., DV, AIC, Photo-JPEG, MPEG4/AAC/H.264/AAC, etc.).

  • IOS 4.0.1 Update Released - Notice any improvements?

    iOS 4.0.1 update released. Install it via your iTunes.
    Notice any improvements with the new update?
    Check out the new remodeled MacOSG website! 24-hour Apple-related news & support.
     MacOSG: An Apple User Group  iTunes: MacOSG Podcast  Follow us on Twitter: MacOSG

    New bars are UGLY and are no longer symmetrical. I can't believe a company so focused on design would do this. Might be the worst PR move in Apple history. Just fix the reception issue and give us back the old bars.

  • My iPad is 2 years old and I am finding aps will suddenly quit.  I have done a system restore several times, without any improvement.  Is it getting too old?

    My iPad is 2 years old and I am finding aps will suddenly quit.  I have done a system restore several times, without any improvement.  Is it getting too old?

    What iOS version are you using?
    iPad Frozen? How to Force Quit an App, Reset or Restart Your iPad
    http://ipadacademy.com/2010/11/ipad-frozen-how-to-force-quit-an-app-reset-or-res tart-your-ipad
    iPad: Basic troubleshooting
    http://support.apple.com/kb/TS3274
    Frozen or unresponsive iPad
    Resolve these most common issues:
        •    Display remains black or blank
        •    Touch screen not responding
        •    Application unexpectedly closes or freezes
    http://www.apple.com/support/ipad/assistant/ipad/
     Cheers, Tom

  • 2008 iMac + nVidia 8800gs + 10.5.3 - Any improvement with Aperture?

    Can anyone with the latest 24" iMac (either the 2.8 or the 3.06 model) give any indication of whether the latest OS X update has improved the performance of Aperture relative to the Radeon 2600HD?
    Given that barefeats has undertaken a number of tests with the latest OS X update and found some measurable performance gains for Pro apps I was wondering how this translated in the real world.
    Are these improvements noticeable? Does Aperture still get bogged down and under what circumstances?
    If the update provides enough of a performance improvement for Aperture (over the Radeon 2600HD) then I will order a 24" iMac with the 8800gs card because I also have a Dell 2407WFP that I want to use with it for viewing/editing images and use the iMac screen for placing the HUD and well, basically everything else.
    Regards,
    Jason

    Yes, people have posted to this board that they've noticed significant improvement with the 8800 and Aperture. The sliders are much smoother now, with no more stuttering and choppiness.

  • Hi, I'm having a problem with my first gen. iPad switching back to the apps page by itself.  This started after upgrading to ios5.  It will do this from safari or kindle.  I have turned it off manually as suggested by a tech rep. without any improvement.

    Hi,
    My 1stgen iPad keeps. Switching back to the apps. Pages by itself after installing ios5.  I have shut it down manually as suggestedby a tech rep but the problem still exists.
    Thanks,  Jim

    1) This is because of software version 1.1. See this
    thread for some options as to how to go back to 1.0,
    which will correct the problem...
    http://discussions.apple.com/thread.jspa?threadID=3754
    59&tstart=0
    2) This tends to happen after videos. Give the iPod a
    minute or two to readjust. It should now be more
    accurate.
    3) This?
    iPod shows a folder icon with exclamation
    point
    4) Restore the iPod
    5) Try these...
    iPod Only Shows An Apple Logo and Will Not Start
    Up
    iPod Only Shows An Apple Logo
    I think 3,4, and 5 are related. Try the options I
    posted for each one.
    btabz
    I just noticed that one of the restore methods you posted was to put it into Disk Mode First rather than just use the resstore straight off, I Have tried that and seems to have solved the problem, If it has thank you. previously I have only tried just restoring it skipping this extra step. Hope my iPod stays healthy, if it doesnt its a warrenty job me thinks any way thanks again

  • Any improvements in sharing an iPhoto Library between multiple users?

    It is possible and Apple Approved to share an iPhoto Library between multiple users, but the Library must be stored on a drive or disk image that ignores permissions:
    http://tech.kateva.org/2008/10/apple-supports-multi-user-iphoto.html
    This doesn't work for me. Has Apple changed anything with iLife '09 to make it easier to share a Library? For example, have they changed from the prior Package format?
    Message was edited by: jfaughnan

    Alternatives to a trip to the Terminal:
    If you want the other user to be able to see the pics, but not add to, change or alter your library, then enable Sharing in your iPhoto (Preferences -> Sharing), leave iPhoto running and use Fast User Switching to open the other account. In that account, enable 'Look For Shared Libraries'. Your Library will appear in the other source pane.
    Any user can drag a pic from the Shared Library to their own in the iPhoto Window.
    Remember iPhoto must be running in both accounts for this to work.
    If you want the other user to have the same access to the library as you: to be able to add, edit, organise, keyword etc. The problem here is that OS X works very hard to keep your data safe and secure from the other users. You're trying to beat what's built in to the system. So, to beat the system
    Quit iPhoto in both accounts
    Move the iPhoto Library Folder to an external HD set to ignore permissions. You could also use a Disk Image or even partition your Hard Disk.
    In each account in turn: Hold down the option (or alt) key and launch iPhoto. From the resulting dialogue, select 'Choose Library' and navigate to the new library location. From that point on, this will be the default library location. Both accounts will have full access to the library, in fact, both accounts will 'own' it.
    However, there is a catch with this system and it is a significant one. iPhoto is not a multi-user app., it does not have the code to negotiate two users simultaneously writing to the database, and trying will cause db corruption. So only one user at a time, and back up, back up back up.
    Lastly: This method seems a little clunky at first, but works very well. Most importantly, it uses the System to do the job for you.
    Create a new Account on your Mac, call it Media. Create an iPhoto Library there. (BTW: This will work for iTunes too.)
    Enable Sharing on the Library:(Preferences -> Sharing), leave iPhoto running and use Fast User Switching to open the other accounts. In those accounts, enable 'Look For Shared Libraries'. The Library will appear in the other source pane.
    This means that both users will be able to see the pics. If you want to use a pic then simply drag it from the shared Library to your own in the iPhoto Window. This means that each user can have their own edits.
    If you want to add photos to the Library: Log into the Media account for that purpose.
    To make it all seamless: Set your Mac to log into the Media Account automatically. Set iPhoto to launch on log-in. Then switch to your own account using Fast User Switching.
    Net result: a Library that's permanently available to all users but also protected. Each user can have their own versions of the pics if they want.
    No partitioning, no permissions issues. Uses no extra disk space. What's not to like?
    Regards
    TD

  • IMac high pitch sound (4th iMac in a week). Any improvements?

    Hello,
    I know there is a lot of forum posts on the internet about this, as I've spent about two days reading them (primarily from my iPhone as my screen sound drives me up the wall).
    As some people have experienced, this is a result of changing the brightness (0% and 100% are fine, anything in between emits a high pitched whine...some people believe this is a result of the capacitors vibrating at around 15-16Hz, which would make sense).
    I have actually gone through four separate iMacs in a week to try to fix this problem (and two being upgrades over the model I had in hopes of a different production run). I have checked the serial number on all of them and they were all build between September and October, at various weeks between, mostly within a 4 week window.
    I am beyond my wits with this issue and not sure what to do now. I have spent nearly 20 hours setting up four separate computers only to format them to take back in a chance I am lucky enough to get one that I can dim at night time without getting a ringing sound in my ear.
    I was wondering if anyone else who has experienced this issue has come across a solution, or at least a replacement that has worked? I am debating to go for number five, but honestly, I am almost too tired of boxing and driving, boxing and drive (rinse and repeat). (I even tried three separate stores in hopes to get a different production week that didn't have this issue).
    Looking forward to your responses, and any guidance. I love this machine and I wish it just stopped having these issues so I could do some work...
    Setup(s):
    First two:
    21.5" iMac 3.06GHz Intel Core i3
    4GB RAM
    500GB HDD
    ATI Radeon 4670
    Next two:
    21.5" iMac 3.2GHz Intel Core i3
    4GB RAM
    1TB HDD
    ATI Radeon 5670
    Thank you,
    Adam

    I started having this problem yesterday on my late 2009 iMac 27 inch after I changed my HDD.
    It was perfectly fine before however after the swap however after a high pitch noise occurred when I increased the display brightness. So Just this morning I pulled my iMac apart again and unplugged the screen again and had a look at the connectors. all were fine except for the Vertical Sync ribbon
    The 4 flat wires/ribbons that are exposed on the end are supposed to be glued to the thin piece of plastic that plugs into the socket on the circuit board. This circuit board is on the top left hand corner of the iMac as well which is where people say the sound is coming from.
    I am not sure if this will solve all the problems out there but its worth a look.
    Follow this link to the ifixit guide to see what I mean (Look at Step 5)
    http://www.ifixit.com/Guide/iMac+Intel+27-Inch+EMC+2309+and+2374+Hard+Drive+Repl acement/1634

  • Any improvement in ripping error handling since 7.0.1.8?

    iTunes is driving me nuts, %10 of the songs I rip from my CD collection are garbled crap and I have to go back and use Realplayer to rerip them or rip them to WAVs with other apps. This is time consuming when you have a 600 CD collection you're trying to transfer. Anyone know whether CD ripping is any more reliable in iTunes versions since 7.0.1.8?
    I have "use error correction..." checked, always have ever since the problem started and I naively thought having error correction might help correcting errors :P
    I'm reluctant to update just to find out because it took some work to get iTunes to ONLY do what I want it to and disable all the junk I don't want it for plus I'm wary of losing synched items in the process or getting an app that's even more bloated than I want when all I want is something to let me transfer my songs from CD to my iPod.

    The CD may be "copy protected" by the manufacturer, meaning that it contains a high number of intentionally-deposited error pts to prevent computer CD-ROMs from being able to rip the data.
    Try ripping the CD with another program, such as Exact Audio Copy, and see if you are able to successfully rip it. And be sure to check the ripped files to see if they sound okay. If you have similar problems there, then the CD is probably copy-protected.
    Do a Google search for the CD in question, and if it's copy-protected, you'll find plenty of other people complaining about it in various online forums. Usually you can return a CD like that to the place you bought it for a refund, as it's your only way of fighting back as a consumer against this form of copy-protection.
    None -- self-built PC   Windows XP Pro   XP Pro SP2, 2 GB RAM, Intel Core 2 Duo 6600

  • Macbook Core 2 Duo Keyboard - Any Improvement On Previous Generation?

    It's a few hundred kilometers to the nearest Apple Store, and local stores which sell Apple products don't have very many models on display or change them often.
    I have tried the keyboards on the previous models (pre-core-2) and found that the keyboards lacked both tactile feedback and sculpturing of the keys (ie: they seemed perfectly flat). As a touch typist, these are features that are important to me.
    Does anyone know if this feature has been improved on the new models?
    Thanks.

    I wouldn't hope for a change to the keyboard. While a handful of people such as yourself don't like the new keyboard, it seems the vast majority of people prefer it over previous versions as well as the keyboard on the MacBook Pro. If you prefer a more traditional keyboard, the Pro may be the way to go. You can get some good deals on Apple refurbs... especially if you get a Core Duo vs. a Core 2 Duo.

  • Any improvements to new 3G audio speaker , also comments on yellow screens?

    Hello all you new 3G owners, can anyone comment on the "New improved audio quality" as mentione by Steve Jobs? Has the speaker phone volume improved and can you hear the ring tones?
    Also a few people are commenting on yellowish tint to their screens, can you state how yours is, so that I can see if it across the board, or just one offs.....
    Thanks

    Compared to my 1st generation iPhone, side by side, the 3G does appear yellow-y, while the 1st generation has more of a blueish hue. Kind of like when you make a picture "cooler" or "warmer" while editing photos. It bothered me when I put them side by side, but when I put my 1st gen. up and just held my 3G, the screen seemed fine. Does it have to do with the quality of the screen, or just the hue? Is this something I need to be concerned about, I wonder.
    Oh, and the audio: It seemed much crisper and less fuzzy, but I didn't really find it louder. It is not bad, but it could be better.
    Message was edited by: iPhoneiPodLove

  • Database Import command untility. Any improved in 5.1?

    ldif2db in 4.16 is painful to use. If I just want to input 1000 entries that is just part of user directory tree, I have to export the user directory tree and put in that 1000 entries, then export nsroot and the other sys configuration root. After that I have to run ldif2db with the above three ldif files. If I do not do so, I will lost the system configuration. But the strange thing is using GUI console, I can easily import that 1000 entries without overwrite the whole database.
    My question is in 5.1 is there any utility that can doing the import like GUI doing?
    Thanks,
    Peter

    The console uses plain old ldap add to add entries to an existing database. You can do the same from the command line:
    ldapmodify -a <ldif file>
    There is no subtree delete command. The GUI console is actually doing a recursive search and delete for each entry in the subtree. I don't know if there is a command line for this, but you could write one.

Maybe you are looking for

  • PS CS3 Crashing . . .

    I had to reinstall CS3 on my new Mac Pro. After going through that dreadful reactivation process, suddenly whenever I try to open a file from the Open menu PS crashes. I can get the image to appear in PS by double clicking it. It only happens when I

  • I use picasa for my photos..currently there is a question mark imposed over the icon on the dock aand it won't open...what does this mean?

    I use picasa for my photos..currently there is a question mark imposed over the icon on the dock and it won't open...what does this mean? Thanks for any help.

  • Connecting to car radio

    After connecting to my car radio via inbuilt ipod cable for around half an hour or so my ipod freezes and has to be reset via itunes. Any ideas?

  • Enquiry about Iphones From Uk

    Recently i have heard that in Uk,some people are importing iphones to India and they are saying that phone comes with 1year Indian warrenty.I asked them how it was possible.They answered me that,they will buy bulk units from manufacturers with Indian

  • BO cannot connect to database

    Hi, all. I am trying to install BOXI 3.1 on windows 2003 server. On the server, there is already an oracle 64bit server installed(BO have to use that db). Now, BO is 32 bit so I have to install a 32bit oracle client. I changed the local path of the B