Package org.springframework.mock.web

# Class MockBodyContent

java.lang.Object
java.io.Writer
jakarta.servlet.jsp.JspWriter
jakarta.servlet.jsp.tagext.BodyContent
org.springframework.mock.web.MockBodyContent

All Implemented Interfaces:
  `Closeable`, `Flushable`, `Appendable`, `AutoCloseable`

public class MockBodyContent extends BodyContent
Mock implementation of the `BodyContent` class. Only necessary for testing applications when testing custom JSP tags.

Since:
  2.5
Author:
  Juergen Hoeller

## Field Summary

### Fields inherited from class jakarta.servlet.jsp.JspWriter

`autoFlush, bufferSize, DEFAULT_BUFFER, NO_BUFFER, UNBOUNDED_BUFFER`

### Fields inherited from class java.io.Writer

`lock`

## Constructor Summary

Constructors
Constructor
Description
`MockBodyContent(String content, HttpServletResponse response)`
Create a MockBodyContent for the given response.
`MockBodyContent(String content, HttpServletResponse response, Writer targetWriter)`
Create a MockBodyContent for the given response.
`MockBodyContent(String content, Writer targetWriter)`
Create a MockBodyContent for the given response.

## Method Summary

Modifier and Type
Method
Description
`void`
`clear()`
`void`
`clearBuffer()`
`void`
`close()`
`Reader`
`getReader()`
`int`
`getRemaining()`
`String`
`getString()`
`void`
`newLine()`
`void`
`print(boolean value)`
`void`
`print(char value)`
`void`
`print(char[] value)`
`void`
`print(double value)`
`void`
`print(float value)`
`void`
`print(int value)`
`void`
`print(long value)`
`void`
`print(Object value)`
`void`
`print(String value)`
`void`
`println()`
`void`
`println(boolean value)`
`void`
`println(char value)`
`void`
`println(char[] value)`
`void`
`println(double value)`
`void`
`println(float value)`
`void`
`println(int value)`
`void`
`println(long value)`
`void`
`println(Object value)`
`void`
`println(String value)`
`void`
`write(char[] value, int offset, int length)`
`void`
`writeOut(Writer writer)`

### Methods inherited from class jakarta.servlet.jsp.tagext.BodyContent

`clearBody, flush, getEnclosingWriter`

### Methods inherited from class jakarta.servlet.jsp.JspWriter

`getBufferSize, isAutoFlush`

### Methods inherited from class java.io.Writer

`append, append, append, nullWriter, write, write, write, write`

### Methods inherited from class java.lang.Object

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

## Constructor Details

### MockBodyContent

public MockBodyContent(String content, HttpServletResponse response)
Create a MockBodyContent for the given response.

Parameters:
  `content` - the body content to expose
  `response` - the servlet response to wrap

### MockBodyContent

public MockBodyContent(String content, Writer targetWriter)
Create a MockBodyContent for the given response.

Parameters:
  `content` - the body content to expose
  `targetWriter` - the target Writer to wrap

### MockBodyContent

public MockBodyContent(String content, @Nullable HttpServletResponse response, @Nullable Writer targetWriter)
Create a MockBodyContent for the given response.

Parameters:
  `content` - the body content to expose
  `response` - the servlet response to wrap
  `targetWriter` - the target Writer to wrap

## Method Details

### getReader

public Reader getReader()

Specified by:
  `getReader` in class `BodyContent`

### getString

public String getString()

Specified by:
  `getString` in class `BodyContent`

### writeOut

public void writeOut(Writer writer) throws IOException

Specified by:
  `writeOut` in class `BodyContent`
Throws:
  `IOException`

### clear

public void clear() throws IOException

Specified by:
  `clear` in class `JspWriter`
Throws:
  `IOException`

### clearBuffer

public void clearBuffer() throws IOException

Specified by:
  `clearBuffer` in class `JspWriter`
Throws:
  `IOException`

### close

public void close() throws IOException

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in class `JspWriter`
Throws:
  `IOException`

### getRemaining

public int getRemaining()

Specified by:
  `getRemaining` in class `JspWriter`

### newLine

public void newLine() throws IOException

Specified by:
  `newLine` in class `JspWriter`
Throws:
  `IOException`

### write

public void write(char[] value, int offset, int length) throws IOException

Specified by:
  `write` in class `Writer`
Throws:
  `IOException`

### print

public void print(boolean value) throws IOException

Specified by:
  `print` in class `JspWriter`
Throws:
  `IOException`

### print

public void print(char value) throws IOException

Specified by:
  `print` in class `JspWriter`
Throws:
  `IOException`

### print

public void print(char[] value) throws IOException

Specified by:
  `print` in class `JspWriter`
Throws:
  `IOException`

### print

public void print(double value) throws IOException

Specified by:
  `print` in class `JspWriter`
Throws:
  `IOException`

### print

public void print(float value) throws IOException

Specified by:
  `print` in class `JspWriter`
Throws:
  `IOException`

### print

public void print(int value) throws IOException

Specified by:
  `print` in class `JspWriter`
Throws:
  `IOException`

### print

public void print(long value) throws IOException

Specified by:
  `print` in class `JspWriter`
Throws:
  `IOException`

### print

public void print(Object value) throws IOException

Specified by:
  `print` in class `JspWriter`
Throws:
  `IOException`

### print

public void print(String value) throws IOException

Specified by:
  `print` in class `JspWriter`
Throws:
  `IOException`

### println

public void println() throws IOException

Specified by:
  `println` in class `JspWriter`
Throws:
  `IOException`

### println

public void println(boolean value) throws IOException

Specified by:
  `println` in class `JspWriter`
Throws:
  `IOException`

### println

public void println(char value) throws IOException

Specified by:
  `println` in class `JspWriter`
Throws:
  `IOException`

### println

public void println(char[] value) throws IOException

Specified by:
  `println` in class `JspWriter`
Throws:
  `IOException`

### println

public void println(double value) throws IOException

Specified by:
  `println` in class `JspWriter`
Throws:
  `IOException`

### println

public void println(float value) throws IOException

Specified by:
  `println` in class `JspWriter`
Throws:
  `IOException`

### println

public void println(int value) throws IOException

Specified by:
  `println` in class `JspWriter`
Throws:
  `IOException`

### println

public void println(long value) throws IOException

Specified by:
  `println` in class `JspWriter`
Throws:
  `IOException`

### println

public void println(Object value) throws IOException

Specified by:
  `println` in class `JspWriter`
Throws:
  `IOException`

### println

public void println(String value) throws IOException

Specified by:
  `println` in class `JspWriter`
Throws:
  `IOException`