How to override InputStream.available()

Hi,
InputStream.available() always returns zero.
now i have a requirement where I want to know total size of data in an InputStream.
Note: I don't want to read all the data byte by byte into an byte[] etc etc.
the reason is that data can be huge and i don't want to keep it in memory.
Regards
Apratim

I'm glad you don't want to keep huge amounts of data in memory but I would consider 512Mb as huge myself.
To override InputStream.available() all you have to do is override InputStream.available(). But if the information you want isn't available, tough.
FileInputStream.available() returns the length of the unread portion of the file, although I don't rely on it personally. Various other implementations of available() return zero. For example, SSLSocket.getInputStream().available(), because the stream can't know without decrypting, and it mightn't have an entire cipher block to decrypt, and you wouldn't want it to block getting the rest of the cipher block so it could decrypt so it could tell you how much data was available without blocking, so what else can it do?

Similar Messages

  • How to get InputStream of uploaded file from request?

    The situation:
    Client is uploading xml file to server.
    <form METHOD=POST ENCTYPE = "multipart/form-data" action="SendFile" accept="text/xml">
              <input type="file" name="SentFile" />
              <input type="submit" value="go"/>
    </form>Then I need to parse data from file.
    I want to use method javax.xml.parsers.DocumentBuilder.parse(InputStream is)
    But, how to get InputStream of uploaded file from request?

    You cannot get the InputStream of the uploaded file directly. The InputStream you can obtain from request.getInputStream() contains a lot of other data as well as the uploaded file. You will have to parse the data in the InputStream to find the data that belongs to the file.
    A short cut is to use the HTTP Multipart File Upload available from www.jenkov.com. It simplifies file upload and makes it easy to obtain an InputStream for only the uploaded file. It also handles upload of multiple files. It is free, open source, Apache license, so if it doesn't fit your needs, you can always read the code and see how it works. Then write your own upload servlet.

  • Unable to understand InputStream.available() method, need some help

    dear friends,
    The following is my doubt. please kindly help me in this. this will help me a lot in understanding some consepts.
    Environment: i am using jdk1.4.1_01 on windowsxp.
    i am using IE6.0 to make requets.
    My requirement:
    what i am actually trying to do is i want to see the raw material
    send by the browser when we made a request to the server
    by the browser.basically i want to see the request line
    and headers as it is that is send by the browser to the server.
    so i thought to code a server that can print the request send
    by the browser as it is on the command window.
    i had taken two examples and i am running Server2.java (look at the bottom for this code)and i made a 25 requests to the server2 program
    which is running on port 8080 by the browser. here only once or twice in 25
    times i was able to see the requests send by the browser.i tried hard and
    found that InputStream.available() method is returning 0 even though the
    request is sucessfully send to the port 8080 that is to the server2 program
    which is listening to port 8080.
    so in this process of experimenting i took Server3.java(i am sending this file
    also as an attachment) which is using multithreading. in this also i did modification
    as i did in Server2.java. the thing is here i am able to succed. here
    InputStream.available method is returning the correct number of bytes
    that are arrived on the port and are available to the InputStream.here
    when ever i made a request from the browser to Server3.java i am able to
    see the raw data send by the browser without failure.
    i could not understand why InputStream.available() is returning 0
    often(not all the time) and why it is giving the desired result when i
    used it in Server3.java ?
    i looked into the documentation and it says " InputStream.available() Returns the number of bytes that can be read (or skipped over) from this input stream without blocking
    by the next caller of a method for this input stream."
    so the thing i could not understand is what is blocking the InputStream
    in the first case.if i could undrstand the internals of how this
    method is working it will help me a lot.if i could understand this i
    will know what is the right situations to use this method.
    Thanking You.
    /*Shows how to develop a simple network server
    Author : Team -J
    Version : 1.0 */
    import java.net.*;
    import java.io.*;
    class Server2{
    static public void main(String[] args)throws Exception{
         // create a new Server Socket
         try{
              ServerSocket ss = new ServerSocket(8080,1);     
         while(true){// set queue length to 1
              // wait for the connections
              Socket s = ss.accept();
              // get the output stream associated with socket
              // to write something to the socket
              PrintStream ps =new PrintStream( s.getOutputStream());
              InputStream is = s.getInputStream();
              ps.println("I am ready to provide xxx Service");
    int len=is.available();
              if(len !=0)
              byte b [] = new byte[len];
              int k =is.read(b,0,(len-1));
              for(int i =0;i<k;i++)
                   char c = (char)b;
                   System.out.print(c);
              // close the connection
              is.close();
              s.close();
         }catch(Exception e){}
    /*Shows how to develop a simple network server
    Author : Team -J
    Version : 1.0 */
    import java.net.*;
    import java.io.*;
    class Server3{
    static public void main(String[] args)throws Exception{
         // create a new Server Socket
         try{
              ServerSocket ss = new ServerSocket(8080,1);
              while(true){
                   // wait for the connections
                   Socket s = ss.accept();
                   ServerThread st = new ServerThread(s);
                   st.start();
         }catch(Exception e){}
    class ServerThread extends Thread{
    Socket s;
         public ServerThread(Socket s){
         this.s = s;
         public void run(){
              try{
              PrintStream ps =new PrintStream( s.getOutputStream());
              InputStream is = s.getInputStream();
              int len=is.available();
              ps.println("I am ready to provide xxx Service");
              if(len!=0)
              byte b [] = new byte[len];
              int k =is.read(b,0,(len-1));
              for(int i =0;i<k;i++)
                   char c = (char)b[i];
                   System.out.print(c);
              is.close();
              s.close();
              }catch(Exception e){}

    so the thing i could not understand is what is
    t is blocking the InputStream
    in the first case.Blocking means the thread goes to sleep waiting for more data to arrive. InputStream.available() shows how many bytes have already arrived, not how many remain to be sent.

  • How to override the create method invoked by a create form?

    Hello everyone, I'm using ADF Faces and have the next question:
    How can I override the create method which is invoked by a create form to preset an attribute in the new row (the preset value is not fixed, I have to send it to the method as a parameter as it is obtained using an EL expression)?
    In the ADF guide I read how to override a declarative method (Section 17.5.1 How to override a declarative method), but this explains how to do it with a method that is called by a button. I don't know how to do the same with a method which is called automatically when the page is loaded.
    I also tried overriding the view object's createRow() method to receive a parameter with the preset values but it didn't work, I believe that was because the declarative create method is not the same as the view object's createRow. This caused the form to display another row from the viewobject and not the newly created one (I also set the new row into STATUS_INITIALIZED after setting the attribute).
    Well, I hope my problem is clear enough for somebody to help me.
    Thank you!

    Hello,
    I'm not sure you can do it with standard generated Create Form.
    In your view object you'll need to create your own create method with parameters, publish it to client interface and invoke instead of standard generated create action in page definition.
    Rado

  • Computer doesn't recognize administrator password.  How to override or reset?

    Computer doesn't recognize administrator password.  How to override or reset?

    You cannot override but you can chage it, the approach depends on the Mac OS X you are using.

  • How to make iBooks available in iBookstore for Sri Lanka and India?

    Does anyone know how to make iBooks available for purchase in iBookstore for Sri Lanka and India?  I have tried going through iTunes Connect to add regions, but it doesn't give me the option to add any more.  Thanks

    ali.basheer.ahamed wrote:
    Can I know How to add to the Indian store please. I have been trying the same - unable to add.
    Consult this list to see whether paid books are available in those countries:
    http://support.apple.com/kb/TS3599
    If not, you have to use another store, like Kindle, Nook, Kobo, Googlebooks, or Sony.

  • How to search for available class in given package?

    How to search for available class in given package or sub package?

    Finally i did it. I make hibernate and spring without much configuration. I just pass the package pattern to search for all bean. I named it package pattern injection.
    My website is still under construction yet. It named Jimmy6 Framework.
    The code it just the following for all hibernate and spring bean for the whole project.
    <bean id="sessionFactory" class="com.j6.framework.JAnnotationSessionFactoryBean">
              <property name="annotatationOrHbmXmlPackagePattern">
                   <list>
                        <value>com\.j6\.project.+?\.vo\..+?</value>                    
                   </list>
              </property>               
    <bean id="autoBeanCreatorFactoryManager" class="com.j6.framework.resource.AutoBeanCreatorFactory">
              <property name="packagePatterns">
                   <list>
                        <value>com\.j6\.project\..+?\.manager\..+?</value>
                   </list>
              </property>
         </bean>
         <bean id="autoBeanCreatorFactoryDao" class="com.j6.framework.resource.AutoBeanCreatorFactory">
              <property name="packagePatterns">
                   <list>
                        <value>com\.j6\.project\..+?\.dao\.hibernate.+?</value>
                   </list>
              </property>
         </bean>Feel free to have a look and gv some comments. Thanks :)
    Regards,
    Jimmy6
    Edited by: jimmy6 on Nov 4, 2008 8:15 AM

  • How can I remove available downloads?

    How can I remove available downloads?

    This forum is for questions from those managing sites on iTunes U, Apple's service for colleges and universities to post educational material in the iTunes Store. You'll be most likely to get help with this issue if you ask in the general iTunes forums.
    Regards.

  • Let me know how to run high availability services in system 9 essbase.

    Hi
    Let me know how to run high availability services in system 9 essbase.
    thanks in ADV
    Message was edited by:
    user624564
    Message was edited by:
    user624564

    Hi,
    Now i am using essbase system 9.2 version,
    & URL : http://localhost:11080/eds/EssbaseEnterprise
    plz guide me to download the High Availability servers .
    thanks in Adv....

  • How many movies are available

    I'm considering an ATV. How many movies are available for rent? Is it the same catalog as in iTunes or is there more on ATV?
    Thanks,
    NM

    i believe there is an un-official website that lists and updates when you movies are added.
    if you have a search thru the forum you will find it mentioned.

  • How to findout how many  instances are available in one server

    how many instances are available in one server

    You can also check (in Unix) /etc/oratab to list all Oracle instances, it should be updated. That's not so true...
    example:
    ps -aef | grep pmon | grep -v grep
    oracle   14867     1  0 Jul29 ?        00:00:00 ora_pmon_TEST9I
    oracle   15024     1  0 12:10 ?        00:00:00 ora_pmon_SECOND9I
    oracle   15172     1  0 12:11 ?        00:00:00 ora_pmon_THIRD9I
    cat /etc/oratab
    *:/opt/oracle/920:NThis topic was discussed here Oracle9i on Redhat and there you could find other suggestions.

  • How many verticals are available in OCOD

    Hello ,
    How many verticals are available in OCOD

    1. Lifesience-
    a. Pharma
    b. Medical
    2. Financial-
    a.GWM
    b.Insurance
    3. High Tech
    4. Automotive
    Some more to come..
    Hope this helps.
    Rgds,
    Amit Sahu

  • How to override confirmation fr sending sms? -urgent-

    I made an application that suppose to send an sms automatically. But it always prompts a confirmation question. How to override this? Thank you..

    This is a problem not only when sending to the few people without a data plan but for people roaming with their data connection disabled to control costs. Somehow, my iPhone can tell the other phone is an iPhone even with no data connection and tries to send an iMessage. It would be nice to be able to send a text message right away instead of waiting for the iMessage to fail or perhaps failing to notice that the "Delivered" notice did not appear.

  • HOW TO override/modify default PTG homepage?

    Hi:
    I want to know how to override default portal to go homepage. I've create my wireless app that is already well deployed in a container and already working in PTG. I want to know how to modify the default ptg home. I've removed all apps from ptg to the guests users and just give access to guest to my application. I need a simple default homepage and i need to remove the SETUP link that is always displayed in /PTG/RM page. Also, can anyone tell me how to create a simple url to access my wireless portal?
    for instance i have to write : portal.myorg.pt/ptg/rm and i would like to just hae to write : wire.morg.pt
    How can i achieve this?
    Thanks
    Joao

    I'm using a beta of 10G at the moment. What I did is change the oracle logo (logo.gif) with our own company's logo (http://host:port/ptg/images/logo.gif) (also the wbmp and png file) .
    If you can get access to the webtool http://host:port/webtool/login.uix you can click on the system tab and look for
    System > Wireless Server: Administration > Device (look at component configuration).
    From here you can enable/disable standard interface options
    Multi-Channel Server Setup Menu Configuration
    Enable Login
    Enable Logout
    Enable User Info
    Enable Application Customization
    Enable Global Preset
    Enable User Profile
    Enable Self Registration
    Enable User's Home Page
    Enable Help
    Help URL
    You can change the logon page and other pages on <oracle_home>\wireless\j2ee\applications\ptg\ptg-web\modules\login
    and
    <oracle_home>\wireless\j2ee\applications\ptg\ptg-web\modules\iaswfr
    I'm also curious if there is a more easy way to customize things.
    Thomas

  • How to override truncateToFit method for SuperTabNavigator

    Hi All,
               How to override truncateToFit method for SuperTabNavigator.
    we have editableLabel method for changing the tab name.
    it is dispalying the ... elipse when entered characters grater than the tab width. it is ok.
    but if the entered characters less than the tab width it is also appending the ... elipse.
    i dont want that . how to remove those. i dont want completely truncateToFit option.
    how to override .
    Can any help me regarding this?
    Thanks in Advance
    Raghu.

    Give me a sample codeNo. Read the links provided by Yannix, try it out for yourself, and if you still have a question, post the code you tried.
    db

Maybe you are looking for

  • Nokia Belle Email: I want a Small Widget like the ...

    Hi, the widget for Email Nokia Belle is too big and I don't like it. I want to install the small widget for Email like I had it on Anna OS in order to install 5 widgets in a single desktop. How can I get this small widget for Nokia Belle Email, pleas

  • How can we create a table with more than 64 fields in the default DB?

    Dear sirs, I am taking part in the process of migrating a J2ee application from JBoss to SAP Server. I have imported the ejb project. I have an entity bean with 79 CMP fields. i have created the bean and created the table for the same also. but when

  • Block CIF differentiating data objects

    Hello, Following one of SAP recommendation, we are blocking the Inbound CIF Queues every time we run the SNP Optimizer in the active version. To do this, we are using the report /SAPAPO/CIFSTOPQUEUES. In this report it is necessary to use a Queue Nam

  • Adjusting Black (K) while in RGB mode?

    Ok, so basically I'm wokring on an image in RGB mode, and I have my INFO box open, and I have the sample picker #1 and #2 set to display CMYK values. I'm not sure if many people realize that even if you're in RGB mode you can actually view other colo

  • Flash Player Question - Re Powerpoint

    We've produced a powerpoint presentation that incorporates lots of flash within it. we have hit a problem with distributing this powerpoint via cdrom in that we need to include the appropriate flash player installation program. so that it installs th