Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 * Helios, OpenSource Monitoring
 * Brought to you by the Helios Development Group
 *
 * Copyright 2012, Helios Development Group and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but 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.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 
 *
 */

import java.net.*;

public class Main {
    /**
     * Renders the details of a socket in the returned string
     * @param socket The socket to render
     * @return the details of the socket as a string
     */
    public static String render(Socket socket) {
        if (socket == null)
            return "NULL";
        StringBuilder b = new StringBuilder("\nSocket [");
        b.append("\n\tLocalPort:").append(socket.getLocalPort());
        b.append("\n\tLocalAddress:").append(socket.getLocalAddress());
        b.append("\n\tLocalSocketAddress:").append(socket.getLocalSocketAddress());
        b.append("\n\tRemotePort:").append(socket.getPort());
        b.append("\n\tRemoteAddress:").append(socket.getInetAddress());
        b.append("\n\tRemoteSocketAddress:").append(socket.getRemoteSocketAddress());
        b.append("\n\tChannel:").append(socket.getChannel());
        b.append("\n\tHashCode:").append(socket.hashCode());
        b.append("\n]");
        return b.toString();
    }

    /**
     * Renders the details of a server socket in the returned string
     * @param socket The server socket to render
     * @return the details of the server socket as a string
     */
    public static String render(ServerSocket socket) {
        if (socket == null)
            return "NULL";
        StringBuilder b = new StringBuilder("\nSocket [");
        b.append("\n\tLocalPort:").append(socket.getLocalPort());
        b.append("\n\tLocalAddress:").append(socket.getInetAddress());
        b.append("\n\tLocalSocketAddress:").append(socket.getLocalSocketAddress());
        b.append("\n\tChannel:").append(socket.getChannel());
        b.append("\n\tHashCode:").append(socket.hashCode());
        b.append("\n]");
        return b.toString();
    }
}