mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
125484 slanglois: MNT-16155 Update source headers - remove old Copyrights from Java and JSP dource files git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.1.N/root@125603 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
58 lines
1.5 KiB
Java
58 lines
1.5 KiB
Java
package org.alfresco.util;
|
|
|
|
import java.io.IOException;
|
|
import java.net.InetAddress;
|
|
import java.net.ServerSocket;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
/**
|
|
* Alfresco port-related utility functions.
|
|
*
|
|
* @author abalmus
|
|
*/
|
|
public class PortUtil
|
|
{
|
|
private static Log logger = LogFactory.getLog(PortUtil.class);
|
|
|
|
/**
|
|
* Check if specified port is free.
|
|
* @param port Port number to check.
|
|
* @param host A local address to bind to; if null, "" or "0.0.0.0" then all local addresses will be considered.
|
|
*/
|
|
public static void checkPort(int port, String host) throws IOException
|
|
{
|
|
ServerSocket serverSocket = null;
|
|
|
|
try
|
|
{
|
|
if (host != null && !host.equals("") && !"0.0.0.0".equals(host.trim()))
|
|
{
|
|
serverSocket = new ServerSocket(port, 0, InetAddress.getByName(host.trim()));
|
|
}
|
|
else
|
|
{
|
|
serverSocket = new ServerSocket(port);
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if (serverSocket != null)
|
|
{
|
|
try
|
|
{
|
|
serverSocket.close();
|
|
}
|
|
catch (IOException ioe)
|
|
{
|
|
if (logger.isDebugEnabled())
|
|
{
|
|
logger.debug(ioe.toString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|