Package gnu.kawa.xml
Class HttpPrinter
- java.lang.Object
-
- java.io.Writer
-
- java.io.PrintWriter
-
- gnu.lists.PrintConsumer
-
- gnu.kawa.xml.HttpPrinter
-
- All Implemented Interfaces:
Consumer
,XConsumer
,Closeable
,Flushable
,Appendable
,AutoCloseable
,Consumer<Object>
,DoubleConsumer
,IntConsumer
,LongConsumer
- Direct Known Subclasses:
ServletPrinter
public class HttpPrinter extends PrintConsumer
Output as an Http response. Used for both CGI scripts (default) and HttpServletResponse (future).
-
-
Field Summary
Fields Modifier and Type Field Description protected OutputStream
ostream
protected String
sawContentType
-
Fields inherited from class gnu.lists.PrintConsumer
base, skipping
-
Fields inherited from class java.io.PrintWriter
out
-
-
Constructor Summary
Constructors Constructor Description HttpPrinter(PrintConsumer out)
HttpPrinter(OutputStream out)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addHeader(String label, String value)
protected void
beforeNode()
void
beginData()
void
endAttribute()
End of an attribute or end of an actual parameter.void
endDocument()
void
endElement()
boolean
ignoring()
True if consumer is ignoring rest of element.static HttpPrinter
make(PrintConsumer out)
void
printHeader(String label, String value)
void
printHeaders()
boolean
reset(boolean headersAlso)
Try to reset (delete) any response generated so far.void
startAttribute(Object attrType)
Write a attribute for the current element.void
startDocument()
void
startElement(Object type)
void
write(char[] buf, int off, int len)
void
write(CharSequence str, int start, int length)
void
writeObject(Object v)
-
Methods inherited from class gnu.lists.PrintConsumer
append, append, append, beforeContent, beginEntity, clearWordEnd, endEntity, endHiderSection, endLogicalBlock, endLogicalBlock, endNumber, freshLine, getPrettyWriter, isDomTerm, setIndentation, startHiderSection, startLogicalBlock, startLogicalBlock, startLogicalBlock, startNumber, writeBoolean, writeBreak, writeBreakFill, writeBreakFill, writeBreakLinear, writeCDATA, writeComment, writeDouble, writeFloat, writeInt, writeLong, writeProcessingInstruction, writeRaw, writeRaw, writeRaw, writeRaw, writeShowHideButton, writeSpace, writeSpaceFill, writeSpaceFill, writeSpaceLinear, writeWordEnd, writeWordStart
-
Methods inherited from class java.io.PrintWriter
checkError, clearError, close, flush, format, format, print, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, println, setError, write, write, write, write
-
Methods inherited from class java.io.Writer
nullWriter
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.function.DoubleConsumer
andThen
-
Methods inherited from interface java.util.function.IntConsumer
andThen
-
Methods inherited from interface java.util.function.LongConsumer
andThen
-
-
-
-
Field Detail
-
sawContentType
protected String sawContentType
-
ostream
protected OutputStream ostream
-
-
Constructor Detail
-
HttpPrinter
public HttpPrinter(OutputStream out)
-
HttpPrinter
public HttpPrinter(PrintConsumer out)
-
-
Method Detail
-
make
public static HttpPrinter make(PrintConsumer out)
-
beforeNode
protected void beforeNode()
- Overrides:
beforeNode
in classPrintConsumer
-
printHeader
public void printHeader(String label, String value) throws IOException
- Throws:
IOException
-
printHeaders
public void printHeaders() throws IOException
- Throws:
IOException
-
startAttribute
public void startAttribute(Object attrType)
Description copied from interface:Consumer
Write a attribute for the current element. This is only allowed immediately after a startElement.- Specified by:
startAttribute
in interfaceConsumer
- Overrides:
startAttribute
in classPrintConsumer
-
endAttribute
public void endAttribute()
Description copied from interface:Consumer
End of an attribute or end of an actual parameter. The former use matches a startAttribute; the latter may not, and can be used to separate parameters in a parameter list. This double duty suggsts the method should at least be re-named.- Specified by:
endAttribute
in interfaceConsumer
- Overrides:
endAttribute
in classPrintConsumer
-
beginData
public void beginData()
-
startElement
public void startElement(Object type)
- Specified by:
startElement
in interfaceConsumer
- Overrides:
startElement
in classPrintConsumer
-
endElement
public void endElement()
- Specified by:
endElement
in interfaceConsumer
- Overrides:
endElement
in classPrintConsumer
-
writeObject
public void writeObject(Object v)
- Specified by:
writeObject
in interfaceConsumer
- Overrides:
writeObject
in classPrintConsumer
-
write
public void write(CharSequence str, int start, int length)
- Specified by:
write
in interfaceConsumer
- Overrides:
write
in classPrintConsumer
-
write
public void write(char[] buf, int off, int len)
- Specified by:
write
in interfaceConsumer
- Overrides:
write
in classPrintWriter
-
startDocument
public void startDocument()
- Specified by:
startDocument
in interfaceConsumer
- Overrides:
startDocument
in classPrintConsumer
-
endDocument
public void endDocument()
- Specified by:
endDocument
in interfaceConsumer
- Overrides:
endDocument
in classPrintConsumer
-
ignoring
public boolean ignoring()
Description copied from interface:Consumer
True if consumer is ignoring rest of element. The producer can use this information to skip ahead.- Specified by:
ignoring
in interfaceConsumer
- Overrides:
ignoring
in classPrintConsumer
-
reset
public boolean reset(boolean headersAlso)
Try to reset (delete) any response generated so far.- Parameters:
headersAlso
- if response headers should also be reset.- Returns:
- true on success, false if it's too late.
-
-