org.otfeed.support
Class BufferFormat

java.lang.Object
  extended by org.otfeed.support.BufferFormat
All Implemented Interfaces:
IFormat<java.nio.ByteBuffer>

public class BufferFormat
extends java.lang.Object
implements IFormat<java.nio.ByteBuffer>

Converts ByteBuffer type to/from a string.

Formats buffer into multi-line string, each line showing up to 16 bytes of the data in a standard "hexdump" format. For example,

 00000001 40360000 00000000 21000001     %....@6......!...
 148a6fe0 69                             %..o.i
 

When parsing, ignores empty lines, and treat separator symbol as start of comment. Therefore, following is a valid input to the parse method:

 %
 % buffer snippet
 %
 00000001 40360000 00000000 21000001     %....@6......!...
 148a6fe0 69                             %..o.i
 


Constructor Summary
BufferFormat()
          Creates format using the default byte-reversed allocation service.
BufferFormat(IBufferAllocator allocator)
          Creates format using the provided allocator service (used for parsing only.
 
Method Summary
 java.lang.String format(java.nio.ByteBuffer buffer)
          Formats an object to a string.
 char getSeparator()
          Symbol that marks the beginnig of comment.
 java.nio.ByteBuffer parse(java.lang.String val)
          Parses object from a string.
 void setSeparator(char val)
          Sets separator character.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufferFormat

public BufferFormat(IBufferAllocator allocator)
Creates format using the provided allocator service (used for parsing only.

Parameters:
allocator - allocator.

BufferFormat

public BufferFormat()
Creates format using the default byte-reversed allocation service.

Method Detail

getSeparator

public char getSeparator()
Symbol that marks the beginnig of comment.

Returns:
separator character.

setSeparator

public void setSeparator(char val)
Sets separator character.

Parameters:
val - separator character.

format

public java.lang.String format(java.nio.ByteBuffer buffer)
Description copied from interface: IFormat
Formats an object to a string.

Specified by:
format in interface IFormat<java.nio.ByteBuffer>
Parameters:
buffer - object to be formatted.
Returns:
string.

parse

public java.nio.ByteBuffer parse(java.lang.String val)
Description copied from interface: IFormat
Parses object from a string.

Specified by:
parse in interface IFormat<java.nio.ByteBuffer>
Parameters:
val - string representation of an object.
Returns:
parsed object.


Copyright © 2007 Mike Kroutikov. All Rights Reserved.