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

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

Introduction

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

Prototype

public static SocketInputWrapper getInputStream(Socket socket) throws IOException 

Source Link

Document

Same as getInputStream(socket, socket.getSoTimeout()).

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   w  w w  .j  a v  a2 s  .c om
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);
        }
    }
}