Top Description Fields Constructors Methods
com.sun.faces.application.view

pack-priv final Class WriteBehindStateWriter

extends Writer
Class Inheritance
Imports
com.sun.faces.RIConstants, com.sun.faces.io.FastStringWriter, com.sun.faces.util.Util, javax.faces.application.StateManager, javax.faces.context.FacesContext, .ResponseWriter, java.io.IOException, .Writer

Custom Writer to efficiently handle the state manager replacement marker written out by MultiViewHandler#writeState(javax.faces.context.FacesContext).

Field Summary

Modifier and TypeField and Description
private char[]
private int
private FacesContext
private static final ThreadLocal<WriteBehindStateWriter>
private FastStringWriter
private Writer
private Writer
private Object
private static final int
private boolean
Inherited from java.io.Writer:
lock

Constructor Summary

AccessConstructor and Description
public
WriteBehindStateWriter(Writer
the writer we write non-buffered content to
out
,
FacesContext
the FacesContext for the current request
context
,
int
the buffer size for post-processing buffered content
bufSize
)

Constructs a new WriteBehindStateWriter instance.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

This is a no-op.
public void
flush()

Implements abstract java.io.Writer.flush.

Implements java.io.Flushable.flush.

This is a no-op.
public void
flushToWriter()

Write directly from our FastStringWriter to the provided writer.

public static WriteBehindStateWriter

Returns:

the WriteBehindStateWriter being used for processing this request
getCurrentInstance
()

private static int

Returns:

the index of the next delimiter, if any
getNextDelimiterIndex
(StringBuilder
buffered content
builder
,
int
the offset to start the search from
offset
)

private StringBuilder

Returns:

the state.
getState
(StateManager
the state manager.
stateManager
,
ResponseWriter
the original response writer.
origWriter
)

Get the state.

public void
release()

Clear the ThreadLocal state.

public boolean

Returns:

true if writingState() has been called, otherwise returns false
stateWritten
()

public void
write(int
int specifying a character to be written
c
)

Overrides java.io.Writer.write.

Writes directly to the current out.
public void
write(char[]
Array of characters to be written
cbuf
)

Overrides java.io.Writer.write.

Writes directly to the current out.
public void
write(String
String to be written
str
)

Overrides java.io.Writer.write.

Writes directly to the current out.
public void
write(String
A String
str
,
int
Offset from which to start writing characters
off
,
int
Number of characters to write
len
)

Overrides java.io.Writer.write.

Writes directly to the current out.
public void
write(char[]
Array of characters
cbuf
,
int
Offset from which to start writing characters
off
,
int
Number of characters to write
len
)

Implements abstract java.io.Writer.write.

Writes directly to the current out.
public void
writingState()

When called, the original writer is backed up and replaced with a new FastStringWriter.

Inherited from java.io.Writer:
appendappendappendnullWriter

Field Detail

bufback to summary
private char[] buf
bufSizeback to summary
private int bufSize
contextback to summary
private FacesContext context
CUR_WRITERback to summary
private static final ThreadLocal<WriteBehindStateWriter> CUR_WRITER
fWriterback to summary
private FastStringWriter fWriter
origback to summary
private Writer orig
outback to summary
private Writer out
stateback to summary
private Object state
STATE_MARKER_LENback to summary
private static final int STATE_MARKER_LEN
stateWrittenback to summary
private boolean stateWritten

Constructor Detail

WriteBehindStateWriterback to summary
public WriteBehindStateWriter(Writer out, FacesContext context, int bufSize)

Constructs a new WriteBehindStateWriter instance.

Parameters
out:Writer

the writer we write non-buffered content to

context:FacesContext

the FacesContext for the current request

bufSize:int

the buffer size for post-processing buffered content

Method Detail

closeback to summary
public void close() throws IOException

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

This is a no-op.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.Writer.close.

If an I/O error occurs

flushback to summary
public void flush() throws IOException

Implements abstract java.io.Writer.flush.

Implements java.io.Flushable.flush.

This is a no-op.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.Writer.flush.

If an I/O error occurs

flushToWriterback to summary
public void flushToWriter() throws IOException

Write directly from our FastStringWriter to the provided writer.

Exceptions
IOException:
if an error occurs
getCurrentInstanceback to summary
public static WriteBehindStateWriter getCurrentInstance()
Returns:WriteBehindStateWriter

the WriteBehindStateWriter being used for processing this request

getNextDelimiterIndexback to summary
private static int getNextDelimiterIndex(StringBuilder builder, int offset)
Parameters
builder:StringBuilder

buffered content

offset:int

the offset to start the search from

Returns:int

the index of the next delimiter, if any

getStateback to summary
private StringBuilder getState(StateManager stateManager, ResponseWriter origWriter) throws IOException

Get the state.

In JSF 2.2 it is required by the specification that the view state hidden input in each h:form has a unique id. So we have to call this method multiple times as each h:form needs to generate the element id for itself.

Parameters
stateManager:StateManager

the state manager.

origWriter:ResponseWriter

the original response writer.

Returns:StringBuilder

the state.

Exceptions
IOException:
when an I/O error occurs.
releaseback to summary
public void release()

Clear the ThreadLocal state.

stateWrittenback to summary
public boolean stateWritten()
Returns:boolean

true if writingState() has been called, otherwise returns false

writeback to summary
public void write(int c) throws IOException

Overrides java.io.Writer.write.

Writes directly to the current out.

Parameters
c:int

Doc from java.io.Writer.write.

int specifying a character to be written

Annotations
@Override
Exceptions
IOException:

Doc from java.io.Writer.write.

If an I/O error occurs

See Also
Writer#write(int)
writeback to summary
public void write(char[] cbuf) throws IOException

Overrides java.io.Writer.write.

Writes directly to the current out.

Parameters
cbuf:char[]

Doc from java.io.Writer.write.

Array of characters to be written

Annotations
@Override
Exceptions
IOException:

Doc from java.io.Writer.write.

If an I/O error occurs

See Also
Writer#write(char[])
writeback to summary
public void write(String str) throws IOException

Overrides java.io.Writer.write.

Writes directly to the current out.

Parameters
str:String

Doc from java.io.Writer.write.

String to be written

Annotations
@Override
Exceptions
IOException:

Doc from java.io.Writer.write.

If an I/O error occurs

See Also
Writer#write(String)
writeback to summary
public void write(String str, int off, int len) throws IOException

Overrides java.io.Writer.write.

Writes directly to the current out.

Parameters
str:String

Doc from java.io.Writer.write.

A String

off:int

Doc from java.io.Writer.write.

Offset from which to start writing characters

len:int

Doc from java.io.Writer.write.

Number of characters to write

Annotations
@Override
Exceptions
IOException:

Doc from java.io.Writer.write.

If an I/O error occurs

See Also
Writer#write(String, int, int)
writeback to summary
public void write(char[] cbuf, int off, int len) throws IOException

Implements abstract java.io.Writer.write.

Writes directly to the current out.

Parameters
cbuf:char[]

Doc from java.io.Writer.write.

Array of characters

off:int

Doc from java.io.Writer.write.

Offset from which to start writing characters

len:int

Doc from java.io.Writer.write.

Number of characters to write

Annotations
@Override
Exceptions
IOException:

Doc from java.io.Writer.write.

If an I/O error occurs

See Also
Writer#write(char[], int, int)
writingStateback to summary
public void writingState()

When called, the original writer is backed up and replaced with a new FastStringWriter. All content written after this method is called will then be buffered and written out later after the entire view has been rendered.