InputStream available() variance in functionality

We have a Webservice program which sends a SOAP request with OutputStream and captures the SOAP response with InputStream. We are using available() method of InputStream to fetch the input response. This method used to work correctly for the below OS and Java version
[user2@HENDRIX ~]$ java -version
java version "1.5.0_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
Java HotSpot(TM) 32-Bit Server VM (build 1.5.0_05-b05, mixed mode
We have upgraded the system to below version and the webservice program is stripping off the SOAP request to some extend and unable to fetch the full SOAP XML response
[user1@HERMES ~]$ java -version
java version "1.6.0_11"
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot(TM) 64-Bit Server VM (build 11.0-b16, mixed mode)
But the same program without change in the code worked for earlier versions. Please let us know do we have any change in the available() method behaviour.

Sounds like you are expecting available() to return the length of the stream. It cannot be reliably used for this process and should never have been used in the first place. [available()|http://java.sun.com/j2se/1.4.2/docs/api/java/io/InputStream.html#available%28%29] return the number of bytes that can be read without blocking and says nothing about how may bytes the stream contains.

Similar Messages

  • 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.

  • Is numlock still available in the Function keys (F1-F12)

    Hi all,
    I have to use the numpad very frequently, so I would like to know if there is any way I can use the numeric keypad in the new Macbook?
    Is the old numlock button still available in the Function Keys (F1-F12)?
    Thanks

    I'm not precisely sure about the situation with the ']' key. It sounds as if perhaps the keyboard doesn't match the language or region of the system. Without knowing more, the first place to go would be the Keyboard tab in the Keyboard preferences pane.
    There are buttons there to set the type of keyboard connected, and also check the settings of the modifier keys, including 'Caps Lock', 'Shift', 'Command', and 'Option'.
    As far as setting keyboard shortcuts for 'F' keys, if you go to the *Keyboard Shortcuts* tab in the Keyboard preference pane and click on the categories in the left column, you should be able to see current settings, and define new ones if necessary.
       !http://img228.imageshack.us/img228/5186/scottdartve1.png!

  • 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?

  • InputStream.available()

    Hi,
    InputStream is = socket.getInputStream();
    int n = is.available();
    n don't return number of bytes available in the InputStream, it is always 0.
    Why?
    ~Hill

    available is not a good function to use because it's behavior is badly defined.
    It is not implemented correctly in many input streams. This is because of the nature of the streams, they generally are not buffered very well in the lower systems. The InputStream api says that the available function SHOULD be overridden but is doesn't have to be.
    Especially now with the new NIO classes, you don't need to use this functionality at all. This is one of the reasons that the NIO was created, as if this functionality actually worked correctly, one of the main reason for NIO ( the problem of one reader per thread ) would be eliminated.

  • InputStream.available() doen't work always

    I have a remote HTTP resource of 11kb that I want to retrieve through InputStream obtained from HttpURLConnection (of J2SE) and HttpConnection (of J2ME).
    If I download it byte after byte with this code ("is" is InputStream instance from Http) :
    int ch;
    ByteArrayOutputStream f = new ByteArrayOutputStream();
    while ((ch = is.read()) != -1)
    f.write((byte)ch);
    it works fine on J2ME on my mobile phone (Nokia 6680), with WirelesseToolkit Emulator and also in my J2SE application.
    But if I try to fetch the resource with read(array) it works only on my Nokia 6680 and not in WIrelessToolkit Emulator and J2SE application.
    The code I used is this:
    int byteDisp = is.available();
    byte[] arraySwap = new byte[byteDisp];
    is.read(arraySwap);
    The problem is that is.available doesn't give me the actual value of bytes of my remote resource when I use the code on my desktop pc (with J2ME emulator or J2SE application). So I think that the problem is caused by Internet connection because it works fine on my mobile phone.
    Can you help me?
    I don't want to use the while with the byte read.
    Thanks you,
    ReX

    >
    Now it works fine everytime and everywhere, do you
    think that this solution could give me some
    problems?The loop means that the CPU is doing work it doesn't need to.
    You can solve this by doing something like the following pseudo code demonstrates.
        byte buffer = new byte[1];  // Note the '1'
       socket.ReadBlock(buffer) // Read only one byte and block till we get it
       AccumlateMessage(buffer)
       while(socket.available)
           buffer = new byte[socket.AvailableSize];
           socket.ReadBlock(buffer)
           AccumlateMessage(buffer)
    For the above you can choose a value besides '1' if it seems reasonable for the actual protocol that you are using and with the possible error cases taken into account.

  • Determine Available Parameters for Function

    Hello, I would like to call an OA Framework page from within EBS forms. From the OA Framework Developer's Guide, I understand I can do this by calling fnd_function.execute() with the function name. I know how to get the function name, however I do not know how to tell what parameters are available. Is there a form in EBS that show this or another method to tell without having to write code?
    Thanks

    Hi,
        Use changing in perform.
        perform data_check changing w_field.
       form data_check changing w_field1.
          * use your FMOD here
          * pass the value from funmod to w_field.
       endform.
    Thanks & Regards,
    Krishna...

  • /DSD/VC_VP_CREATE - AVAILABLE BAPI or FUNCTION MODULE/HOW To BATCH INPUT

    I have a problem with this this transaction /DSD/VC_VP_CREATE I Cannot control the Drag and Drop for Customer in this Transaction when doing a Batch Input Is there a way to control it in Batch Input? Is there Available BAPI/Function Module for This Visit Plan(/DSD/VC_VP_CREATE) Transaction?

    Hi,
    did you find any BAPI/FM?
    Because i need exactly the same - find FM/BAPI/method to create acceptance request like via F881

  • UD CODE OF RESPECTIVE PLAN SHOULD BE AVAILABLE IN F4 FUNCTION

    Hi Guys,
    I have made the configuration for the U.D code for each Inspection type. Based on the origin of inspection I want only respective U.D code should show in the F4 function.
    Eg: If the Origin of inspection lot is G.R then in U.D code F4 function I want only 01-Goods Receipt Insp'n for P.O and  A for acceptence or R for Rejection. presently system is showing pany U.D code out of which I have to select the one which I have created for my plant.
    Please let me know where I can put the filtering paprameters.
    Thanks,
    Dhanu

    Dear Dhanu,,
    In config pls maintain the following
    SPRO > Quality Inspection > maintain inspection type > choose the inspection type >
    1) Maintain UD selected set
    2) Tick selected set in Same Plant
    Revert woth feedback
    Regards
    gajesh

  • Does ipad2 5.0.1 available for call function?

    Ipad2 5.0.1 04.11.08 does it have a call function?

    No. Only the iPhone can make phone calls. On the iPad, FaceTime can make video calls, or you can make Skype calls if you download the Skype app. But there is no native call function on the iPad.

  • Create Web Service Option not available for BAPI Functional Module

    Hello Experts
    I am trying to create a web service from a standard BAPI functional module referring following document
    http://help.sap.com/saphelp_nw04/Helpdata/EN/e9/ae1b9a5d2cef4ea4b579f19d902871/content.htm
    I am facing the same issue as mentioned in this thread (But for me answer is not OK)
    Web Service Creation
    When I click the FLIGHT Business Object and navigate to the Tools tab, I cannot see Create Web Service option.
    Also when I try to start the web service wizard from (SE37 -> BAPI_FLIGHT_GETLIST) Utilities Menu, after specifying all the details, after clicking Finish, I get an error "Access Refused"
    I verified the authorization to current user and gave him all the authorization required viz. (SAP_BC_WEBSERVICE_ADMIN, SAP_BC_WEBSERVICE_ADMIN_BIZ, SAP_BC_WEBSERVICE_CONSUMER etc) all 7 of them.
    My system is ECC 6.0 700 Release
    Thanks
    Paresh

    Hello,
    For creating Web service definition, you have to be a registered developer. In SAP Service Market place, you will get developer access key. This should be entered in DEVACCESS table by creating any development object.
    Thanks,
    Venu

  • InputStream available() question

    Crosspost
    Is it unusual for an input stream to say that there are X bytes available but when calling
      int foo = in.read(myArray, intstart, myArray.length);to read less than the available?
    foo = X - something?
    Thanks

    Thank you for the response. This is exactly what I'm
    seeing though. I find it puzzling.
    byte[] buffer = new byte[512];
    int MAX = in.available();  // This is returning 972
    bytes
    if(MAX > buffer.length) MAX = buffer.length;
    intTotal = in.read(buffer, 0, MAX);  // intTotal =
    155 ???Should I be looking elsewhere for the issue. The
    stream is from a data socket.can u try this
    int MIN = in.available();
    buffer = new byte[MIN];
    intTotal = in.read(buffer, 0, MIN);

  • Function Module available to get Stock lying against a Sale-Order

    Dear Sir,
    We have function module "KPKA_UTILS_PROJECT_STOCK_CHECK" for getting Stock lying against a WBS (Project Stock) .
    We are looking for a function module to get the Stock lying against a Sale-Order (Sale-Order plus it's Line Item) .
    We request SAP experts to kindly guide us about the availability of such Function Module please .
    We will award full points for the suggested solution pl .
    Rgds
    B Mittal

    Hi
    table MSKA - Sales Order Stock is availble whcih will give the Stock pertainig to a sales Order & line item.
    Hope this helps
    Thanks & Regards
    Kishore

  • Enabling the printing function of your HP Laserjet M1005 printer

    If you wonder how to install the printing function of your HP Laserjet M1005 printer, here is listed a bullet list of the actions. This has just been tested out thanks to the Support team from Germany
    Go to the page http://h20000.www2.hp.com/bizsupport/TechSupport/DriverDownload.jsp?prodNameId=1 839459&lang=en&cc=us&prodTypeId=18972&prodSeriesId=1839458&taskId=135 and select the link Mac OS X; download the link "HP LaserJet M1005 MFP Mac OS X Full Software Solution"
    Use the opportunity to update your printer firmware by selecting the link "Printer Firmware Update"
    Shutdown your Mac and start up in the safe boot mode (should be the combined keyboard shift and power on/off - refer to the Apple web site for details)
    Run the downloaded SW package listed in the step 1
    Go and select under system settings printer and fax, follow the step-by-step instructions to have a printer installed
    Shutdown your Mac and start up again in the safe boot mode
    Connect your printer and the printer SW installation message shoud pop up requesting you to install it
    SW download process should appear and run
    Be aware that just the printing function will be available - no scanning function so far
    For those who may be interested in knowing why safe boot mode: it is likelz that my anti-virus SW Kaspersky denied the installation.
    Continue to enjoy your HP Laserjet M1005 printer

    "For those who may be interested in knowing why safe boot mode: it is likelz that my anti-virus SW Kaspersky denied the installation."
    You should read this:
    http://www.reedcorner.net/mmg-antivirus/

  • Material availability check be switched off for during dispatching of order

    Hi All,
    Material availability u2013 can the material availability check be switched off during  dispatching of production order but kept when order is created? 
    Is there any implications on availibilty check.
    How can we do this?
    Regards,
    Vidyasagar

    Dear
    If you want to do Material Availablity Check only at the time of order creation , please choose Availability Check Business Function 1  with your order type  /plant combination .Keep No Check  in Capacity  and do not assing  the Overall Capacity Profile Here .
    Where as keep the Capacity Overall Profile for Production Order Type with Availablity Check  -2  and Mark No Check to material availablity  option in the same .
    In OPKP -make sure that you have Capacity Profile assinged and do not mark Confirm Partial Available Qty .
    How ever , in capacity requirement , material availablity is the intregrated part  and while dispathcing production order with in the available capacity of any operation in work centre , system tries to make sure the materials are available for processing just before actual operation starts .
    Check in CM21-Setting-Strategy -Dispatch Control -Check if you have option to un-check the Material Availability .
    Regards
    JH

Maybe you are looking for

  • Authorization issue BI 7.0

    Dear all, in our dev-system we have the authorization SAP_ALL and S_A.SYSTEM. Which profile do we need furthermore regarding BI 7.0, because eg. we get authoritazion error for infosource (democube) 0D_DECU and can not open queries. Thanks in advance

  • Some Questions I Have About the GE70 Apache Pro

    Hi Y'all,     I'm new here to the MSI Community and am looking to make my first purchase of a MSI Notebook.   I'm looking at the new GE 70 Apache Pro because of the budget I have to work with thanks to having to go out and spend $6K to get my car fix

  • How do I deactivate CS3 when I get an error message that I'm not connected to the internet, when I am?

    Trying to deactivate CS3 from one computer to reload on another. Keep getting error message that I'm not connected to the internet.

  • OnEntry onExit functionality for Interactive Activities

    Does anyone know how to set onEntry and onExit kind of functionality for interactive activities in ALBPM 5.7 It is easy to add automatic activities before and after interactivity to do same job but then it starts cluterring the process if we have too

  • Trial Help

    I downloaded the new Flash Builder 4.5 PHP Standard, but when I installed it it said it was the premium version.  After running the install I opened the program and it said that I needed to install Zend.  There was a tab for Zend so I installed it.