/** * Same as getOutputStream(socket, 0). Timeout of zero implies write will * wait until data is available.<br><br> * * From documentation for {@link #getOutputStream(Socket, long)} : <br> * Returns OutputStream for the socket. If the socket has an associated * SocketChannel then it returns a * {@link SocketOutputStream} with the given timeout. If the socket does not * have a channel, {@link Socket#getOutputStream()} is returned. In the later * case, the timeout argument is ignored and the write will wait until * data is available.<br><br> * * Any socket created using socket factories returned by {@link NetUtils}, * must use this interface instead of {@link Socket#getOutputStream()}. * * @see #getOutputStream(Socket, long) * * @param socket * @return OutputStream for writing to the socket. * @throws IOException */ public static OutputStream getOutputStream(Socket socket) throws IOException { return getOutputStream(socket, 0); }
IpcStreams(Socket socket, int maxResponseLength) throws IOException { this.maxResponseLength = maxResponseLength; setInputStream( new BufferedInputStream(NetUtils.getInputStream(socket))); setOutputStream( new BufferedOutputStream(NetUtils.getOutputStream(socket))); }
InputStream inStream = NetUtils.getInputStream(socket); OutputStream outStream = NetUtils.getOutputStream(socket, this.rpcClient.writeTO);
protected OutputStream wrapOutputStream(Socket socket, long timeoutMillis) throws IOException { return new BufferedOutputStream(NetUtils.getOutputStream(socket, timeoutMillis), 1024 * 10); }
InputStream inStream = NetUtils.getInputStream(socket); OutputStream outStream = NetUtils.getOutputStream(socket, this.rpcClient.writeTO);
OutputStream unbufOut = NetUtils.getOutputStream(sock, writeTimeout); InputStream unbufIn = NetUtils.getInputStream(sock); DataEncryptionKeyFactory keyFactory =
proxySock.setKeepAlive(true); OutputStream unbufProxyOut = NetUtils.getOutputStream(proxySock, dnConf.socketWriteTimeout); InputStream unbufProxyIn = NetUtils.getInputStream(proxySock);
OutputStream unbufOut = NetUtils.getOutputStream(socket, writeTimeout); InputStream unbufIn = NetUtils.getInputStream(socket); DataEncryptionKeyFactory keyFactory =
/** * Same as getOutputStream(socket, 0). Timeout of zero implies write will * wait until data is available.<br><br> * * From documentation for {@link #getOutputStream(Socket, long)} : <br> * Returns OutputStream for the socket. If the socket has an associated * SocketChannel then it returns a * {@link SocketOutputStream} with the given timeout. If the socket does not * have a channel, {@link Socket#getOutputStream()} is returned. In the later * case, the timeout argument is ignored and the write will wait until * data is available.<br><br> * * Any socket created using socket factories returned by {@link NetUtils}, * must use this interface instead of {@link Socket#getOutputStream()}. * * @see #getOutputStream(Socket, long) * * @param socket * @return OutputStream for writing to the socket. * @throws IOException */ public static OutputStream getOutputStream(Socket socket) throws IOException { return getOutputStream(socket, 0); }
OutputStream unbufMirrorOut = NetUtils.getOutputStream(mirrorSock, writeTimeout); InputStream unbufMirrorIn = NetUtils.getInputStream(mirrorSock);
private void checksumOk(Socket sock) { try { OutputStream out = NetUtils.getOutputStream(sock, HdfsConstants.WRITE_TIMEOUT); byte buf[] = { (DataTransferProtocol.OP_STATUS_CHECKSUM_OK >>> 8) & 0xff, (DataTransferProtocol.OP_STATUS_CHECKSUM_OK) & 0xff }; out.write(buf); out.flush(); } catch (IOException e) { // its ok not to be able to send this. LOG.debug("Could not write to datanode " + sock.getInetAddress() + ": " + e.getMessage()); } } }
private void checksumOk(Socket sock) { try { OutputStream out = NetUtils.getOutputStream(sock, HdfsConstants.WRITE_TIMEOUT); byte buf[] = { (DataTransferProtocol.OP_STATUS_CHECKSUM_OK >>> 8) & 0xff, (DataTransferProtocol.OP_STATUS_CHECKSUM_OK) & 0xff }; out.write(buf); out.flush(); } catch (IOException e) { // its ok not to be able to send this. LOG.debug("Could not write to datanode " + sock.getInetAddress() + ": " + e.getMessage()); } } }
/** * Utility function for sending a response. * @param s socket to write to * @param opStatus status message to write * @param timeout send timeout **/ private void sendResponse(Socket s, short opStatus, long timeout) throws IOException { DataOutputStream reply = new DataOutputStream(NetUtils.getOutputStream(s, timeout)); try { reply.writeShort(opStatus); reply.flush(); } finally { IOUtils.closeStream(reply); } }
/** * Utility function for sending a response. * @param s socket to write to * @param opStatus status message to write * @param timeout send timeout **/ private void sendResponse(Socket s, short opStatus, long timeout) throws IOException { DataOutputStream reply = new DataOutputStream(NetUtils.getOutputStream(s, timeout)); try { reply.writeShort(opStatus); reply.flush(); } finally { IOUtils.closeStream(reply); } } }
public static TTransport create(SocketAddress addr, long timeoutMillis) throws IOException { Socket socket = null; try { socket = SelectorProvider.provider().openSocketChannel().socket(); socket.setSoLinger(false, 0); socket.setTcpNoDelay(true); socket.connect(addr); InputStream input = new BufferedInputStream(getInputStream(socket, timeoutMillis), 1024 * 10); OutputStream output = new BufferedOutputStream( NetUtils.getOutputStream(socket, timeoutMillis), 1024 * 10); return new TIOStreamTransport(input, output); } catch (IOException e) { try { if (socket != null) socket.close(); } catch (IOException ioe) {} throw e; } } }
StreamerStreams(final DatanodeInfo src, final long writeTimeout, final long readTimeout, final Token<BlockTokenIdentifier> blockToken) throws IOException { sock = createSocketForPipeline(src, 2, dfsClient); OutputStream unbufOut = NetUtils.getOutputStream(sock, writeTimeout); InputStream unbufIn = NetUtils.getInputStream(sock, readTimeout); IOStreamPair saslStreams = dfsClient.saslClient .socketSend(sock, unbufOut, unbufIn, dfsClient, blockToken, src); unbufOut = saslStreams.out; unbufIn = saslStreams.in; out = new DataOutputStream(new BufferedOutputStream(unbufOut, HdfsConstants.SMALL_BUFFER_SIZE)); in = new DataInputStream(unbufIn); }
StreamerStreams(final DatanodeInfo src, final long writeTimeout, final long readTimeout, final Token<BlockTokenIdentifier> blockToken) throws IOException { sock = createSocketForPipeline(src, 2, dfsClient); OutputStream unbufOut = NetUtils.getOutputStream(sock, writeTimeout); InputStream unbufIn = NetUtils.getInputStream(sock, readTimeout); IOStreamPair saslStreams = dfsClient.saslClient .socketSend(sock, unbufOut, unbufIn, dfsClient, blockToken, src); unbufOut = saslStreams.out; unbufIn = saslStreams.in; out = new DataOutputStream(new BufferedOutputStream(unbufOut, HdfsConstants.SMALL_BUFFER_SIZE)); in = new DataInputStream(unbufIn); }
IpcStreams(Socket socket, int maxResponseLength) throws IOException { this.maxResponseLength = maxResponseLength; setInputStream( new BufferedInputStream(NetUtils.getInputStream(socket))); setOutputStream( new BufferedOutputStream(NetUtils.getOutputStream(socket))); }
StreamerStreams(final DatanodeInfo src, final long writeTimeout, final long readTimeout, final Token<BlockTokenIdentifier> blockToken) throws IOException { sock = createSocketForPipeline(src, 2, dfsClient); OutputStream unbufOut = NetUtils.getOutputStream(sock, writeTimeout); InputStream unbufIn = NetUtils.getInputStream(sock, readTimeout); IOStreamPair saslStreams = dfsClient.saslClient .socketSend(sock, unbufOut, unbufIn, dfsClient, blockToken, src); unbufOut = saslStreams.out; unbufIn = saslStreams.in; out = new DataOutputStream(new BufferedOutputStream(unbufOut, DFSUtilClient.getSmallBufferSize(dfsClient.getConfiguration()))); in = new DataInputStream(unbufIn); }
/** For {@link TestTransferRbw} */ public static BlockOpResponseProto transferRbw(final ExtendedBlock b, final DFSClient dfsClient, final DatanodeInfo... datanodes) throws IOException { assertEquals(2, datanodes.length); final Socket s = DFSOutputStream.createSocketForPipeline(datanodes[0], datanodes.length, dfsClient); final long writeTimeout = dfsClient.getDatanodeWriteTimeout(datanodes.length); final DataOutputStream out = new DataOutputStream(new BufferedOutputStream( NetUtils.getOutputStream(s, writeTimeout), HdfsConstants.SMALL_BUFFER_SIZE)); final DataInputStream in = new DataInputStream(NetUtils.getInputStream(s)); // send the request new Sender(out).transferBlock(b, new Token<BlockTokenIdentifier>(), dfsClient.clientName, new DatanodeInfo[]{datanodes[1]}, new StorageType[]{StorageType.DEFAULT}); out.flush(); return BlockOpResponseProto.parseDelimitedFrom(in); }