Пример #1
0
 // Initialize the socket connection and prepare the output stream
 private void initSocket(String host, String port) throws IOException {
   // check the validity of the host name
   if (null == host || "".equals(host)) { // $NON-NLS-1$
     // logging.C=Illegal host argument.
     throw new IllegalArgumentException(Messages.getString("logging.C")); // $NON-NLS-1$
   }
   // check the validity of the port number
   int p = 0;
   try {
     p = Integer.parseInt(port);
   } catch (NumberFormatException e) {
     // logging.D=Illegal port argument.
     throw new IllegalArgumentException(Messages.getString("logging.D")); // $NON-NLS-1$
   }
   if (p <= 0) {
     // logging.D=Illegal port argument.
     throw new IllegalArgumentException(Messages.getString("logging.D")); // $NON-NLS-1$
   }
   // establish the network connection
   try {
     this.socket = new Socket(host, p);
   } catch (IOException e) {
     // logging.E=Failed to establish the network connection.
     getErrorManager()
         .error(
             Messages.getString("logging.E"),
             e, //$NON-NLS-1$
             ErrorManager.OPEN_FAILURE);
     throw e;
   }
   // BEGIN android-modified
   super.internalSetOutputStream(new BufferedOutputStream(this.socket.getOutputStream(), 8192));
   // END android-modified
 }
Пример #2
0
 /**
  * Closes this handler. The network connection to the host is also closed.
  *
  * @throws SecurityException If a security manager determines that the caller does not have the
  *     required permission to control this handler.
  */
 @Override
 public void close() {
   try {
     super.close();
     if (null != this.socket) {
       this.socket.close();
       this.socket = null;
     }
   } catch (Exception e) {
     // logging.F=Exception occurred when closing the socket handler.
     getErrorManager()
         .error(
             Messages.getString("logging.F"),
             e, //$NON-NLS-1$
             ErrorManager.CLOSE_FAILURE);
   }
 }