Package org.apache.myfaces.view.facelets
Class StateWriter
- java.lang.Object
- 
- java.io.Writer
- 
- org.apache.myfaces.view.facelets.StateWriter
 
 
- 
- All Implemented Interfaces:
- Closeable,- Flushable,- Appendable,- AutoCloseable
 
 public final class StateWriter extends Writer A class for handling state insertion. Content is written directly to "out" until an attempt to write state; at that point, it's redirected into a buffer that can be picked through in theory, this buffer should be very small, since it only needs to be enough to contain all the content after the close of the first (and, hopefully, only) form.Potential optimizations: - If we created a new FastWriter at each call to writingState(), and stored a List of them, then we'd know that state tokens could only possibly be near the start of each buffer (and might not be there at all). (There might be a close-element before the state token). Then, we'd only need to check the start of the buffer for the state token; if it's there, write out the real state, then blast the rest of the buffer out. This wouldn't even require toString(), which for large buffers is expensive. However, this optimization is only going to be especially meaningful for the multi-form case.
- More of a FastWriter optimization than a StateWriter, but: it is far faster to create a set of small 1K buffers than constantly reallocating one big buffer.
 - Version:
- $Id$
- Author:
- Adam Winer
 
- 
- 
Constructor SummaryConstructors Constructor Description StateWriter(Writer initialOut, int initialSize)StateWriter(Writer initialOut, int initialSize, FacesContext facesContext)
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidflush()StringgetAndResetBuffer()static StateWritergetCurrentInstance()static StateWritergetCurrentInstance(FacesContext facesContext)booleanisStateWritten()booleanisStateWrittenWithoutWrapper()voidrelease()voidrelease(FacesContext facesContext)voidwrite(char[] cbuf)voidwrite(char[] cbuf, int off, int len)voidwrite(int c)voidwrite(String str)voidwrite(String str, int off, int len)voidwritingState()Mark that state is about to be written.voidwritingStateWithoutWrapper()- 
Methods inherited from class java.io.Writerappend, append, append, nullWriter
 
- 
 
- 
- 
- 
Constructor Detail- 
StateWriterpublic StateWriter(Writer initialOut, int initialSize) 
 - 
StateWriterpublic StateWriter(Writer initialOut, int initialSize, FacesContext facesContext) 
 
- 
 - 
Method Detail- 
getCurrentInstancepublic static StateWriter getCurrentInstance() 
 - 
getCurrentInstancepublic static StateWriter getCurrentInstance(FacesContext facesContext) 
 - 
writingStatepublic void writingState() Mark that state is about to be written. Contrary to what you'd expect, we cannot and should not assume that this location is really going to have state; it is perfectly legit to have a ResponseWriter that filters out content, and ignores an attempt to write out state at this point. So, we have to check after the fact to see if there really are state markers.
 - 
isStateWrittenpublic boolean isStateWritten() 
 - 
writingStateWithoutWrapperpublic void writingStateWithoutWrapper() 
 - 
isStateWrittenWithoutWrapperpublic boolean isStateWrittenWithoutWrapper() 
 - 
closepublic void close() throws IOException- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Specified by:
- closein class- Writer
- Throws:
- IOException
 
 - 
flushpublic void flush() throws IOException- Specified by:
- flushin interface- Flushable
- Specified by:
- flushin class- Writer
- Throws:
- IOException
 
 - 
writepublic void write(char[] cbuf, int off, int len) throws IOException- Specified by:
- writein class- Writer
- Throws:
- IOException
 
 - 
writepublic void write(char[] cbuf) throws IOException- Overrides:
- writein class- Writer
- Throws:
- IOException
 
 - 
writepublic void write(int c) throws IOException- Overrides:
- writein class- Writer
- Throws:
- IOException
 
 - 
writepublic void write(String str, int off, int len) throws IOException - Overrides:
- writein class- Writer
- Throws:
- IOException
 
 - 
writepublic void write(String str) throws IOException - Overrides:
- writein class- Writer
- Throws:
- IOException
 
 - 
getAndResetBufferpublic String getAndResetBuffer() 
 - 
releasepublic void release() 
 - 
releasepublic void release(FacesContext facesContext) 
 
- 
 
-