Example usage for org.apache.hadoop.net NetUtils getOutputStream

List of usage examples for org.apache.hadoop.net NetUtils getOutputStream

Introduction

In this page you can find the example usage for org.apache.hadoop.net NetUtils getOutputStream.

Prototype

public static OutputStream getOutputStream(Socket socket) throws IOException 

Source Link

Document

Same as getOutputStream(socket, 0).

Usage

From source file:com.mellanox.r4h.DFSClient.java

License:Apache License

/**
 * Connect to the given datanode's datantrasfer port, and return
 * the resulting IOStreamPair. This includes encryption wrapping, etc.
 *//*from  ww  w  . j av  a  2  s.com*/
private IOStreamPair connectToDN(DatanodeInfo dn, int timeout, LocatedBlock lb) throws IOException {
    boolean success = false;
    Socket sock = null;
    try {
        sock = socketFactory.createSocket();
        String dnAddr = dn.getXferAddr(getConf().getConnectToDnViaHostname());
        if (LOG.isDebugEnabled()) {
            LOG.debug("Connecting to datanode " + dnAddr);
        }
        NetUtils.connect(sock, NetUtils.createSocketAddr(dnAddr), timeout);
        sock.setSoTimeout(timeout);

        OutputStream unbufOut = NetUtils.getOutputStream(sock);
        InputStream unbufIn = NetUtils.getInputStream(sock);
        IOStreamPair ret = saslClient.newSocketSend(sock, unbufOut, unbufIn, this, lb.getBlockToken(), dn);
        success = true;
        return ret;
    } finally {
        if (!success) {
            IOUtils.closeSocket(sock);
        }
    }
}