001/*
002 * To change this template, choose Tools | Templates
003 * and open the template in the editor.
004 */
005package org.anarres.qemu.exec.host.disk;
006
007import java.net.InetAddress;
008import java.net.InetSocketAddress;
009import javax.annotation.CheckForNull;
010import javax.annotation.Nonnull;
011import org.anarres.qemu.exec.host.chardev.UdpCharDevice;
012
013/**
014 *
015 * @author shevek
016 */
017public class SshDisk extends AbstractDisk {
018
019    public static final int DEFAULT_PORT = 22;
020    private final InetSocketAddress address;
021    private final String user;
022    private final String path;
023
024    public SshDisk(@Nonnull InetSocketAddress address, @CheckForNull String user, @Nonnull String path) {
025        this.address = address;
026        this.user = user;
027        this.path = path;
028    }
029
030    public SshDisk(@Nonnull InetAddress address, @CheckForNull String user, @Nonnull String path) {
031        this(new InetSocketAddress(address, DEFAULT_PORT), user, path);
032    }
033
034    @Override
035    public String toString() {
036        StringBuilder buf = new StringBuilder("ssh://");
037        if (user != null)
038            buf.append(user).append("@");
039        buf.append(UdpCharDevice.toHostString(address));
040        if (address.getPort() > 0 || DEFAULT_PORT != address.getPort())
041            buf.append(':').append(address.getPort());
042        buf.append(path);
043        return buf.toString();
044    }
045}