Java Socket Address Get toFileName(InetSocketAddress address)

Here you can find the source of toFileName(InetSocketAddress address)

Description

Converts the specified address into a string that is suitable for naming files.

License

Apache License

Parameter

Parameter Description
address Address.

Return

File name.

Declaration

public static String toFileName(InetSocketAddress address) 

Method Source Code

//package com.java2s;
/*//from  w w w  .  ja v a  2s  .  c om
 * Copyright 2019 The Hekate Project
 *
 * The Hekate Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

import java.net.InetSocketAddress;

public class Main {
    /** Prefix for the file name of {@link #toFileName(InetSocketAddress)}. */
    public static final String FILE_PREFIX = "node_";
    /** Separator of host and port components for {@link #toFileName(InetSocketAddress)}. */
    public static final String PORT_SEPARATOR = "_";

    /**
     * Converts the specified address into a string that is suitable for naming files.
     *
     * @param address Address.
     *
     * @return File name.
     *
     * @see #fromFileName(String, Logger)
     */
    public static String toFileName(InetSocketAddress address) {
        return FILE_PREFIX + address.getAddress().getHostAddress() + PORT_SEPARATOR + address.getPort();
    }
}

Related

  1. stringifyInetSocketAddressList(InetSocketAddress[] addresses)
  2. stringToInetSocketAddress( String address, int defaultPort)
  3. toAddressString(InetSocketAddress address)
  4. toByte(InetSocketAddress socketAddress)
  5. toBytes(SocketAddress address)
  6. toHttpUrl(InetSocketAddress addr)
  7. toInetSocketAddress(String address)
  8. toInetSocketAddress(String hostPortPair, int defaultPort)
  9. toInetSocketAddressLIst(List addressList)