/** * Decode a series of 4 bytes from <code>buf</code>, starting at position 0, * and interpret them as an integer. * * @param buf * The buffer to read from. * @return An integer, as read from the buffer. */ public static final int decodeBigEndian(final byte[] buf) { return decodeBigEndian(buf, 0); }
/** * Decode a series of 4 bytes from <code>buf</code>, starting at position 0, * and interpret them as an integer. * * @param buf * The buffer to read from. * @return An integer, as read from the buffer. */ public static final int decodeBigEndian(final byte[] buf) { return decodeBigEndian(buf, 0); }
/** * Read a 4-byte word from the underlying transport and interpret it as an * integer. * * @return The length prefix of the next SASL message to read. * @throws TTransportException * Thrown if reading from the underlying transport fails. */ protected int readLength() throws TTransportException { byte[] lenBuf = new byte[4]; underlyingTransport.readAll(lenBuf, 0, lenBuf.length); return EncodingUtils.decodeBigEndian(lenBuf); }
/** * Read a 4-byte word from the underlying transport and interpret it as an * integer. * * @return The length prefix of the next SASL message to read. * @throws TTransportException * Thrown if reading from the underlying transport fails. */ protected int readLength() throws TTransportException { byte[] lenBuf = new byte[4]; underlyingTransport.readAll(lenBuf, 0, lenBuf.length); return EncodingUtils.decodeBigEndian(lenBuf); }
/** * Read a complete Thrift SASL message. * * @return The SASL status and payload from this message. * @throws TTransportException * Thrown if there is a failure reading from the underlying * transport, or if a status code of BAD or ERROR is encountered. */ protected SaslResponse receiveSaslMessage() throws TTransportException { underlyingTransport.readAll(messageHeader, 0, messageHeader.length); byte statusByte = messageHeader[0]; byte[] payload = new byte[EncodingUtils.decodeBigEndian(messageHeader, STATUS_BYTES)]; underlyingTransport.readAll(payload, 0, payload.length); NegotiationStatus status = NegotiationStatus.byValue(statusByte); if (status == null) { sendAndThrowMessage(NegotiationStatus.ERROR, "Invalid status " + statusByte); } else if (status == NegotiationStatus.BAD || status == NegotiationStatus.ERROR) { try { String remoteMessage = new String(payload, "UTF-8"); throw new TTransportException("Peer indicated failure: " + remoteMessage); } catch (UnsupportedEncodingException e) { throw new TTransportException(e); } } if (LOGGER.isDebugEnabled()) LOGGER.debug(getRole() + ": Received message with status {} and payload length {}", status, payload.length); return new SaslResponse(status, payload); }
/** * Read a complete Thrift SASL message. * * @return The SASL status and payload from this message. * @throws TTransportException * Thrown if there is a failure reading from the underlying * transport, or if a status code of BAD or ERROR is encountered. */ protected SaslResponse receiveSaslMessage() throws TTransportException { underlyingTransport.readAll(messageHeader, 0, messageHeader.length); byte statusByte = messageHeader[0]; byte[] payload = new byte[EncodingUtils.decodeBigEndian(messageHeader, STATUS_BYTES)]; underlyingTransport.readAll(payload, 0, payload.length); NegotiationStatus status = NegotiationStatus.byValue(statusByte); if (status == null) { sendAndThrowMessage(NegotiationStatus.ERROR, "Invalid status " + statusByte); } else if (status == NegotiationStatus.BAD || status == NegotiationStatus.ERROR) { try { String remoteMessage = new String(payload, "UTF-8"); throw new TTransportException("Peer indicated failure: " + remoteMessage); } catch (UnsupportedEncodingException e) { throw new TTransportException(e); } } if (LOGGER.isDebugEnabled()) LOGGER.debug(getRole() + ": Received message with status {} and payload length {}", status, payload.length); return new SaslResponse(status, payload); }