while ( in.ready() );
    protected synchronized Packet readPacket() {        try {            StringBuffer buf = new StringBuffer();            /* BEGIN Debug code BEGIN **            // Write to a test file.            buf.append( "read" )                .append( this.getId() )                .append( ".txt" );            Writer test = new BufferedWriter                ( new FileWriter(buf.toString(), true) );            buf = new StringBuffer();            /*  END  Debug code  END  */            // There's a race condition in creating this object.            while (in == null) {                wait(100);                // We can't simply pass the socket's InputStream to the parser,                // as it expends and end-of-transmission to stop parsing.                in = new BufferedReader                    ( new InputStreamReader(socket.getInputStream()) );            }            // Wait for a packet.            // N.B. I can't get blocking to work so I'm going to poll.            while ( !in.ready() ) {                wait(100);            }            // Read the entire transmission.            while ( in.ready() ) {                // Read and store the character.                final int inChar = in.read();                buf.append( (char) inChar );            }            /* BEGIN Debug code BEGIN **                // Write the character to the test file.                test.write( inChar );            }            while ( in.ready() ); // do we keep this line?            // Finish off the file.            test.flush();            test.close();            /*  END  Debug code  END  */            // Now decode the packet from the XML.                        ParsedXML root = TinyParser.parseXML                 ( new ByteArrayInputStream(buf.toString().getBytes()) );            Enumeration rootChildren = root.elements();            if ( !rootChildren.hasMoreElements() ) {                throw new ParseException( "No children of the root." );            }            ParsedXML rootNode = (ParsedXML)rootChildren.nextElement();            Packet packet = PacketEncoder.decode( rootNode, null );            return packet;        } catch (IOException ex) {            System.err.print( "server(" );            System.err.print( getId() );            System.err.println( "): IO error reading command" );            server.disconnected(this);            return null;        } catch (ParseException parseEx) {            System.err.print( "server(" );            System.err.print( getId() );            System.err.println( "): Could not parse data" );            parseEx.printStackTrace( System.err );            return null;            /* BEGIN Debug code BEGIN */        } catch (InterruptedException intEx) {            System.err.print( "server(" );            System.err.print( getId() );            System.err.println( "): Interrupted waiting for data" );            server.disconnected(this);            return null;            /*  END  Debug code  END  */        }    }