Logo
Distributed Genetic Programming Framework
print print

File org.sfc.net.Net.java

Here you can find all the information about the file org.sfc.net.Net.java. You may explore it here or download it onto your local disk.
/*
 * Copyright (c) 2006 Thomas Weise
 * 
 * E-Mail           : tweise@gmx.de
 * Creation Date    : 2006-01-23 10:11:21
 * Original Filename: org.sfc.net.Net.java
 * Version          : 2.0.1
 * Last modification: 2006-02-22
 *                by: Thomas Weise
 * 
 * License          : GNU LESSER GENERAL PUBLIC LICENSE
 *                    Version 2.1, February 1999
 *                    You should have received a copy of this license along
 *                    with this library; if not, write to the Free Software
 *                    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *                    MA 02111-1307, USA or download the license under
 *                    http://www.gnu.org/copyleft/lesser.html.
 *                    
 * Warranty         : This software is provided "as is" without any
 *                    warranty; without even the implied warranty of
 *                    merchantability or fitness for a particular purpose.
 *                    See the Gnu Lesser General Public License for more
 *                    details.
 */

 
package org.sfc.net;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.List;

import org.sfc.collections.Collections;
import org.sfc.utils.Typesafe;

/**
 * This class helps you by accessing the network.
 * For example, it holds some port definitions useful for network
 * connectivity.
 *
 * @author Thomas Weise
 */

public  final class Net
  {
  
/**
 * The internet address of the local host.
 */

  public  static  final InetAddress   LOCAL_HOST  ;
  
  static
    {
    InetAddress l_ia;
    
    try
      {
      l_ia = InetAddress.getLocalHost();
      }
    catch(Throwable l_t)
      {
      try
        {
        l_ia = InetAddress.getByAddress(new byte[] {127, 0, 0, 1});
        }
      catch(Throwable l_t2)
        {
        try
          {
          l_ia = InetAddress.getByName("localhost");
          }
        catch(Throwable l_t3)
          {
          l_ia = null;
          }
        }
      }
    
    LOCAL_HOST = l_ia;
    }
  
/**
 * The internal, hidden constructor.
 */

  private Net()
    {
    Typesafe.do_not_call();
    }
  
  
/**
 * Convert a string to a valid ip address/port combination.
 * @param p_address The string to be converted.
 * @return  The new internet address/port combination.
 * @throws  Throwable If something goes wrong.
 */

  public static final InetSocketAddress string_to_address (String p_address)
      throws Throwable
    {
    final int         l_j, l_p;
    final InetAddress l_a;
    
    p_address = p_address.trim();    
    l_j       = p_address.lastIndexOf(':');
    l_p       = Integer.parseInt(p_address.substring(l_j+1));
    l_a       = InetAddress.getByName(p_address.substring(0, l_j));
    
    return new InetSocketAddress(l_a, l_p);
    }
  
/**
 * Convert a ip-address/port combination to a human readable string
 * representation.
 * @param p_address The internet socket address.
 * @return  The string representation of the address.
 */

  public static final String address_to_string
                              (final InetSocketAddress p_address)
    {
    return (p_address.getAddress().getHostAddress() + ":" +
            p_address.getPort());
    }
  
/**
 * Extract all possible internet socket addresses from the specified range
 * of a string array.
 * @param p_args  The string array.
 * @param p_start The start index from where to search inside the string.
 * @param p_count The count of strings to investiage.
 * @return  A list with the internet-addresses wanted.
 */

  public  static  final List<InetSocketAddress> extract_addresses
                          (final String[] p_args,
                                 int      p_start,
                                 int      p_count)
    {
    final List<InetSocketAddress> l_l;
          
    l_l      = Collections.create_list(p_count);
    p_count--;
    p_start += p_count; 
    
    for(; p_count >= 0; p_count--)
      {
      try
        {
        l_l.add(string_to_address(p_args[p_start--]));
        }
      catch(Throwable l_t)
        {
        //
        }
      }
    
    return l_l;
    }
  }

File Information:

file name:Net.java
package:org.sfc.net
qualified name:org.sfc.net.Net.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/sfc/net/Net.java
size:4.214 KB (4316 B)
uploaded: 2018-01-07 12:03:36 GMT+0000
last update: 2006-08-25 14:53:06 GMT+0000
last access: 2018-04-20 18:33:13 GMT+0000

statistics online since 2006-01-02.   RSS Feed
Contact us by sending an email to tweise@gmx.de to receive further information, to report errors, or to join our project.
All content on this site (http://dgpf.sourceforge.net/) is LGPL-licensed.
http://dgpf.sourceforge.net/scripts/source/source.php last modified at 2018-01-07 12:03:34 GMT+0000 served at 2018-04-20 18:33:13 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo