Esempio n. 1
0
 public void addScore() {
   try {
     out88.writeUTF("加分");
     out88.flush();
     out88.writeUTF("");
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Esempio n. 2
0
 public void cutScore(String whom) {
   try {
     out88.writeUTF("减分");
     out88.flush();
     out88.writeUTF("");
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
 public void serialize(TreeRequest request, DataOutputStream dos, int version)
     throws IOException {
   dos.writeUTF(request.sessionid);
   CompactEndpointSerializationHelper.serialize(request.endpoint, dos);
   dos.writeUTF(request.cf.left);
   dos.writeUTF(request.cf.right);
   if (version > MessagingService.VERSION_07)
     AbstractBounds.serializer().serialize(request.range, dos);
 }
Esempio n. 4
0
 protected void write(DataOutputStream out) throws IOException {
   out.writeUTF(allocationMode.name());
   out.writeInt(length());
   out.writeUTF(dataType().name());
   if (dataType() == Type.DOUBLE) {
     for (int i = 0; i < length(); i++) out.writeDouble(getDouble(i));
   } else {
     for (int i = 0; i < length(); i++) out.writeFloat(getFloat(i));
   }
 }
Esempio n. 5
0
 /** @param args the command line arguments */
 public static void main(String[] args) throws Exception {
   BufferedReader br =
       new BufferedReader(new InputStreamReader(new FileInputStream("/var/song.txt"), "UTF-8"));
   Map map = new TreeMap();
   String line = null;
   while ((line = br.readLine()) != null) {
     System.out.println("line:" + line);
     try {
       String[] strs = line.split("\t");
       String str = " ";
       if (strs != null && strs.length >= 2) str = strs[1];
       map.put(new Integer(strs[0]), str);
     } catch (Exception e) {
       System.out.println("Opuszczam linie " + e.toString());
     }
   }
   DataOutputStream dos = new DataOutputStream(new FileOutputStream("/var/song.bin"));
   dos.writeInt(map.size());
   for (Iterator it = map.keySet().iterator(); it.hasNext(); ) {
     Integer pos = (Integer) it.next();
     String txt = (String) map.get(pos);
     dos.writeInt(pos.intValue());
     dos.writeUTF(txt);
   }
   dos.flush();
   dos.close();
 }
Esempio n. 6
0
 public void outputBinary(DataOutputStream dos) throws IOException {
   dos.writeInt(samples.size());
   for (String s : samples) {
     dos.writeUTF(s);
   }
   dos.writeInt(cols.size());
   for (Column c : cols) {
     c.outputBinary(dos);
   }
 }
 /**
  * Write string to named file.
  *
  * @param f File to write too
  * @param contenet String to write
  * @exception IOException if we fail to save our string
  */
 private void putContent(String f, String content) throws IOException {
   DataOutputStream out = null;
   try {
     out = new DataOutputStream(new FileOutputStream(new File(bundleDir, f)));
     out.writeUTF(content);
   } finally {
     if (out != null) {
       out.close();
     }
   }
 }
Esempio n. 8
0
  void send(String msg) {
    Iterator it = clients.keySet().iterator();

    while (it.hasNext()) {
      try {
        DataOutputStream out = (DataOutputStream) clients.get(it.next());
        out.writeUTF(msg);
      } catch (IOException e) {
      }
    }
  }
 public void displayMenu() throws Exception {
   while (true) {
     System.out.println("[ MENU ]");
     System.out.println("1. Send File");
     System.out.println("2. Receive File");
     System.out.println("3. Exit");
     System.out.print("\nEnter Choice :");
     int choice;
     choice = Integer.parseInt(br.readLine());
     if (choice == 1) {
       dout.writeUTF("SEND");
       SendFile();
     } else if (choice == 2) {
       dout.writeUTF("GET");
       ReceiveFile();
     } else {
       dout.writeUTF("DISCONNECT");
       System.exit(1);
     }
   }
 }
Esempio n. 10
0
 public void writeHtmlParts(File filename) throws IOException {
   DataOutputStream dataOut = null;
   try {
     dataOut = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(filename)));
     dataOut.writeInt(htmlParts.size());
     for (String part : htmlParts) {
       dataOut.writeUTF(part);
     }
   } finally {
     SpringIOUtils.closeQuietly(dataOut);
   }
 }
  void SendFile() throws Exception {

    String filename;
    System.out.print("Enter File Name :");
    filename = br.readLine();

    File f = new File(filename);
    if (!f.exists()) {
      System.out.println("File not Exists...");
      dout.writeUTF("File not found");
      return;
    }

    dout.writeUTF(filename);

    String msgFromServer = din.readUTF();
    if (msgFromServer.compareTo("File Already Exists") == 0) {
      String Option;
      System.out.println("File Already Exists. Want to OverWrite (Y/N) ?");
      Option = br.readLine();
      if (Option == "Y") {
        dout.writeUTF("Y");
      } else {
        dout.writeUTF("N");
        return;
      }
    }

    System.out.println("Sending File ...");
    FileInputStream fin = new FileInputStream(f);
    int ch;
    do {
      ch = fin.read();
      dout.writeUTF(String.valueOf(ch));
    } while (ch != -1);
    fin.close();
    System.out.println(din.readUTF());
  }
Esempio n. 12
0
  public void outputBinary(DataOutputStream dos) throws IOException {
    dos.writeUTF(id);
    dos.writeInt(values.size());

    int i = 0, j = 0;
    while (i < values.size()) {
      for (j = i; j < values.size() && values.get(j) != null; j++) {}
      int count = j - i - 1;
      dos.writeInt(count);
      for (j = 1; j <= count && i + j < values.size(); j++) {
        dos.writeFloat(values.get(i + j));
      }
      i = j + 1;
    }
  }
Esempio n. 13
0
  public void nick_name(String msg) {
    try {
      String name = msg.substring(13);
      this.setName(name);
      Vector v = father.onlineList;
      boolean isRepeatedName = false;
      int size = v.size();
      for (int i = 0; i < size; i++) {
        ServerAgentThread tempSat = (ServerAgentThread) v.get(i);
        if (tempSat.getName().equals(name)) {
          isRepeatedName = true;
          break;
        }
      }
      if (isRepeatedName == true) {
        dout.writeUTF("<#NAME_REPEATED#>");
        din.close();
        dout.close();
        sc.close();
        flag = false;
      } else {
        v.add(this);
        father.refreshList();
        String nickListMsg = "";
        StringBuilder nickListMsgSb = new StringBuilder();
        size = v.size();
        for (int i = 0; i < size; i++) {
          ServerAgentThread tempSat = (ServerAgentThread) v.get(i);
          nickListMsgSb.append("!");
          nickListMsgSb.append(tempSat.getName());
        }
        nickListMsgSb.append("<#NICK_LIST#>");
        nickListMsg = nickListMsgSb.toString();
        Vector tempv = father.onlineList;
        size = tempv.size();
        for (int i = 0; i < size; i++) {
          ServerAgentThread tempSat = (ServerAgentThread) tempv.get(i);
          tempSat.dout.writeUTF(nickListMsg);
          if (tempSat != this) {
            tempSat.dout.writeUTF("<#MSG#>" + this.getName() + "is now online....");
          }
        }
      }

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Esempio n. 14
0
 private void sendResponse(long requestId, Object value, Class<?> declaredType)
     throws IOException {
   DataOutputStream out = newFlusher();
   out.writeByte(RESPONSE);
   out.writeLong(requestId);
   if (value == null) {
     out.writeBoolean(false);
   } else {
     out.writeBoolean(true);
     Class<?> clazz = value.getClass();
     out.writeUTF(clazz.getName());
     Serializer<Object> s = serializerFor(clazz, declaredType);
     s.serialize(out, value);
   }
   out.writeBoolean(false);
   out.flush();
 }
Esempio n. 15
0
  public void run() {

    while (true) {
      try {
        System.out.println(
            "TCP Server waiting for client on port " + serverSocket.getLocalPort() + "...");
        Socket server = serverSocket.accept();
        System.out.println("Just received request from " + server.getRemoteSocketAddress());

        /* parsing a request from socket */
        DataInputStream in = new DataInputStream(server.getInputStream());
        String request = in.readUTF();
        System.out.println("Request: " + request);

        /* handle the request */
        String output = null;
        output = requestHandler(request);
        System.out.print(output);

        /* display dataTable */
        System.out.print("-dataTable--------\n");
        Enumeration<String> key = dataTable.keys();
        while (key.hasMoreElements()) {
          String str = key.nextElement();
          System.out.println(str + ": " + dataTable.get(str));
        }
        System.out.print("------------------\n");

        /* send the result back to the client */
        DataOutputStream out = new DataOutputStream(server.getOutputStream());
        out.writeUTF(output);
        server.close();

      } catch (SocketTimeoutException s) {
        System.out.println("Socket timed out!");
        break;
      } catch (IOException e) {
        e.printStackTrace();
        break;
      }
    }
  }
Esempio n. 16
0
  public void run() {
    String objRouter = applet.getParameter("name");
    // No Internationalisation
    try {
      ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
      DataOutputStream outp = new DataOutputStream(byteStream);
      outp.writeInt(GenericConstants.ROUTER_PROPERTIES);
      outp.writeUTF(objRouter);
      outp.flush();

      byte[] bytes = byteStream.toByteArray();
      outp.close();
      byteStream.reset();
      byteStream.close();
      byte[] data = GenericSession.getInstance().syncSend(bytes);
      if (data != null) {
        DataInputStream inp = new DataInputStream(new ByteArrayInputStream(data));
        int reqId = inp.readInt();
        if (reqId == GenericConstants.ROUTER_PROPERTIES) {
          int length = inp.readInt();
          byte serverData[] = new byte[length];
          inp.readFully(serverData);
          routerobject = NmsClientUtil.deSerializeVector(serverData);
        }

        init();
        refresh();
        super.setVisible(true);
      }
      /*init();
      refresh();
      super.setVisible(true);*/

      else close();

    } catch (Exception e) {
      // NmsClientUtil.err(NmsClientUtil.getFrame(app),"IO Error sending request to server.
      // "+e);//No Internationalisation
    }
  }
  @SuppressWarnings("rawtypes")
  private static void writeObjectToStream(Object obj, DataOutputStream data) throws IOException {
    Class objClass = obj.getClass();

    if (objClass.equals(Boolean.class)) {
      data.writeBoolean((Boolean) obj);
    } else if (objClass.equals(Byte.class)) {
      data.writeByte((Byte) obj);
    } else if (objClass.equals(Integer.class)) {
      data.writeInt((Integer) obj);
    } else if (objClass.equals(String.class)) {
      data.writeUTF((String) obj);
    } else if (objClass.equals(Double.class)) {
      data.writeDouble((Double) obj);
    } else if (objClass.equals(Float.class)) {
      data.writeFloat((Float) obj);
    } else if (objClass.equals(Long.class)) {
      data.writeLong((Long) obj);
    } else if (objClass.equals(Short.class)) {
      data.writeShort((Short) obj);
    }
  }
  void ReceiveFile() throws Exception {
    String fileName;
    System.out.print("Enter File Name :");
    fileName = br.readLine();
    dout.writeUTF(fileName);
    String msgFromServer = din.readUTF();

    if (msgFromServer.compareTo("File Not Found") == 0) {
      System.out.println("File not found on Server ...");
      return;
    } else if (msgFromServer.compareTo("READY") == 0) {
      System.out.println("Receiving File ...");
      File f = new File(fileName);
      if (f.exists()) {
        String Option;
        System.out.println("File Already Exists. Want to OverWrite (Y/N) ?");
        Option = br.readLine();
        if (Option == "N") {
          dout.flush();
          return;
        }
      }
      FileOutputStream fout = new FileOutputStream(f);
      int ch;
      String temp;
      do {
        temp = din.readUTF();
        ch = Integer.parseInt(temp);
        if (ch != -1) {
          fout.write(ch);
        }
      } while (ch != -1);
      fout.close();
      System.out.println(din.readUTF());
    }
  }
Esempio n. 19
0
 public void send(String str) throws IOException {
   DataOutputStream dos = new DataOutputStream(s.getOutputStream());
   dos.writeUTF(str);
 }
Esempio n. 20
0
  /** Method to keep the connection alive with the name server */
  public void run() {
    boolean connected = false;
    int ticket = 0;
    int serial = -1;
    int time = 1000;

    DatagramPacket inPack = new DatagramPacket(new byte[1024], 1024);
    DatagramPacket outPack = new DatagramPacket(new byte[1024], 1024);

    ByteArrayOutputStream outBuf = new ByteArrayOutputStream();
    DataInputStream inData;
    DataOutputStream outData = new DataOutputStream(outBuf);

    while (running) {
      if (!connected) { // Thoust ought Register thine self
        try {
          outBuf.reset();
          outData.writeByte(0);
          outData.writeUTF(userName);
          outData.writeInt(portNum);
          outData.flush();
          outPack.setData(outBuf.toByteArray());
          nameServer.send(outPack);
        } catch (IOException e) {
          System.err.println("LeetActive: " + e);
        }
      } else { // Thoust ought Renew thine self
        try {
          outBuf.reset();
          outData.writeByte(2);
          outData.writeInt(ticket);
          outData.flush();
          outPack.setData(outBuf.toByteArray());
          nameServer.send(outPack);
        } catch (IOException e) {
          System.err.println(e);
        }
      }

      // Now we will receive a packet...
      try {
        nameServer.receive(inPack);
        inData = new DataInputStream(new ByteArrayInputStream(inPack.getData()));

        byte type = inData.readByte();

        if (type == 1) { // Twas a ticket packet
          try {
            ticket = inData.readInt();
            if (ticket > -1) { // Make sure its not evil
              connected = true;
            } else {
              connected = false;
            }
            time = inData.readInt();
          } catch (IOException e) {
            System.err.println(e);
          }
        }

        if (type == 5) { // Twas an update packet
          try {
            int s = inData.readInt();
            if (s > serial) { // Make sure its not old
              serial = s;
              int size = inData.readInt();
              ArrayList newList = new ArrayList(size);

              for (int x = 0; x < size; x++) {
                newList.add(
                    new String(
                        "" + inData.readUTF() + "@" + inData.readUTF() + ":" + inData.readInt()));
              }

              if (!newList.equals(hostList)) {
                hostList = newList;
                updated = true;
              }
            }
          } catch (IOException e) {
            System.err.println(e);
          }
        }
      } catch (SocketTimeoutException e) { // Server hates you
        connected = false;
        System.err.println(e);
      } catch (IOException e) {
        System.err.println(e);
      }

      try { // Take a nap
        sleep(time / 4);
      } catch (InterruptedException e) {
      }
    }
  }
Esempio n. 21
0
  public void saveToStorage() {

    DataOutputStream outputStream = NvStorage.CreateDataOutputStream();

    try {
      outputStream.writeInt(accountIndex);
      outputStream.writeBoolean(showOfflineContacts);
      outputStream.writeBoolean(fullscreen);
      outputStream.writeInt(def_profile);
      outputStream.writeBoolean(smiles);
      outputStream.writeBoolean(showTransports);
      outputStream.writeBoolean(selfContact);
      outputStream.writeBoolean(collapsedGroups);
      outputStream.writeBoolean(ignore);
      outputStream.writeBoolean(eventComposing);

      outputStream.writeInt(gmtOffset);
      outputStream.writeInt(locOffset);

      outputStream.writeBoolean(autoLogin);
      outputStream.writeBoolean(autoJoinConferences);

      outputStream.writeBoolean(popupFromMinimized);

      outputStream.writeBoolean(notifyBlink);
      outputStream.writeBoolean(memMonitor);

      outputStream.writeInt(font1);
      outputStream.writeInt(font2);

      outputStream.writeBoolean(autoFocus);

      outputStream.writeInt(notInListDropLevel /*keepAlive*/);

      outputStream.writeBoolean(storeConfPresence);

      outputStream.writeBoolean(capsState);

      outputStream.writeInt(textWrap);

      outputStream.writeInt(loginstatus);

      outputStream.writeUTF(msgPath);
      outputStream.writeBoolean(msgLog);
      outputStream.writeBoolean(msgLogPresence);
      outputStream.writeBoolean(msgLogConfPresence);
      outputStream.writeBoolean(msgLogConf);
      outputStream.writeBoolean(cp1251);

      outputStream.writeInt(autoAwayDelay);

      outputStream.writeUTF(defGcRoom);

      outputStream.writeBoolean(altInput);

      outputStream.writeInt(isbottom);

      outputStream.writeInt(confMessageCount);

      outputStream.writeBoolean(newMenu);

      outputStream.writeBoolean(lightState);

      outputStream.writeBoolean(notifySound);

      outputStream.writeBoolean(lastMessages);

      outputStream.writeBoolean(setAutoStatusMessage);

      outputStream.writeInt(autoAwayType);

      outputStream.writeBoolean(autoScroll);

      outputStream.writeBoolean(popUps);

      outputStream.writeBoolean(showResources);

      outputStream.writeBoolean(antispam);

      outputStream.writeBoolean(enableVersionOs);

      outputStream.writeInt(messageLimit);

      outputStream.writeUTF(lang);

      outputStream.writeBoolean(eventDelivery);

      outputStream.writeBoolean(transliterateFilenames);

      outputStream.writeBoolean(rosterStatus);

      outputStream.writeBoolean(queryExit);

      outputStream.writeBoolean(notifyPicture);
      outputStream.writeBoolean(showBalloons);

      outputStream.writeBoolean(userKeys);

      outputStream.writeInt(msglistLimit);

      outputStream.writeBoolean(useTabs);

      outputStream.writeInt(autoSubscribe);

      outputStream.writeBoolean(useBoldFont);

    } catch (Exception e) {
    }

    NvStorage.writeFileRecord(outputStream, "config", 0, true);
  }
Esempio n. 22
0
  /**
   * Process and loop until told to stop. A callback_done will stop the loop and will return a
   * result. Otherwise null is returned.
   */
  public Object run() throws CommandException {
    Object result = null;
    boolean shutdown = false;
    boolean closeWhenDone = true;
    Commands.ValueObject valueObject =
        new Commands.ValueObject(); // Working value object so not continually recreated.
    InvokableValueSender valueSender =
        new InvokableValueSender(); // Working valuesender so not continually recreated.
    try {
      boolean doLoop = true;

      /**
       * Note: In the cases below you will see a lot of finally clauses that null variables out.
       * This is because this is a long running loop, and variables declared within blocks are not
       * garbage collected until the method is terminated, so these variables once set would never
       * be GC'd. The nulling at the end of the case makes sure that any of those objects set are
       * now available for garbage collection when necessary.
       */
      while (doLoop && isConnected()) {
        byte cmd = 0;
        try {
          if (LINUX_1_3) socket.setSoTimeout(1000); // Linux 1.3 bug, see comment on LINUX_1_3
          cmd = in.readByte();
          if (LINUX_1_3 && isConnected())
            socket.setSoTimeout(0); // Linux 1.3 bug, see comment on LINUX_1_3
        } catch (InterruptedIOException e) {
          continue; // Timeout, try again
        }
        switch (cmd) {
          case Commands.QUIT_CONNECTION:
            doLoop = false;
            break; // Close this connection

          case Commands.TERMINATE_SERVER:
            doLoop = false;
            shutdown = true; // Shutdown everything
            break;

          case Commands.GET_CLASS:
            String className = in.readUTF();
            Class aClass = null;
            Class superClass = null;
            String superClassName = null;
            boolean added = false;
            try {
              aClass =
                  Class.forName(
                      className); // Turns out using JNI format for array type will work fine.

              added = server.getIdentityID(aClass, valueObject);
              boolean isInterface = aClass.isInterface();
              boolean isAbstract = java.lang.reflect.Modifier.isAbstract(aClass.getModifiers());
              superClass = aClass.getSuperclass();
              superClassName = (superClass != null) ? superClass.getName() : ""; // $NON-NLS-1$
              out.writeByte(Commands.GET_CLASS_RETURN);
              out.writeInt(valueObject.objectID);
              out.writeBoolean(isInterface);
              out.writeBoolean(isAbstract);
              out.writeUTF(superClassName);
              out.flush();
            } catch (ClassNotFoundException e) {
              valueObject.set();
              Commands.sendErrorCommand(out, Commands.GET_CLASS_NOT_FOUND, valueObject);
            } catch (ExceptionInInitializerError e) {
              sendException(e.getException(), valueObject, out);
            } catch (LinkageError e) {
              sendException(e, valueObject, out);
            } catch (Throwable e) {
              // Something bad, did we add a class? If we did remove it from the table.
              if (added) server.removeObject(server.getObject(valueObject.objectID));
              throw e;
            } finally {
              // clear out for GC to work.
              className = null;
              aClass = null;
              superClass = null;
              superClassName = null;
              valueObject.set();
            }
            break;

          case Commands.GET_CLASS_FROM_ID:
            int classID = in.readInt();
            try {
              aClass = (Class) server.getObject(classID);
              boolean isInterface = aClass.isInterface();
              boolean isAbstract = java.lang.reflect.Modifier.isAbstract(aClass.getModifiers());
              superClass = aClass.getSuperclass();
              superClassName = (superClass != null) ? superClass.getName() : ""; // $NON-NLS-1$
              out.writeByte(Commands.GET_CLASS_ID_RETURN);
              out.writeUTF(aClass.getName());
              out.writeBoolean(isInterface);
              out.writeBoolean(isAbstract);
              out.writeUTF(superClassName);
              out.flush();
            } catch (ClassCastException e) {
              valueObject.set();
              Commands.sendErrorCommand(out, Commands.CLASS_CAST_EXCEPTION, valueObject);
            } finally {
              // clear out for GC to work.
              aClass = null;
              superClass = null;
              superClassName = null;
              valueObject.set();
            }
            break;

          case Commands.GET_OBJECT_DATA:
            int objectID = in.readInt();
            Object anObject = null;
            try {
              anObject = server.getObject(objectID);
              valueObject.setObjectID(objectID, server.getIdentityID(anObject.getClass()));
              Commands.writeValue(out, valueObject, true);
            } catch (ClassCastException e) {
              valueObject.set();
              Commands.sendErrorCommand(out, Commands.CLASS_CAST_EXCEPTION, valueObject);
            } finally {
              anObject = null; // Clear out for GC to work
              valueObject.set();
            }
            break;

          case Commands.RELEASE_OBJECT:
            int id = in.readInt();
            server.removeObject(server.getObject(id));
            break;

          case Commands.NEW_INIT_STRING:
            classID = in.readInt(); // ID Of class to do new upon.
            String initString = in.readUTF(); // The init string.
            Object newValue = null;
            Class theClass = null;
            try {
              theClass = (Class) server.getObject(classID);
              if (theClass == null) {
                // The class wasn't found. So imply ClassNotFound exception.
                throw new ClassNotFoundException();
              }

              InitializationStringParser parser = null;
              try {
                parser = InitializationStringParser.createParser(initString);
                newValue = parser.evaluate();
                boolean primitive = parser.isPrimitive();
                // If expected class is Void.TYPE, that means don't test the type of the result
                // to verify if correct type, just return what it really is.
                if (theClass != Void.TYPE && primitive != theClass.isPrimitive()) {
                  valueObject.set();
                  Commands.sendErrorCommand(out, Commands.CLASS_CAST_EXCEPTION, valueObject);
                  continue; // Goto next command.
                }
                if (primitive) {
                  try {
                    // Need to do special tests for compatibility and assignment.
                    sendObject(
                        newValue,
                        classID != Commands.VOID_TYPE
                            ? classID
                            : server.getIdentityID(parser.getExpectedType()),
                        valueObject,
                        out,
                        true); // This will make sure it goes out as the correct primitive type
                  } catch (ClassCastException e) {
                    // The returned type is not of the correct type for what is expected.
                    valueObject.set();
                    Commands.sendErrorCommand(out, Commands.CLASS_CAST_EXCEPTION, valueObject);
                    continue; // Goto next command
                  }
                } else {
                  if (newValue != null) {
                    // Test to see if they are compatible. (Null can be assigned to any object,
                    // so that is why it was tested out above).
                    // If expected class is Void.TYPE, that means don't test the type of the result
                    // to verify if correct type, just return what it really is.
                    if (theClass != Void.TYPE && !theClass.isInstance(newValue)) {
                      // The returned type is not of the correct type for what is expected.
                      valueObject.set();
                      Commands.sendErrorCommand(out, Commands.CLASS_CAST_EXCEPTION, valueObject);
                      continue; // Goto next command
                    }
                  }
                  sendObject(
                      newValue, NOT_A_PRIMITIVE, valueObject, out, true); // Send out as an object.
                }
              } catch (InitializationStringEvaluationException e) {
                if (e instanceof EvaluationException) {
                  // Want to return the real exception.
                  sendException(e.getOriginalException(), valueObject, out);
                } else {
                  // Couldn't be evaluated, return an error for this.
                  setExceptionIntoValue(e.getOriginalException(), valueObject);
                  Commands.sendErrorCommand(out, Commands.CANNOT_EVALUATE_STRING, valueObject);
                }
              } finally {
                parser = null; // Clear out for GC to work
              }
            } catch (Throwable e) {
              sendException(e, valueObject, out);
            } finally {
              // Clear out for GC to work
              initString = null;
              theClass = null;
              newValue = null;
              valueObject.set();
            }
            break;

          case Commands.INVOKE:
            Object target = null;
            Object[] parms = null;
            Class returnType = null;
            java.lang.reflect.Method aMethod = null;
            try {
              int methodID = in.readInt(); // ID of method to invoke
              aMethod = (java.lang.reflect.Method) server.getObject(methodID); // Method to invoke
              Commands.readValue(in, valueObject);
              target = getInvokableObject(valueObject);
              Commands.readValue(in, valueObject);
              if (valueObject.type == Commands.ARRAY_IDS) {
                // It is an array containing IDs, as it normally would be.
                valueSender.initialize(valueObject);
                Commands.readArray(in, valueObject.anInt, valueSender, valueObject, false);
                parms = (Object[]) valueSender.getArray();
              } else {
                // It is all objects or null, so it should be an Object[] or null. If not, then this
                // is an error.
                parms = (Object[]) valueObject.anObject;
              }

              if (!aMethod.isAccessible())
                aMethod.setAccessible(
                    true); // We will allow all to occur. Let access control be handled by IDE and
                           // compiler.
              newValue = aMethod.invoke(target, parms);
              returnType = aMethod.getReturnType();
              if (returnType.isPrimitive()) {
                int returnTypeID = server.getIdentityID(returnType);
                // Need to tell sendObject the correct primitive type.
                sendObject(newValue, returnTypeID, valueObject, out, true);

              } else {
                sendObject(
                    newValue,
                    NOT_A_PRIMITIVE,
                    valueObject,
                    out,
                    true); // Just send the object back. sendObject knows how to iterpret the type
              }
            } catch (CommandException e) {
              throw e; // Throw it again. These we don't want to come up as an exception proxy.
                       // These should end the thread.
            } catch (java.lang.reflect.InvocationTargetException e) {
              // This is a wrappered exception. Return the wrappered one so it looks like
              // it was the real one. (Sometimes the method being invoked is on a
              // java.lang.reflect.Constructor.newInstance,
              // which in turn is an InvocationTargetException, so we will go until we don't have an
              // InvocationTargetException.
              Throwable t = e;
              do {
                t = ((java.lang.reflect.InvocationTargetException) t).getTargetException();
              } while (t instanceof java.lang.reflect.InvocationTargetException);
              sendException(t, valueObject, out);
            } catch (Throwable e) {
              sendException(e, valueObject, out); // Turn it into a exception proxy on the client.
            } finally {
              // Clear out for GC to work
              valueObject.set();
              parms = null;
              target = null;
              aMethod = null;
              returnType = null;
              newValue = null;
              valueSender.clear();
            }
            break;

          case Commands.INVOKE_WITH_METHOD_PASSED:
            aClass = null;
            String methodName = null;
            Class[] parmTypes = null;
            target = null;
            parms = null;
            returnType = null;
            aMethod = null;

            try {
              Commands.readValue(in, valueObject);
              aClass = (Class) getInvokableObject(valueObject); // The class that has the method.
              methodName = in.readUTF();
              Commands.readValue(in, valueObject);
              if (valueObject.type == Commands.ARRAY_IDS) {
                // It is an array containing IDs, as it normally would be.
                valueSender.initialize(valueObject);
                Commands.readArray(in, valueObject.anInt, valueSender, valueObject, false);
                parmTypes = (Class[]) valueSender.getArray();
              } else {
                // It null, so it should be an null. If not, then this is an error.
                parmTypes = null;
              }
              aMethod = aClass.getMethod(methodName, parmTypes);

              // Now we get the info for the invocation of the method and execute it.
              Commands.readValue(in, valueObject);
              target = getInvokableObject(valueObject);
              Commands.readValue(in, valueObject);
              if (valueObject.type == Commands.ARRAY_IDS) {
                // It is an array containing IDs, as it normally would be.
                valueSender.initialize(valueObject);
                Commands.readArray(in, valueObject.anInt, valueSender, valueObject, false);
                parms = (Object[]) valueSender.getArray();
              } else {
                // It is all objects or null, so it should be an Object[] or null. If not, then this
                // is an error.
                parms = (Object[]) valueObject.anObject;
              }

              if (!aMethod.isAccessible())
                aMethod.setAccessible(
                    true); // We will allow all to occur. Let access control be handled by IDE and
                           // compiler.
              newValue = aMethod.invoke(target, parms);
              returnType = aMethod.getReturnType();
              if (returnType.isPrimitive()) {
                int returnTypeID = server.getIdentityID(returnType);
                // Need to tell sendObject the correct primitive type.
                sendObject(newValue, returnTypeID, valueObject, out, true);

              } else {
                sendObject(
                    newValue,
                    NOT_A_PRIMITIVE,
                    valueObject,
                    out,
                    true); // Just send the object back. sendObject knows how to iterpret the type
              }
            } catch (CommandException e) {
              throw e; // Throw it again. These we don't want to come up as an exception proxy.
                       // These should end the thread.
            } catch (java.lang.reflect.InvocationTargetException e) {
              // This is a wrappered exception. Return the wrappered one so it looks like
              // it was the real one. (Sometimes the method being invoked is on a
              // java.lang.reflect.Constructor.newInstance,
              // which in turn is an InvocationTargetException, so we will go until we don't have an
              // InvocationTargetException.
              Throwable t = e;
              do {
                t = ((java.lang.reflect.InvocationTargetException) t).getTargetException();
              } while (t instanceof java.lang.reflect.InvocationTargetException);
              sendException(t, valueObject, out);

            } catch (Throwable e) {
              sendException(e, valueObject, out); // Turn it into a exception proxy on the client.
            } finally {
              aClass = null;
              methodName = null;
              parmTypes = null;
              // Clear out for GC to work
              valueObject.set();
              parms = null;
              target = null;
              aMethod = null;
              returnType = null;
              newValue = null;
              valueSender.clear();
            }
            break;

          case Commands.GET_ARRAY_CONTENTS:
            try {
              target = server.getObject(in.readInt()); // Array to get the ids for.
              valueObject.setArrayIDS(
                  new ArrayContentsRetriever(target),
                  Array.getLength(target),
                  Commands.OBJECT_CLASS);
              Commands.writeValue(out, valueObject, true); // Write it back as a value command.
            } catch (CommandException e) {
              throw e; // Throw it again. These we don't want to come up as an exception proxy.
                       // These should end the thread.
            } catch (Throwable e) {
              sendException(e, valueObject, out); // Turn it into a exception proxy on the client.
            } finally {
              target = null;
              valueObject.set();
            }
            break;

          case Commands.CALLBACK_DONE:
            try {
              if (connectionThread != null) {
                valueObject.set();
                Commands.sendErrorCommand(out, Commands.UNKNOWN_COMMAND_SENT, valueObject);
              } else {
                try {
                  Commands.readBackValue(in, valueObject, Commands.NO_TYPE_CHECK);
                  if (valueObject.type == Commands.ARRAY_IDS) {
                    // It is an array containing IDs, as it normally would be.
                    valueSender.initialize(valueObject);
                    Commands.readArray(in, valueObject.anInt, valueSender, valueObject, false);
                    result = valueSender.getArray();
                  } else {
                    result = getInvokableObject(valueObject);
                  }
                  doLoop = false; // We need to terminate and return result
                  closeWhenDone = false; // Don't close, we will continue.
                } catch (CommandErrorException e) {
                  // There was an command error on the other side. This means
                  // connection still good, but don't continue the callback processing.
                  doLoop = false; // We need to terminate and return result
                  closeWhenDone = false; // Don't close, we will continue.
                  throw e; // Let it go on out.
                }
              }
            } finally {
              valueObject.set();
              valueSender.clear();
            }
            break;

          case Commands.ERROR:
            try {
              // Got an error command. Don't know what to do but read the
              // value and simply print it out.
              Commands.readValue(in, valueObject);
              result = getInvokableObject(valueObject);
              System.out.println("Error sent to server: Result=" + result); // $NON-NLS-1$
            } finally {
              valueObject.set();
            }
            break;

          case Commands.EXPRESSION_TREE_COMMAND:
            try {
              processExpressionCommand(valueObject, valueSender);
            } finally {
              valueObject.set();
              valueSender.clear();
            }
            break;

          default:
            // Unknown command. We don't know how long it is, so we need to shut the connection
            // down.
            System.err.println("Error: Invalid cmd send to server: Cmd=" + cmd); // $NON-NLS-1$
            doLoop = false;
            closeWhenDone = true;
            break;
        }
      }
    } catch (EOFException e) {
      // This is ok. It means that the connection on the other side was terminated.
      // So just accept this and go down.
    } catch (CommandException e) {
      throw e;
    } catch (SocketException e) {
      if (socket != null)
        throw new UnexpectedExceptionCommandException(
            false, e); // socket null means a valid close request
    } catch (Throwable e) {
      e.printStackTrace();
    } finally {
      if (closeWhenDone) {
        try {
          for (Iterator itr = expressionProcessors.values().iterator(); itr.hasNext(); ) {
            ExpressionProcesserController exp = (ExpressionProcesserController) itr.next();
            exp.close();
          }
        } finally {
          expressionProcessors.clear();
        }

        if (in != null)
          try {
            in.close();
          } catch (Exception e) {
          }
        in = null;
        if (out != null)
          try {
            out.close();
          } catch (Exception e) {
          }
        out = null;
        close();
      }
    }

    if (closeWhenDone && connectionThread != null) server.removeConnectionThread(connectionThread);
    if (shutdown) server.requestShutdown();

    return result;
  }