1 package java.net;
   2 
   3 import java.util.Arrays;
   4 
   5 /**
   6  * Immutable representation of a AF_UNIX address.
   7  * 
   8  * TODO: methods for detection of abstract addresses
   9  * 
  10  * @see StandardProtocolFamily#UNIX
  11  * @author Ing. Frantisek Kucera (frantovo.cz)
  12  */
  13 public class UnixSocketAddress extends SocketAddress {
  14 
  15     private static final long serialVersionUID = 1l;
  16 
  17     private final byte[] path;
  18 
  19     /**
  20      * Empty address -- used in case of unix domain socket client.
  21      */
  22     public UnixSocketAddress() {
  23         this.path = null;
  24     }
  25 
  26     /**
  27      * @param path raw path bytes in the platform encoding
  28      */
  29     public UnixSocketAddress(byte[] path) {
  30         this.path = Arrays.copyOf(path, path.length);
  31     }
  32     
  33     /**
  34      * @param path String representation of the socket's path
  35      */
  36     public UnixSocketAddress(String path) {
  37         this.path = path.getBytes();
  38     }
  39 
  40     /**
  41      * @return String representation of the socket's path
  42      */
  43     public String getPath() {
  44         return path == null ? null : new String(path);
  45     }
  46 
  47     /**
  48      *
  49      * @return original representation of the socket's path
  50      */
  51     public byte[] getPathBytes() {
  52         return path == null ? null : Arrays.copyOf(path, path.length);
  53     }
  54 
  55     @Override
  56     public String toString() {
  57         return getClass().getSimpleName() + ": " + getPath();
  58     }
  59 
  60 }