Available() - Don't use it!!!!!!

I've seen a number of questions and replies recently where the InputStream.available() method, also inherited by many subclasses, is being used, or where the replies advise that it be used.
So far, I haven't seen a single usage which is correct.
Unless you're doing asynchronous I/O (java.nio...), it's very unlikely that this method is going to do what you want. All it tells you is how many bytes (not strings, or objects, or whatever, just bytes) can be read without the stream blocking (making the calling thread wait). It has nothing to do with the number of bytes that will ultimately be readable from the stream. It is not the size of the file.
In short, unless you have a clear understanding of asynchronous I/O your use of this method is almost certainly going to be wrong.
Sylvia.

>>>
Pretty obvious if the file is more then 2Gb.
So if the file is more than 2 gigs than a read will
block?
I know I can write C code for files larger than that
and the read will not block.
So why does java have this limitation?I don't understand the point you're making. The
available() method was never required to return a
number such that an attempt to read more than that
number would definitely block. That requirement would
be absurd, because the read() must necessarily folllow
the call to available() and in the mean time, more
data may arrive, so that a read of more bytes that
were supposedly available will still not block.
So for a file greater than 2Gb, it would be reasonable
for the available() method to return values lesss than
2Gb. This would be in compliance with the
specification.
Nope. The docs state quite clearly that it returns the number of bytes that can be read before a block occurs.
It doesn't say anything about returning a value less than what might be available before a block.
And we are not discussing what is "reasonable" but rather exactly what the specification says.
Of course if you wish to discuss what is reasonable then please provide an example of code that does not return the file size. Because I consider it reasonable (given my knowledge of how low level file systems work) that the only reasonable size to return is the size of the file.
>>
What about a file on a network file system?
Irrelavent. All current file systems mount files at
the OS level. The file size will be the same
regardless of whether it is local or not.But the implication is that if available() returned
the size of the file, then reads of that amount of
data could block because the system has to wait while
further data arrives over the network. In such
situation, available() would not be conforming with
its specification.And again that is not the point.
The point is not whether blocks occur but rather whether any OS provides that information at the low level (much less high level) io calls for a file system read.
As far as I know they do not.
And unless a 'magic' interface has been added to java or it is replacing the OS itself then it is not going to have that information.
>
>>
The documentation itself for available() in
FileInputStream says :
"Returns the number of bytes that can be read from
this file input stream without blocking."
And when the file is bigger than 2 gigs but it can
read the file without blocking what does it return?
It can't return 2 gigs because that is a lie.No - it's simply saying that you can read that many
bytes without blocking.And as I already pointed out I can read more than that on any OS that I know of without blocking.
>
And it can't return more than that because the int is
too small.
And it can't return less than that because that would
be a lie as well.
So in the above case which of the following are you
claiming?
1. The documentation is wrong.
2. Files bigger than 2 gigs are not allowed.Neither, for the reasons stated above.You are claiming that the value returned represents a blocked value. And I am specifically telling you that that does not happen at the OS level. So exactly what are you claiming is blocking?
>
>>
It would be nonsense to talk about blocking if the
only possible case for blocking was where an attempt
was made to read more bytes than are in the file,
because an attempt to read more bytes than that would
still not block. It would read up to the end of file
and return immediately.No idea what you are talking about.
Whether I can produce an example is irrelevant. This
is about specification, not about current
implementations.So you claim that the documentation is now and always
will be perfect?I claim that it is correct. And you know this because?
I can only presume that either you have verified it in java or you have verified it with the low level io calls for a particular OS.
Which one is it? And if the latter please provide the OS and hopefully a link so I can read about this low level io block.
In view of this
discussion, and other people's misunderstandings, I
think the documentation could be improved to make it
clear that it cannot be infered that an attempt to
read more than available() returns will necessarily
block. Although as I've argued, that should have been
obvious.And as I was trying to make obvious, for the context I gave, it will not block and thus the only reasonable size that available can return, based on the documentation, is the size of the file.
>>
And whether you can produce an example is relevant to
me.
Because it is rather easy for me to produce an example
of an InputStream that will block and thus your
comment about InputStream.available() seems very
relevant.
However, I can't conceive of a situation (given the
constraints that I suggested and that normally occur)
where a file read will block. I know for a fact that
OS file system implementations do not do that.
Blockage does occur but that information is not
available to the low level file io methods.This should be viewed as a limitation in current O/S
implementations. There's no good reason for a system
not to support asynchronous disk I/O, and certainly no
such reason for a failure to support it on network
file systems.There is a very good reason for it. The OS itself does not expect it. And given that every modern 32 bit and 64 bit system that I know of does it exactly that way I don't really expect it to change in the future.
However, feel free though to provide a link to a research paper, or several, that demonstrate that we can expect to see this in the next wave of hard drives or file systems.

Similar Messages

  • I am using a work laptop and have the same problem. When I try to change the "configure proxy", they only available option is "use this proxy server for all protocols". Could it be that my system administrator blocked me from changing it since they don'

    I am using a work laptop and have the same problem. When I try to change the "configure proxy", they only available option is "use this proxy server for all protocols". Could it be that my system administrator blocked me from changing it since they don't want us to use Firefox.
    == User Agent ==
    Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB6.4; FNGP_SYS)

    Start Firefox in [[Safe Mode]] to check if one of your add-ons is causing your problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    See [[Troubleshooting extensions and themes]] and [[Troubleshooting plugins]]
    If it does work in Safe-mode then disable all your extensions and then try to find which is causing it by enabling one at a time until the problem reappears.
    You can use "Disable all add-ons" on the ''Safe mode'' start window.
    You have to close and restart Firefox after each change via "File > Exit" (on Mac: "Firefox > Quit")

  • How about allowing customers who don't use all their paid for data to store it to be used in the event of an over use?

    If we have already paid for data why can't we store it so if someone on the plan is traveling or in an area without wifi if the plan is in jeopardy of going over it could pull from the storage.  I have five (5) lines and 10g and rarely use more than half but occasionally there is the possibility of going over.  It seems unfair when for months I have paid for and not used it all.  It would be a really good marketing move to offer this to those who might be ready to switch cell phone carrier.

    rebretz wrote:
    Barely going over your data plan results in such a ridicously high charge. It's $10 for an extra GB. That's really steep. And the difference between the 5GB and 10 GB plan is only $30. Again it only comes done to Verizon greed. (Not just Verizon but AT&T also) If someone is on the More Everything plan, it is $15 for an overage of up to 1 GB if you have an allowance of 1 GB or more, it is not $10. Additionally, there is not a 5 GB plan, but a 4 GB and a 6 GB plan. The difference between a 4 GB and 10 GB plan is $30/month and the difference between a 6 GB and 10 GB plan is $20/month.
    This also goes along with Verizon now going to throttle data of people still on grandfathered unlimited plans by claiming it's for network optimization. It's all about trying to squeeze as much money as possible out of people. I have two lines of grandfathered unlimited data but if I would change my plan to so called "More Everything Plan" I'll end paying about $70 more a month. Throttling data does NOT squeeze more money out of customers. You will still be paying the same $30/month for your unlimited data. The throttling will ONLY be for high bandwidth activities, at least as reported by multiple sources, and will only be temporary, unlike until the end of the billing cycle as has been the case in the past. Of course if you would be paying $70 more/month to switch to More Everything you should stick with your old Nationwide plan. Not everyone who switches will be paying more, though, and would need to be determined on a case by case basis by the customer.
    It's obvious Verizon is only doing this to squeeze us of Unlimited. If they were really worried about Network Optimization they would throttle anyone who uses more than 5GB of data a months not just those still on Unlimited Data. This is not the case. When someone who pays for ACTUAL usage, the increased revenue can help Verizon offset the cost of increasing capacity. When you have a SET REVENUE stream on an unlimited data plan, this IS NOT the case. Increased revenue leads to more money available to be used on infrastructure.

  • If you don't use an ipod, is there a reason to download the updater?

    Since I don't use an ipod, currently. Is there any reason I would need to download the updaters when they come out?? Is there some function they address even if you don't use one??

    The functions previously provided by the iPod updater are now part of iTunes, and the updater is no longer available as a standalone download. You may still see an older version of the iPod updater in Software Update if your version of Mac OS X cannot run iTunes 7.
    (16139)

  • Does a nonstandard(created by you) become available for general use?

    if you don't have a standard bapi  available for some transaction you require, can you create your own bapi and use it ? is it allowed ? does such a bapi become available for general use from then on like the standard ones? otherwise who else can use it?

    Hi,
    Yes we can use them as standard ones
    regards

  • Partitions I don't use being automounted - Udisks ?

    Several partitions on my disks are formatted but are (were) not in /etc/fstab since for the
    moment I an not using them (they used to have a 32 bit ARCH version, I am using 64 bit now).
    But I started noticing that some programs started showing them (thunar, adeskbar icon changer),
    and if I willingly or unwilling clicked on them, they would be mounted under /media with their
    labels as device name (/media/free_1, /media/free_2, ...).
    This in itself doesn't break anything but it makes no sense to mount dormant partitions.
    I suspected udisks, that I know little about, executed "udisks --inhibit-all-polling" to stop
    it meddling with my fixed disks, to no avail.
    After trial and error I now have the empty partitions in /etc/fstab, noauto, being mounted in
    fake directories outside /media:  /free_1, ....
    Perhaps someone more knowledgeable can explain to me what this is all about.
    I have ARCH 64, fully updated, don't use any desktop manager (only WM, icewm or pekwm), but do
    use some programs from the Gnome suite.
    My DAEMONS line in /etc/rc.conf is:
    DAEMONS=(syslog-ng !dbus hal !network @net-profiles netfs @sensors @ntpd @sshd @crond)
    Mektub

    By design, Thunar will not show any partition that is in /etc/fstab (except /), but will show the other ones... I don't think udisks has anything to do with this (I don't know what udisks is, though.) So your solution looks ok to me.

  • How to access SMP if I don't use SAP product but only MaxDB?

    Hi All,
    I am sorry if this is answered elsewhere, I am a MaxDB user and our company operates a website with MaxDB as the data engine behind it since 2003. Recently I am evaluating if we can use synchronization to scale out, however I hit road blocks when I research information and most are on SMP which requires a login. How can I get access there ?
    Regards,
    Chris

    Hi Chris,
    the SAP Service Marketplace is for SAP customers only.
    Anyhow, especially for MaxDB there are many information available for public use.
    There's the [WIKI|https://www.sdn.sap.com/irj/scn/wiki?path=/display/maxdb/main] and the [MaxDB Website|http://maxdb.sap.com/] that includes online searchable documentation, as well as trainings materials and presentations from the MaxDB events.
    A good starting point is always the [MaxDB Homepage here in SDN|https://www.sdn.sap.com/irj/sdn/maxdb].
    If you don't find your questions answered with these options, you can always post your question here to the forum.
    Anyhow, what information did you want to look up and only find them in the SAP notes on SMP?
    Especially if you're an "Open Source"-MaxDB user, most of the available documentation is already made accessible via the resources I mentioned.
    regards,
    Lars

  • HT4847 Storage: 0 bytes available 13.3  used.  IClous has 18.9GB available.  How do I transfer

    Can Stored datga be transfered to the ICloud?

    You have to delete files on your device. 
    Delete apps you don't use.
    Delete videos you don't want (these take up a lot of space).
    Do you have a lot of emails stored on the device?
    Are there apps that store data files, like a PDF reader?  If there are a lot of these, you need to delete some.
    The bottom line is that you need to remove data and/or apps on your device to make more storage available.

  • Time Machine formatted itself on my external drive despite pressing "Don't Use"

    I have an external hard drive that has been in use on/off for years. I even had backups on it (not using Time Machine). I mounted this hard drive, it was taking a while to mount. A prompt came up to ask if I wanted to use this drive as a time machine backup. I said "Don't Use". It hanged. Meanwhile, I opened disk utility twice. Both I had to force quit. After a while I relaunched finder.
    Assuming it would cancel the time machine prompt. Only when did the finder eventually relaunch that the drive mounted to see that all my files where gone and looking in Thermal under ls -a to see their we're spotlight and time machine files along with some oddly named thing. About 1GB Is in use on the drive(I had much more that a gig on it). It is a TB drive
    Here is the output from the ls -a on the volume
    ._.com.apple.timemachine.donotpresent
    .com.apple.timemachine.donotpresent
    .Spotlight-V100
    .fseventsd
    .Trashes
    USBCˆö?␀.␀€␀
    ._.Trashes
    Anyway would a tool like this (http://www.cgsecurity.org/wiki/TestDisk) help get back my files and format back to what I had previously? Or I am going in the wrong direction? What should I do?
    Thanks. If you have any questions please reply below

    Thank you Thomas,
    I should have mentioned that the drive is formated as FAT32 and I  ran verify disk on the drive and this error keep coming up until I stop the process :
    "2013-02-16 12:06:23 +0000: / has entries after end of directory
    2013-02-16 12:06:23 +0000: Truncate? no
    2013-02-16 12:06:23 +0000: Extend? no"
    Will the tools mentioned in you post work with FAT 32? I am looking at Data Rescue 3 becuase of the FileIQ functionality since I know I have obsure file formats on there
    Does this help or it is irrelevant?

  • How do I remove the "Web" bar in F4 - I don't use any of the social sites

    A black toolbar with "Web" on the LHS has appeared in my latest version of FF. It is near the top of the page. How do I get rid of it - it is annoying and I don't use any of the sites it has (like Facebook or Twitter etc)

    That didn't come with Firefox4, something else installed that into Firefox.
    Try the Firefox SafeMode. <br />
    ''A troubleshooting mode, which disables most Add-ons.'' <br />
    ''(If you're not using it, switch to the Default Theme.)''
    # You can open the Firefox 4.0 SafeMode by holding the '''Shft''' key when you use the Firefox desktop or Start menu shortcut.
    # Or use the Help menu item, click on '''Restart with Add-ons Disabled...''' while Firefox is running. <br />
    ''To exit the Firefox Safe Mode, just close Firefox and wait a few seconds before using the Firefox shortcut (without the Shft key) to open it again.''
    If it is good in the Firefox SafeMode, your problem is probably caused by an extension, and you need to figure out which one. <br />
    http://support.mozilla.com/en-US/kb/troubleshooting+extensions+and+themes

  • HT3986 I've had MS Office:mac 2011 on my imac for around 18 months now.  Outlook has just disappeared and when I find the file and open it it tells me that there is a problem and I may need to re-install it.  I've just done this using the installation dis

    I've had MS Office:mac 2011 on my imac for around 18 months now.  Outlook has just disappeared and when I find the file and open it it tells me that there is a problem and I may need to re-install it.  I've just done this using the installation disc which, then said the installation had been successful.
    Outlook is still not working.  Can anyone please advise me on what to do next.

    Remove MS Office 2011 completely (here are instructions) and reinstall it.
    It's not a simple or fast process but it is important to follow all of the steps in order to get all the files that Office scatters around. This will not affect your data files, only MS Office and its preferences.

  • I have been a loyal customer for years and have a hot spot because internet options are very limited in our rural area.  I have stayed with 10G since the beginning.  Most months I don't use the 10G.  Verizon has no problem with me paying for Data I don't

    I have been a loyal customer for years and have a hot spot because internet options are very limited in our rural area.  I have stayed with 10G since the beginning.  Most months I don't use the 10G.  Verizon has no problem with me paying for Data I don't use.  This month my daughter comes home from College and she accidentally uses 24G.....14 over get blind sided with $140.00 in overages.  I called Verizon today......stopped in to the store today......My neighbor told me they waved charges for her one time.  Lots of charges.....But I'm am getting no help.  Not even an offer of a payment plan to help me out.  I went back just 6 months and I have over paid for 19G.....Seems like they would like to help out their loyal customers!!!!     Does anybody have any suggestions on how to deal with them?   We are not wealthy....or I would just pay this and walk away......

    There is a big misconception in what customers believe a cell carrier is obligated to do.
    You pay a set price to use up to that amount of xx data. It makes no difference if you use it to the paid limit or way under. Its like peace of mind when you don't have to worry about a data counter.
    Your daughter used the data, your plan is quite clear of what overage charges are. Why should or would Verizon wireless just forgive the charges because you are a customer? Your daughter used the data, get the money from her. That is the responsible thing to do.
    There is no "I have been a loyal customer so please remove the $120, or $250, or $2,000.00 since I did not mean to use it"
    Your electric company, or gas company or any other company does not remove valid charges. Why should Verizon wireless?
    Just pay the invoice and don't think you are being mistreated because Verizon is a business and not a charity.
    Good Luck

  • Attention!!-don't use OLE object in Reports

    If you are planning to use or is currently using OLE objects in Reports-please don't use it as the object maynot reload in future and your report may not even open in Report Builder.I got this message when opening the report containing OLE object:
    REP-4004: Error occurred while restoring OLE object
    and it refused to open up crashing my days of work.
    The pity is I can't open my report even to remove the OLE object.

    I know that is weird.I placed the object in the same directory-but in vain.Afterall, what's the logic of putting it in the same directory after embedding it?

  • I upgraded for Firefox 4 and now my simplePass identity protection (biometric scanner) on my laptop will not work. WHY? It still works with IE but I don't use IE.

    I upgraded for Firefox 4 and now my HP SimplePass Identity Protection (biometric scanner) on my laptop will not work. WHY? It still works with IE but I don't use IE. It worked with the previous Firefox version but now when I use the internet, it doesn't even acknowledge I have the scanner. When I run my finger over it, it opens the settings panel but does not allow use of the already saved information or allow new information to be entered. I need this corrected. Any suggestions?

    I asked this same question, and just received a response:
    "Thank you for contacting DigitalPersona. There will be no update releases
    for DigitalPersona Personal in the future. There will be no updates for
    Firefox 4 nor Internet Explorer 9. IF they work they work, if they do
    not work with DPPersonal, then you will have to decide to either keep
    DPPersonal and forgo Firefox 4 or IE 9, or vice versa. DigitalPersona
    is leaving the consumer market and is focusing on business applications.
    In fact, DigitalPersona Personal will not longer be supported after
    Mid-April of this year.
    We apologize for any inconvenience this might cause. Sincerely, Tech Team "
    In other words, there will be NO update.

  • HT204053 I have 2 Itunes accounts, one I don't use with money in the account, can I combine that money or account into the account I currently use?

    I have 2 Itunes accounts, one I don't use with money in the account, can I combine that money or account into the account I currently use?

    You can access, usually under the Apple (icon) menu in the main desktop
    window, note item with name "About this Mac" & click on that, to see more
    information about your computer, its OS X version, and other. The system
    version and build model are there. Do not post a serial number.
    If you are setting up Mail in a Mavericks OS X 10.9.x system, there often
    is access to information in the Help viewer from the main menu bar, or
    in an open mail application. If you have a Gmail or other account, that
    info is often on their home page where setup and help are located.
    The settings of each email account may vary according to their provider;
    so you would have to change your computer to accept them. An older
    link to a general look at that issue, change IMAP to POP, is covered here:
    https://discussions.apple.com/message/16770816#16770816
    While that may not answer your question, you could use the info in
    your Mac OS X system Help viewer and use its search; or maybe
    a Spotlight search to see an answer online.
    You have to learn some basic things in order to actually use these...
    and it helps to expand that so you won't have to pay for tech service
    on things you can do yourself in a few minutes, beyond easy stuff.
    Of course, you're hearing this from a guy with no ISP email, ever.
    So mine are web-mail only; & I never save email to a computer.
    PS: If you have a new Mac with an AppleCare plan, you may be able
    contact Support for help. Ask someone (for 90 days, or up to 3 years
    if the Plan was extended) there at AppleCare, for their guidance.
    http://www.apple.com/support/contact/
    Good luck & happy computing!
    edited

Maybe you are looking for

  • My 2nd AX will connect to TC but not AE

    I have a network with a AE and an extention TC in another part of the house connected with a cable. Both are there show as create network in settings. I have an AX (1st generation) connected to the TC (1st generation) and it works fine. I wanted to c

  • Not Able to Connect to Intranet Web Server

    We have ASA5550 (ver. 8.0.4). We setup Split-tunneling. The Remote users were NOT able to access the intranet web server using Cisco VPN client. However, they were able to access other internal resources. We were able to ping the IP address of the In

  • Save as template kill the web part connection

    Hi, I have a Sharepoint web site and I would like to save it as a template in order to create several site with the same structure and the same web pages. On some of my web part pages I have some webpart connected to each other (mostly BDC List web p

  • Last image settings for auto apply adjustments?

    We're testing the watched folder setup for LR3 and it seems to work fairly well.  One very big snag we've come across though is with using auto apply adjustments and the apparent lack of a 'use previous image settings' option. We're using DSLR Remote

  • Can I set the time ruler in the main window to minutes/seconds/milliseconds?

    Is there a way to set the time ruler in the MAIN window to minutes/seconds/milliseconds? It seems that the only ruler time display option is minutes/seconds/frames/subframes. Or, failing that, is there a way to suppress the display of frames/subframe