Open SiteSearch 4.1.1
Final

ORG.oclc.ber
Class BerString

java.lang.Object
  |
  +--ORG.oclc.ber.ASN1
        |
        +--ORG.oclc.ber.BerString

public class BerString
extends ASN1
implements Serializable

BerString is a class for BER encoded strings.

Here is an example to read a BER record from System.in, build a DataDir tree over the BER record and write a formatted version of the DataDir tree to System.out.

 BerString berRec = new BerString(System.in);
 DataDir dir = new DataDir(berRec);
 System.out.println(dir.toString()); 
 

The BER utilities are available via anonymous ftp to ftp.rsch.oclc.org and are in the pub/BER_utilities directory. They are available in either a C version (as source) or a Java version (as class files).

See Also:
ASN1, BufferedBerStream, Serialized Form

Field Summary
 boolean EOFFound
           
protected  boolean indefinite
           
protected  int offset
           
protected  byte[] record
           
 
Fields inherited from class ORG.oclc.ber.ASN1
APPLICATION, arbitrary, BITSTRING, BOOLEAN, CONSTRUCTED, CONTEXT, ENUMERATED, EXTERNAL, GENERALSTRING, INTEGER, NULL, OBJECTDESCRIPTOR, OBJECTIDENTIFIER, octet_aligned, OCTETSTRING, PRIMITIVE, PRIVATE, SEQUENCE, SET, single_ASN1_type, UNIVERSAL, VISIBLESTRING
 
Constructor Summary
BerString(byte[] record)
           
BerString(DataDir dir)
          Build a ber_record from a directory.
BerString(DataDir dir, int extraLength, int offset)
          Build a ber_record from a directory and leave space in the buffer for other data to be provided by the application.
BerString(InputStream in)
          Read a ber_record from the InputStream.
 
Method Summary
 int asn1Len()
          Find the length of a BER record.
 int getLen(int[] fieldlen)
          Get a length directly from a BER record.
 int getTag()
          Get a tag directly from a BER record.
 int getTag(int[] tagLen)
          Get a tag directly from a BER record and fill in the tagLen in the incoming integer array.
 boolean IsCompleteBER(int len, int[] remainder)
          Determine if a complete BER record has been received.
 boolean IsCompleteBER(int offset, int len, int[] remainder)
           
 void putChar(byte[] chars, int length)
          Put an array of bytes in to a BER record.
 void putChar(byte[] chars, int toffset, int length)
           
 void putLen(int len)
          Put a length directly into a BER record.
 void putNumber(long number)
          Put a number into a BER record.
 void putTag(int fldid, byte asn1class, byte form)
          Put a tag directly into a BER record.
 byte[] record()
          Accessor method for byte[] record.
 void setOffset(int offset)
          Allows caller to reset offset to beginning of record.
 String toString()
          Creates String representation of BER record.
 String toString(int length)
          Creates String representation of BER record.
 void writeBerString(OutputStream out)
          Write the BerString to the OutputStream.
 
Methods inherited from class ORG.oclc.ber.ASN1
getLong, getNum, lenLen, numLen, putNum, tagLen
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

record

protected byte[] record

offset

protected int offset

indefinite

protected boolean indefinite

EOFFound

public boolean EOFFound
Constructor Detail

BerString

public BerString(byte[] record)

BerString

public BerString(DataDir dir)
Build a ber_record from a directory.
Parameters:
dir - directory

BerString

public BerString(DataDir dir,
                 int extraLength,
                 int offset)
Build a ber_record from a directory and leave space in the buffer for other data to be provided by the application. This is a tricky one but it's very useful. The BER record is often only part of a record being built for inclusion in a package to be given to telecom and the BER record gets headers and trailers. If you use 'new BerString(DataDir)', it will allocate space for the record and build the record and then you'll have to move the BER record over to the area where your telecom message is being built. Ralph hates moving data unnecessarily. A preferable method is to leave room in the BER record buffer for the header and trailer information.
int header_size = 13, trailer_size = 14;
DataDir dir; // BER record you want between header & trailer
BerString berRec = new BerString(dir, header_size + trailer_size,
header_size);
Parameters:
dir - directory
length - additional space requested
offset - where to build the BER record in the new buffer

BerString

public BerString(InputStream in)
          throws FileNotFoundException,
                 IOException,
                 EOFException
Read a ber_record from the InputStream.
Parameters:
in - InputStream
Throws:
FileNotFoundException - Creation of BufferedInputStream failed
IOException - Error reading InputStream
Method Detail

record

public byte[] record()
Accessor method for byte[] record.

setOffset

public void setOffset(int offset)
Allows caller to reset offset to beginning of record.

writeBerString

public final void writeBerString(OutputStream out)
                          throws IOException
Write the BerString to the OutputStream.

toString

public final String toString()
Creates String representation of BER record.
Overrides:
toString in class Object

toString

public final String toString(int length)
Creates String representation of BER record.
Parameters:
length - Truncate output to this length.

asn1Len

public final int asn1Len()
Find the length of a BER record.
Returns:
length

getTag

public final int getTag()
Get a tag directly from a BER record.
Returns:
tag

getTag

public final int getTag(int[] tagLen)
Get a tag directly from a BER record and fill in the tagLen in the incoming integer array.
Returns:
tag

getLen

public final int getLen(int[] fieldlen)
Get a length directly from a BER record.
Returns:
length of BER record

putTag

public final void putTag(int fldid,
                         byte asn1class,
                         byte form)
Put a tag directly into a BER record.
Parameters:
fldid - fldid of tag
asn1class - class of tag
form - form of tag

putLen

public final void putLen(int len)
Put a length directly into a BER record.
Parameters:
length - length to put into record

putNumber

public final void putNumber(long number)
Put a number into a BER record.
Parameters:
number - number to put

putChar

public final void putChar(byte[] chars,
                          int length)
Put an array of bytes in to a BER record.
Parameters:
chars - array of bytes
length - number of bytes to copy into record

putChar

public final void putChar(byte[] chars,
                          int toffset,
                          int length)

IsCompleteBER

public final boolean IsCompleteBER(int len,
                                   int[] remainder)
Determine if a complete BER record has been received.
Parameters:
len - length of BER record
remainder - number of bytes missing from record, or 0
Returns:
true or false. If false, the remainder will tell you how many bytes need to be read. This value could be 0, which means that the record has indeterminate length or that you haven't even received the length portion of the record yet. How you read the remainder of the record, in this case, will depend on the access method. Best to just read 1 byte at a time until IsCompleteBER() tells you that you are done or gives you a definite length to read. If true, remainder[0] is set to the actual length of the record.

IsCompleteBER

public final boolean IsCompleteBER(int offset,
                                   int len,
                                   int[] remainder)

Open SiteSearch 4.1.1
Final