# Class CommandResponse

java.lang.Object
org.apache.zookeeper.server.admin.CommandResponse

public class CommandResponse extends Object
A response from running a `Command`.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`KEY_COMMAND`
The key in the map returned by `toMap()` for the command name.
`static final String`
`KEY_ERROR`
The key in the map returned by `toMap()` for the error string.

## Constructor Summary

Constructors
Constructor
Description
`CommandResponse(String command)`
Creates a new response with no error string.
`CommandResponse(String command, String error, int statusCode)`
Creates a new response.
`CommandResponse(String command, String error, int statusCode, InputStream inputStream)`
Creates a new response.

## Method Summary

Modifier and Type
Method
Description
`void`
`addHeader(String name, String value)`
Adds a header to this response.
`String`
`getCommand()`
Gets the command name.
`String`
`getError()`
Gets the error string (may be null).
`Map<String,String>`
`getHeaders()`
Returns all headers
`InputStream`
`getInputStream()`
Gets the InputStream (may be null).
`int`
`getStatusCode()`
Gets the http status code
`Object`
`put(String key, Object value)`
Adds a key/value pair to this response.
`void`
`putAll(Map<? extends String, ?> m)`
Adds all key/value pairs in the given map to this response.
`void`
`setInputStream(InputStream inputStream)`
Sets the InputStream
`void`
`setStatusCode(int statusCode)`
Sets the http status code
`Map<String,Object>`
`toMap()`
Converts this response to a map.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### KEY_COMMAND

public static final String KEY_COMMAND
The key in the map returned by `toMap()` for the command name.

See Also:
  - Constant Field Values

### KEY_ERROR

public static final String KEY_ERROR
The key in the map returned by `toMap()` for the error string.

See Also:
  - Constant Field Values

## Constructor Details

### CommandResponse

public CommandResponse(String command)
Creates a new response with no error string.

Parameters:
  `command` - command name

### CommandResponse

public CommandResponse(String command, String error, int statusCode)
Creates a new response.

Parameters:
  `command` - command name
  `error` - error string (may be null)
  `statusCode` - http status code

### CommandResponse

public CommandResponse(String command, String error, int statusCode, InputStream inputStream)
Creates a new response.

Parameters:
  `command` - command name
  `error` - error string (may be null)
  `statusCode` - http status code
  `inputStream` - inputStream to send out data (may be null)

## Method Details

### getCommand

public String getCommand()
Gets the command name.

Returns:
  command name

### getError

public String getError()
Gets the error string (may be null).

Returns:
  error string

### getStatusCode

public int getStatusCode()
Gets the http status code

Returns:
  http status code

### setStatusCode

public void setStatusCode(int statusCode)
Sets the http status code

### getInputStream

public InputStream getInputStream()
Gets the InputStream (may be null).

Returns:
  InputStream

### setInputStream

public void setInputStream(InputStream inputStream)
Sets the InputStream

### put

public Object put(String key, Object value)
Adds a key/value pair to this response.

Parameters:
  `key` - key
  `value` - value
Returns:
  prior value for key, or null if none

### putAll

public void putAll(Map<? extends String, ?> m)
Adds all key/value pairs in the given map to this response.

Parameters:
  `m` - map of key/value pairs

### addHeader

public void addHeader(String name, String value)
Adds a header to this response.

Parameters:
  `name` - name of the header
  `value` - value of the header

### getHeaders

public Map<String,String> getHeaders()
Returns all headers

Returns:
  map representation of all headers

### toMap

public Map<String,Object> toMap()
Converts this response to a map. The returned map is mutable, and changes to it do not reflect back into this response.

Returns:
  map representation of response