Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.Closeable;
import java.io.IOException;

import java.net.ServerSocket;
import java.net.Socket;

public class Main {
    /**
     * Simple utility to close {@link Closeable} instance.
     *
     * A typical usage is as follows:
     * <pre>{@code
     *   Closeable stream = ...;
     *   boolean succeeded = false;
     *   try {
     *     // Read data from stream here.
     *     ...
     *
     *     succeeded = true;
     *   } finally {
     *     close(stream, !succeeded);
     *   }
     * }</pre>
     *
     * @param closeable
     * @param ignoreException
     * @throws IOException
     */
    public static void close(Closeable closeable, boolean ignoreException) throws IOException {
        try {
            closeable.close();
        } catch (IOException e) {
            if (!ignoreException) {
                throw e;
            }
        }
    }

    /**
     * Simple utility to close {@link Socket} instance.
     * See {@link MozcUtil#close(Closeable,boolean)} for details.
     */
    public static void close(Socket socket, boolean ignoreIOException) throws IOException {
        try {
            socket.close();
        } catch (IOException e) {
            if (!ignoreIOException) {
                throw e;
            }
        }
    }

    /**
     * Simple utility to close {@link ServerSocket} instance.
     * See {@link MozcUtil#close(Closeable,boolean)} for details.
     */
    public static void close(ServerSocket socket, boolean ignoreIOException) throws IOException {
        try {
            socket.close();
        } catch (IOException e) {
            if (!ignoreIOException) {
                throw e;
            }
        }
    }
}