|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jnetstream.packet.format.PacketFormatter
public class PacketFormatter
Formats a packet for text output to an Appendable output.
Appendable interface is implemented by standard PrintStream
(i.e. System.out) and standard StringBuilder, plus of
course any custom objects. The packet contents are formatted according to the
default PacketFormat definition and sent to the output (Appendable).
There are actually 2 separate instances of PacketFormatter to handle
PrintStream type output and for formatting into a string buffer. You can
retrieve each of these formatters using
PacketFormatter#getPrintFormatter() and
PacketFormatter#getStringFormatter() static methods. The
Packet.format and Packet.toString methods each use one of the
2 formatters. Packet.format uses the platformFormatter that outputs to a
PrintStream by default and the Packet.toString method uses the
platformFormatter that output to an internal string buffer which content can
be retrieved using the PacketFormatter.toString() method.
A number of predefined formats are supplied and can be set as default
formatters or simply used directly to delagate packet content directly. The
supplied formats can be accessed using the FormatType enum
definition.
Packet packet = ... some packet we current have reference to
PacketFormatter.setDefault(PacketFormatter.Type.Html);
PacketFormatter.PacketFormat out = PacketFormatter.getDefault();
out.format(packet);
How about switching the output from default System.out to a cutom
StringBuilder buffer:
StringBuilder b = new StringBuilder(1024);
PacketFormatter.setDefault(b);
Packet packet = ... some packet
PacketFormatter.PacketFormat out = PacketFormatter.getDefault();
out.format(packet);
System.out.println("Our nicely platformFormatter packet:\n" + b.toString());
The defaults after initialization are as follows. Default delagate type is
, default output is System.out.
The method Packet#toString() uses the default platformFormatter as
retrieved using the static PacketFormatter#getPrintFormatter() method
call and to the values the deafault platformFormatter is initialized to.
| Nested Class Summary | |
|---|---|
static interface |
PacketFormatter.Builder
Builds a new instance of a PacketFormatter. |
| Constructor Summary | |
|---|---|
|
PacketFormatter()
Constructs a new packet formatter. |
|
PacketFormatter(java.lang.Appendable a)
Constructs a new formatter with the specified destination. |
|
PacketFormatter(java.lang.Appendable a,
java.util.Locale l)
Constructs a new formatter with the specified destination and locale. |
protected |
PacketFormatter(boolean init)
Constructs a new packet formatter. |
|
PacketFormatter(FormatterType formatType)
|
|
PacketFormatter(FormatterType formatType,
java.lang.Appendable a)
|
|
PacketFormatter(FormatterType formatType,
java.lang.Appendable a,
java.util.Locale l)
|
| Method Summary | |
|---|---|
void |
close()
|
void |
flush()
|
PacketFormatter |
format(Header header)
|
PacketFormatter |
format(java.util.Locale l,
Packet packet)
|
java.util.Formatter |
format(java.util.Locale l,
java.lang.String format,
java.lang.Object... args)
|
PacketFormatter |
format(Packet packet)
|
java.util.Formatter |
format(java.lang.String format,
java.lang.Object... args)
|
static boolean |
hasRegisteredBuilder(FormatterType formatType)
|
java.io.IOException |
ioException()
|
java.util.Locale |
locale()
|
java.lang.Appendable |
out()
|
static void |
registerBuilder(FormatterType formatType,
PacketFormatter.Builder builder)
|
protected java.util.Locale |
setLocale(java.util.Locale l)
|
protected void |
setOut(java.lang.Appendable o)
|
protected void |
setPlatformFormatter(java.util.Formatter f)
|
java.lang.String |
toString()
Returns the contents of the internal string buffer and resets the buffer. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public PacketFormatter()
Constructs a new packet formatter.
The destination of the formatted output is a StringBuilder which may be retrieved by invoking out() and whose current content may be converted into a string by invoking toString(). The locale used is the default locale for this instance of the Java virtual machine.
public PacketFormatter(java.lang.Appendable a)
Constructs a new formatter with the specified destination.
The locale used is the default locale for this instance of the Java virtual machine.
a - Destination for the formatted output. If a is null then a
StringBuilder will be created.
public PacketFormatter(java.lang.Appendable a,
java.util.Locale l)
a - Destination for the formatted output. If a is null then a
StringBilder will be created.l - The locale to apply during formatting. If l is null then no
localization is applied.protected PacketFormatter(boolean init)
Constructs a new packet formatter.
The destination of the formatted output is a StringBuilder which may be retrieved by invoking out() and whose current content may be converted into a string by invoking toString(). The locale used is the default locale for this instance of the Java virtual machine.
public PacketFormatter(FormatterType formatType)
public PacketFormatter(FormatterType formatType,
java.lang.Appendable a)
public PacketFormatter(FormatterType formatType,
java.lang.Appendable a,
java.util.Locale l)
| Method Detail |
|---|
public static boolean hasRegisteredBuilder(FormatterType formatType)
formatType -
public static void registerBuilder(FormatterType formatType,
PacketFormatter.Builder builder)
public void close()
close in interface java.io.CloseableFormatter.close()public void flush()
flush in interface java.io.FlushableFormatter.flush()
public PacketFormatter format(java.util.Locale l,
Packet packet)
public java.util.Formatter format(java.util.Locale l,
java.lang.String format,
java.lang.Object... args)
l - delagate - args -
Formatter.format(java.util.Locale, java.lang.String,
java.lang.Object[])
public PacketFormatter format(Header header)
throws java.io.IOException
header -
java.io.IOExceptionorg.jnetstream.packet.format.PacketFormat#format(MetaPacket,
org.jnetstream.packet.MetaHeader)public PacketFormatter format(Packet packet)
packet -
java.io.IOExceptionorg.jnetstream.packet.format.PacketFormat#format(org.jnetstream.packet.MetaPacket)
public java.util.Formatter format(java.lang.String format,
java.lang.Object... args)
delagate - args -
Formatter.format(java.lang.String, java.lang.Object[])public java.io.IOException ioException()
Formatter.ioException()public java.util.Locale locale()
Formatter.locale()public java.lang.Appendable out()
Formatter.out()protected java.util.Locale setLocale(java.util.Locale l)
protected void setOut(java.lang.Appendable o)
protected void setPlatformFormatter(java.util.Formatter f)
public java.lang.String toString()
toString in class java.lang.Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||