net.sourceforge.foobase
Class CBFUtil

java.lang.Object
  |
  +--net.sourceforge.foobase.CBFUtil

public class CBFUtil
extends java.lang.Object

Class containing a number of usefull methods for old-style chessbase databases.

The code in this class consists of static methods.


Field Summary
static java.lang.String __version
           
 
Constructor Summary
CBFUtil()
           
 
Method Summary
static java.lang.String bytesToString(byte[] bar, int ofs, int len)
          Convert input byte array containing annotated text from a database to String format using the required encoding for this package.
static void decodeHeader(byte[] hdr)
          Decode a game header from its file format.
static void decodeHeaderText(byte[] hdrtxt)
          Decode or encode the specified header text.
static void encodeHeader(byte[] hdr)
          Encode a game header into the file format.
static char evalToString(byte b)
          Convert an evaluation byte to proper internal code.
static boolean isChecksumValid(byte[] hdr)
          Compute checksum on decoded header and check if it matches the specified checksum in that header.
static boolean isPreferredChecksumValid(byte[] hdr)
          Compute checksum on decoded header and check if it matches the specified checksum in that header.
static char movEvalToString(byte b)
          Convert a move evaluation byte to proper internal code.
static char posEvalToString(byte b)
          Convert a position evaluation byte to proper internal code.
static void setChecksum(byte[] hdr)
          Set checksum in header data.
static byte[] stringToBytes(java.lang.String s)
          Convert a normalized string to byte array suitable for storage in oldstyle chessbase database.
static byte stringToEval(java.lang.String s)
          Convert an internal evaluation code to proper byte value.
static byte stringToMovEval(java.lang.String s)
          Convert an internal move evaluation code to proper byte value.
static byte stringToPosEval(java.lang.String s)
          Convert an internal position evaluation code to proper byte value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

__version

public static final java.lang.String __version
Constructor Detail

CBFUtil

public CBFUtil()
Method Detail

decodeHeader

public static void decodeHeader(byte[] hdr)
Decode a game header from its file format.

On return, the input buffer contains the decoded version of the header (this is an "in-place" operation)

Parameters:
hdr - byte[] containing the encoded 14-byte header

encodeHeader

public static void encodeHeader(byte[] hdr)
Encode a game header into the file format.

On return, the input buffer contains the encoded version of the header (this is an "in-place" operation)

Parameters:
hdr - byte[] containing the 14-byte decoded header

decodeHeaderText

public static void decodeHeaderText(byte[] hdrtxt)
Decode or encode the specified header text.

Decoding decoded text results back in the original encoded text, so there is only one coding method required.

Coding occurs in place (that is: the input array is changed)

Parameters:
hdrtxt - byte[] containing the text to decode

isChecksumValid

public static boolean isChecksumValid(byte[] hdr)
Compute checksum on decoded header and check if it matches the specified checksum in that header.
Parameters:
hdr - byte[] containing the 14-byte decoded header data
Returns:
boolean value true if the computed checksum matches the specified checksum.

isPreferredChecksumValid

public static boolean isPreferredChecksumValid(byte[] hdr)
Compute checksum on decoded header and check if it matches the specified checksum in that header.
Parameters:
hdr - byte[] containing the 14-byte decoded header data
Returns:
boolean value true if the computed checksum matches the specified checksum.

setChecksum

public static void setChecksum(byte[] hdr)
Set checksum in header data.

The computed checksum is stored in the input byte[].

Parameters:
hdr - byte]\ containing the 14-byte decoded header data.

bytesToString

public static java.lang.String bytesToString(byte[] bar,
                                             int ofs,
                                             int len)
Convert input byte array containing annotated text from a database to String format using the required encoding for this package.
Parameters:
bar - byte[] containing the input data to process
ofs - int containing the start offset from where to process bar
len - int containing the number of bytes to process
Returns:
String containing the input data with special codes converted to symbols

evalToString

public static char evalToString(byte b)
Convert an evaluation byte to proper internal code.
Parameters:
b - byte to convert
Returns:
char containing the internal code for the evaluation

stringToEval

public static byte stringToEval(java.lang.String s)
Convert an internal evaluation code to proper byte value.
Parameters:
s - String to convert
Returns:
byte containing the corresponding byte code to store in oldstyle chessbase databases.

posEvalToString

public static char posEvalToString(byte b)
Convert a position evaluation byte to proper internal code.
Parameters:
b - byte to convert
Returns:
char containing the internal code for the position evaluation

stringToPosEval

public static byte stringToPosEval(java.lang.String s)
Convert an internal position evaluation code to proper byte value.
Parameters:
s - String to convert
Returns:
byte containing the corresponding byte code to store in oldstyle chessbase databases.

movEvalToString

public static char movEvalToString(byte b)
Convert a move evaluation byte to proper internal code.
Parameters:
b - byte to convert
Returns:
char containing the internal code for the move evaluation

stringToMovEval

public static byte stringToMovEval(java.lang.String s)
Convert an internal move evaluation code to proper byte value.
Parameters:
s - String to convert
Returns:
byte containing the corresponding byte code to store in oldstyle chessbase databases.

stringToBytes

public static byte[] stringToBytes(java.lang.String s)
Convert a normalized string to byte array suitable for storage in oldstyle chessbase database.
Parameters:
s - String to convert
Returns:
byte[] containing the converted string