Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Static Public Attributes | Protected Attributes | Package Attributes | Static Package Attributes
Connection Class Reference
Collaboration diagram for Connection:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Connection (Socket client_socket)
final void run ()

Public Attributes

Socket client

Static Public Attributes

static final boolean DEBUG = true

Protected Attributes

BufferedReader in
PrintWriter out

Package Attributes

StringBuffer request

Static Package Attributes

static final String SERVER = "HTTP Test Server/1.1"

Detailed Description

Definition at line 41 of file Connection.java.


Constructor & Destructor Documentation

Connection.Connection ( Socket  client_socket) [inline]

Definition at line 50 of file Connection.java.

                                            {
              client = client_socket;

              if (DEBUG)
              {
                     System.out.println(
                         "---------------------------------------------------------");
                     System.out.println(client);
              }
              try {
                     in = new BufferedReader(new InputStreamReader(
                            client.getInputStream()));
                     out = new PrintWriter(client.getOutputStream());
                     this.start();
              }
              catch (IOException e) {
                     try {
                            client.close();
                     }
                     catch (IOException another) {
                     }
                     System.out.println("Exception while getting socket streams."
                            + e);
              }
       }

Member Function Documentation

final void Connection.run ( ) [inline]

Definition at line 76 of file Connection.java.

                               {

              String line = null;
              String firstline = null;
              request = new StringBuffer();

              int len = 0;
        int extralen= 0;
              try {
                     while(true) {
                            if (!in.ready()) {
                                   continue;
                         }
                line = in.readLine();
                            if (line == null)
                                   break;
                            if (firstline == null)
                                firstline = new String(line);
                            len = line.length();
                if (line.regionMatches(true, 0,
                        "Content-length: ", 0, 16)) {
                    extralen = Integer.valueOf(line.substring(16,
                        line.length())).intValue();
                }
                            if (len == 0)
                {
                    // Now read only the extralen if any-
                    if (extralen > 0)
                    {
                        char[] postbuffer = new char[extralen];
                        in.read(postbuffer);
                        request.append("\n");
                        request.append(postbuffer);
                        if (DEBUG) {
                            System.out.println();
                            System.out.println(postbuffer);
                        }
                    }
                    break;
                }
                request.append(line);
                            request.append("\n");
                            if (DEBUG)
                                System.out.println(line);
                     }
            // This will appropriately write all the stuff based
            // on the first line and the script file
            ScriptFile sf = new ScriptFile(this, firstline, out);
              out.flush();
              // mark for garbage collect
              sf = null;
              } // try
              catch (IOException e) {
                     System.out.println("Some problem while communicating. " + e);
              }
              finally {
                     try {
                            client.close();
                     }
                     catch (IOException e2) {
                     }
              }
       }

Here is the call graph for this function:


Member Data Documentation

Definition at line 44 of file Connection.java.

final boolean Connection.DEBUG = true [static]

Definition at line 43 of file Connection.java.

BufferedReader Connection.in [protected]

Definition at line 45 of file Connection.java.

PrintWriter Connection.out [protected]

Definition at line 46 of file Connection.java.

StringBuffer Connection.request [package]

Definition at line 139 of file Connection.java.

final String Connection.SERVER = "HTTP Test Server/1.1" [static, package]

Definition at line 48 of file Connection.java.


The documentation for this class was generated from the following file: