Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

jreceiver.util.text
Class WordFormatB  view WordFormatB download WordFormatB.java

java.lang.Object
  extended byjreceiver.util.text.FormatB
      extended byjreceiver.util.text.WordFormatB

public class WordFormatB
extends FormatB

Formatter to output an object in 4 bytes.

Implementation presently assumes 4-byte integers.

Word example:

 String pattern = "{0,word}{1,word,be}{2,word,le}";
 MessageFormatB mfb = new MessageFormatB(pattern);
 Object[] objs = { new Integer(0xAABBCCDD),
                   new Integer(0xAABBCCDD),
                   new Integer(0xAABBCCDD) };
 byte[] = mfb.format(objs);
 
{0,word} encoded as a 4-byte word using the default big-endian (Mac) order (result = AA BB CC DD)

{1,word,be} same as {0}

{2,word,le} encoded as a 4-byte word using the little-endian (Intel) order (result = DD CC BB AA)

There are two byte orders available for formatting words:

 --------------------------- ---------------------------
|            MSB            |           LSB             |
| ------------------------- | ------------------------- |
| Big Endian                | Little Endian             |
| MostSignificantByteFirst  | LeastSignificantByteFirst |
| "Network" Order           | "VAX" order               |
| Java/Sun/Mac/IBM390       | Intel/Windows/AMD/DEC/VAX |
| used by Blefuscudians     | used by Lilliputians      |
| 0xCAFEBABE = CA FE BA BE  | 0xCAFEBABE = BE BA FE CA  |
 --------------------------- ---------------------------
 
MSB is the default of Java and therefore the default of JReceiver.

Version:
$Revision: 1.2 $ $Date: 2002/12/29 00:44:08 $

Field Summary
static int BIG_ENDIAN
           
private  int endian
           
static java.lang.String ID
           
static int LITTLE_ENDIAN
           
 
Constructor Summary
WordFormatB()
           
 
Method Summary
 java.io.ByteArrayOutputStream format(int val, java.io.ByteArrayOutputStream toAppendTo, java.text.FieldPosition pos)
           
 java.io.ByteArrayOutputStream format(java.lang.Object obj, java.io.ByteArrayOutputStream toAppendTo, java.text.FieldPosition pos)
          format the object in 4 bytes
 void setEndian(int endian)
           
 void setOption(java.lang.String option)
          set an option string
 java.lang.String toString()
          Convert this Object to a human-readable String.
 
Methods inherited from class jreceiver.util.text.FormatB
format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ID

public static final java.lang.String ID
See Also:
Constant Field Values

BIG_ENDIAN

public static int BIG_ENDIAN

LITTLE_ENDIAN

public static int LITTLE_ENDIAN

endian

private int endian
Constructor Detail

WordFormatB

public WordFormatB()
Method Detail

setOption

public void setOption(java.lang.String option)
set an option string

Specified by:
setOption in class FormatB

setEndian

public void setEndian(int endian)

format

public final java.io.ByteArrayOutputStream format(java.lang.Object obj,
                                                  java.io.ByteArrayOutputStream toAppendTo,
                                                  java.text.FieldPosition pos)
                                           throws java.io.IOException
format the object in 4 bytes

Specified by:
format in class FormatB

format

public final java.io.ByteArrayOutputStream format(int val,
                                                  java.io.ByteArrayOutputStream toAppendTo,
                                                  java.text.FieldPosition pos)
                                           throws java.io.IOException

toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).

Specified by:
toString in class FormatB