All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class ORG.oclc.ber.BerString

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

public class BerString
extends ASN1
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()); 
 

Version:
@(#)BerString.java 1.1 07/09/97
See Also:
ASN1, BufferedBerStream

Constructor Index

 o BerString(byte[])
 o BerString(DataDir)
Build a ber_record from a directory.
 o BerString(DataDir, int, int)
Build a ber_record from a directory and leave space in the buffer for other data to be provided by the application.
 o BerString(InputStream)
Read a ber_record from the InputStream.

Method Index

 o asn1Len()
Find the length of a BER record.
 o getLen(int[])
Get a length directly from a BER record.
 o getTag(int[])
Get a tag directly from a BER record.
 o IsCompleteBER(int, int, int[])
 o IsCompleteBER(int, int[])
Determine if a complete BER record has been received.
 o putChar(byte[], int)
Put an array of bytes in to a BER record.
 o putChar(byte[], int, int)
 o putLen(int)
Put a length directly into a BER record.
 o putNumber(int)
Put a number into a BER record.
 o putTag(int, byte, byte)
Put a tag directly into a BER record.
 o record()
Accessor method for byte[] record.
 o setOffset(int)
Allows caller to reset offset to beginning of record.
 o toString()
Creates String representation of BER record.
 o toString(int)
Creates String representation of BER record.
 o writeBerString(OutputStream)
Write the BerString to the OutputStream.

Constructors

 o BerString
 public BerString(byte record[])
 o BerString
 public BerString(DataDir dir)
Build a ber_record from a directory.

Parameters:
dir - directory
 o 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
 o 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
Throws: IOException
Error reading InputStream

Methods

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

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

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

 o toString
 public final String toString()
Creates String representation of BER record.

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

Parameters:
length - Truncate output to this length.
 o asn1Len
 public final int asn1Len()
Find the length of a BER record.

Returns:
length
 o getTag
 public final int getTag(int tagLen[])
Get a tag directly from a BER record.

Returns:
tag public final int getTag() { int len = (((record[offset] & 0x1f) != 0x1f) ? 1 : ((record[offset+1]&0xff) < 0x80) ? 2 : 3); int id_code = 0; if (len == 1) id_code = record[offset] & 0x1f; else for (int i = 1; i < len; i++) id_code = (id_code << 7) | (record[i+offset] & 0x7f); offset += len; return id_code; }
 o getLen
 public final int getLen(int fieldlen[])
Get a length directly from a BER record.

Returns:
length of BER record
 o 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
 o putLen
 public final void putLen(int len)
Put a length directly into a BER record.

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

Parameters:
number - number to put
 o 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
 o putChar
 public final void putChar(byte chars[],
                           int toffset,
                           int length)
 o 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.
 o IsCompleteBER
 public final boolean IsCompleteBER(int offset,
                                    int len,
                                    int remainder[])

All Packages  Class Hierarchy  This Package  Previous  Next  Index