package com.jscape.inet.proxy.socks.protocol.v4.marshaling;

import com.jscape.util.IOTools;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Inet4Address;

/**
 * @author Alex Usun
 */
public class InetAddressCodec {

    public static void writeValue(Inet4Address value, OutputStream out)
            throws IOException {
        out.write(value.getAddress());
    }

    public static Inet4Address readValue(InputStream in)
            throws IOException {
        byte[] address4 = IOTools.read(new byte[4], in);
        return (Inet4Address) Inet4Address.getByAddress(address4);
    }

    private InetAddressCodec() {
    }
}
