public void run()

in tcpmon/src/main/java/org/apache/axis/utils/tcpmon.java [617:823]


        public void run() {
            try {
                byte[]      buffer = new byte[4096];
                byte[]      tmpbuffer = new byte[8192];
                String      message = null;
                int         saved = 0 ;
                int         len ;
                int         i1, i2 ;
                int         i ;
                int         reqSaved = 0 ;
                int         tabWidth = 3 ;
                boolean     atMargin = true ;
                int         thisIndent = -1,
                    nextIndent = -1,
                    previousIndent = -1;

                //if ( inSocket  != null ) inSocket.setSoTimeout( 10 );
                //if ( outSocket != null ) outSocket.setSoTimeout( 10 );

                if ( tmodel != null ) {
                    String tmpStr = (String) tmodel.getValueAt(tableIndex,
                            REQ_COLUMN);

                    if ( !"".equals(tmpStr) ) {
                        reqSaved = tmpStr.length();
                    }
                }

            a:
                for ( ; ; ) {
                    if ( done ) {
                        break;
                    }
                    //try{
                    //len = in.available();
                    //}catch(Exception e){len=0;}
                    len = buffer.length ;
                    // Used to be 1, but if we block it doesn't matter
                    // however 1 will break with some servers, including apache
                    if ( len == 0 ) {
                        len = buffer.length;
                    }
                    if ( saved + len > buffer.length) {
                        len = buffer.length - saved ;
                    }
                    int len1 = 0;

                    while ( len1 == 0 ) {
                        try {
                            len1 = in.read(buffer, saved, len);
                        }
                        catch ( Exception ex ) {
                            if ( done && saved == 0  ) {
                                break a;
                            }
                            len1 = -1;
                            break;
                        }
                    }
                    len = len1;

                    if ( len == -1 && saved == 0 ) {
                        break ;
                    }
                    if ( len == -1) {
                        done = true;
                    }

                    // No matter how we may (or may not) format it, send it
                    // on unformatted - we don't want to mess with how its
                    // sent to the other side, just how its displayed
                    if ( out != null && len > 0 ) {
                        slowLink.pump(len);
                        out.write( buffer, saved, len );
                    }

                    if ( tmodel != null && reqSaved < 50 ) {
                        String old = (String) tmodel.getValueAt( tableIndex,
                                REQ_COLUMN);

                        old = old + new String(buffer, saved, len);
                        if ( old.length() > 50 ) {
                            old = old.substring(0, 50);
                        }

                        reqSaved = old.length();

                        if ( (i = old.indexOf('\n')) > 0 ) {
                            old = old.substring(0, i - 1);
                            reqSaved = 50 ;
                        }

                        tmodel.setValueAt( old, tableIndex, REQ_COLUMN );
                    }

                    if ( xmlFormat ) {
                        // Do XML Formatting
                        boolean inXML = false ;
                        int     bufferLen = saved ;

                        if ( len != -1 ) {
                            bufferLen += len ;
                        }
                        i1 = 0 ;
                        i2 = 0 ;
                        saved = 0 ;
                        for ( ; i1 < bufferLen ; i1++ ) {
                            // Except when we're at EOF, saved last char
                            if ( len != -1 && i1 + 1 == bufferLen ) {
                                saved = 1;
                                break;
                            }
                            thisIndent = -1;
                            if ( buffer[i1] == '<' && buffer[i1 + 1] != '/' ) {
                                previousIndent = nextIndent++;
                                thisIndent = nextIndent;
                                inXML = true ;
                            }
                            if ( buffer[i1] == '<' && buffer[i1 + 1] == '/' ) {
                                if (previousIndent > nextIndent) {
                                    thisIndent = nextIndent;
                                }
                                previousIndent = nextIndent--;
                                inXML = true ;
                            }
                            if ( buffer[i1] == '/' && buffer[i1 + 1] == '>' ) {
                                previousIndent = nextIndent--;
                                inXML = true ;
                            }
                            if ( thisIndent != -1 ) {
                                if ( thisIndent > 0 ) {
                                    tmpbuffer[i2++] = (byte) '\n';
                                }
                                for ( i = tabWidth * thisIndent; i > 0; i-- ) {
                                    tmpbuffer[i2++] = (byte) ' ';
                                }
                            }
                            atMargin = ( buffer[i1] == '\n' || buffer[i1] == '\r');

                            if ( !inXML || !atMargin ) {
                                tmpbuffer[i2++] = buffer[i1];
                            }
                        }
                        message = new String( tmpbuffer, 0, i2, getEncoding() );
                        if (numericEnc) {
                            textArea.append( StringUtils.escapeNumericChar(message) );
                        } else {
                            textArea.append( StringUtils.unescapeNumericChar(message) );
                        }

                        // Shift saved bytes to the beginning
                        for ( i = 0 ; i < saved ; i++ ) {
                            buffer[i] = buffer[bufferLen - saved + i];
                        }
                    }
                    else {
                        message = new String( buffer, 0, len, getEncoding() );
                        if (numericEnc) {
                            textArea.append( StringUtils.escapeNumericChar(message) );
                        } else {
                            textArea.append( StringUtils.unescapeNumericChar(message) );
                        }
                    }
                // this.sleep(3);  // Let other threads have a chance to run
                }
            // this.sleep(3);  // Let other threads have a chance to run
            // halt();
            // Only set the 'done' flag if we were reading from a
            // Socket - if we were reading from an input stream then
            // we'll let the other side control when we're done
            //      if ( inSocket != null ) done = true ;
            }
            catch ( Throwable t ) {
                t.printStackTrace();
            }
            finally {
                done = true ;
                try {
                    if (out != null) {
                        out.flush();
                        if (null != outSocket) {
                            outSocket.shutdownOutput();
                        } else {
                            out.close();
                        }
                        out = null;
                    }
                }
                catch (Exception e) {
                    ;
                }
                try {
                    if (in != null) {
                        if (inSocket != null) {
                            inSocket.shutdownInput();
                        } else {
                            in.close();
                        }
                        in = null;
                    }
                }
                catch (Exception e) {
                    ;
                }
                myConnection.wakeUp();
            }
        }