DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5827>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5827

DataInputStream.readInt returns wrong values

           Summary: DataInputStream.readInt returns wrong values
           Product: Tomcat 4
           Version: 4.0 Beta 1
          Platform: PC
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Major
          Priority: Other
         Component: Catalina
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


We are using HTTP POST command to open a stream and pass a few arguments 
between a client and a servlet. Our client uses Java's core 
DataOutputStream.writeInt to send the binary data (configuration parameters). 
The servlet code is pretty straightforward - just create a DataInputStream and 
read out the values. Apparently, the integers are translated into different 
values.

Consider the following:
>From TryServlet.java:
void process (String method,
                 HttpServletRequest req,
                 HttpServletResponse res) throws ServletException, IOException {
   try {
      DataInputStream dis = new DataInputStream(req.getInputStream());        
int b;

                while (true) {
                                
                        b = dis.readInt();
                        /*b = ((dis.readByte() & 0xFF) << 24) | 
                            ((dis.readByte() & 0xFF) << 16) |
                            ((dis.readByte() & 0xFF) << 8) |
                            (dis.readByte() & 0xFF);*/

                        //b = dis.readByte();


                        l++;
                        //input += Integer.toBinaryString(b);
                        input += "" + b;
                }
        }
        catch (Exception e) {
                System.out.println("Exception while reading input " + e); 
        }
        System.out.println("Received raw input of length " + l + " \"" + input 
+ "\"");

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to