com.objsys.asn1j.runtime
Class Asn1JsonDecodeBuffer

java.lang.Object
  extended by com.objsys.asn1j.runtime.Asn1MessageBufferBase
      extended by com.objsys.asn1j.runtime.Asn1JsonDecodeBuffer

public class Asn1JsonDecodeBuffer
extends Asn1MessageBufferBase

Decode buffer for decoding JSON-encoded data.


Field Summary
 
Fields inherited from class com.objsys.asn1j.runtime.Asn1MessageBufferBase
context, mTypeCode
 
Constructor Summary
Asn1JsonDecodeBuffer(java.io.InputStream stream)
          Create Asn1JsonDecodeBuffer on the given input byte stream.
Asn1JsonDecodeBuffer(java.io.Reader reader)
          Create Asn1JsonDecodeBuffer on the given reader.
 
Method Summary
 boolean nextCharacterIs(char c)
          Returns true if the next character is the given character.
 boolean nextCharacterIsNot(char c)
          Returns true if the next character not the given character.
 boolean readBoolean()
          Reads "true" or "false" from input and returns the corresponding boolean value.
 void readCharacter(char matchChar)
          Read the given character from input.
 int readInt()
          Convenience method equivalent to Integer.parseInt( this.readNumber() )
 java.lang.String readJsonValue()
          Read the next JSON value from the input.
 void readNull()
          Reads "null" from input.
 java.lang.String readNumber()
          Read a JSON number from input.
 java.lang.String readString()
          Read a JSON string from the input.
 void readString(java.lang.String expectedValue)
          Convenience method which invokes readString() and throws an exception if the result is not the expectedValue.
 int seekCharacter()
          Seeks past whitespace in the input to find the next input character.
 void skipWhitespace()
          Skip (read past) all whitespace on input until there is no more input or a nonwhitespace character is the next character of input.
 
Methods inherited from class com.objsys.asn1j.runtime.Asn1MessageBufferBase
getContext, hexDump, hexDump, setKey, setTypeCode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Asn1JsonDecodeBuffer

public Asn1JsonDecodeBuffer(java.io.Reader reader)
Create Asn1JsonDecodeBuffer on the given reader.


Asn1JsonDecodeBuffer

public Asn1JsonDecodeBuffer(java.io.InputStream stream)
Create Asn1JsonDecodeBuffer on the given input byte stream. The constructor will automatically detect the variety of UTF character encoding, following IETF RFC 4627. Note: on Java ME, the input stream is currently assumed to be UTF-8.

Parameters:
stream -
Method Detail

skipWhitespace

public void skipWhitespace()
                    throws java.io.IOException
Skip (read past) all whitespace on input until there is no more input or a nonwhitespace character is the next character of input.

Throws:
java.io.IOException

nextCharacterIs

public boolean nextCharacterIs(char c)
                        throws java.io.IOException
Returns true if the next character is the given character. This uses seekCharacter to see what the next character is and returns true if and only if there is a next character and it is the given character.

Throws:
java.io.IOException

nextCharacterIsNot

public boolean nextCharacterIsNot(char c)
                           throws java.io.IOException
Returns true if the next character not the given character. This uses seekCharacter to see what the next character is and returns true if and only if there is a next character and it is not the given character.

Throws:
java.io.IOException

seekCharacter

public int seekCharacter()
                  throws java.io.IOException
Seeks past whitespace in the input to find the next input character. This will skip any whitespace in the input until it finds the next input character, call it X. 'X' is not read, so all of the read* methods will still see this character, and repeated calls to seekCharacter will return the same character.

Throws:
java.io.IOException

readCharacter

public void readCharacter(char matchChar)
                   throws java.io.IOException
Read the given character from input. Leading whitespace is skipped. This will read the next character of input. If it matches the given token, this method simply returns. If there is no next character, or if the next character is not the given character, an exception is thrown.

Parameters:
matchChar - The character expected on input.
Throws:
Asn1Exception - if the expected character token is not present
java.io.IOException

readInt

public int readInt()
            throws java.io.IOException
Convenience method equivalent to Integer.parseInt( this.readNumber() )

Throws:
java.io.IOException

readNumber

public java.lang.String readNumber()
                            throws java.io.IOException
Read a JSON number from input. This will skip any whitespace ahead of the number. If a JSON number is not available in the input, an exception is thrown.

Returns:
A JSON number as a string. It is guaranteed to be a valid JSON number.
Throws:
java.io.IOException

readJsonValue

public java.lang.String readJsonValue()
                               throws java.io.IOException
Read the next JSON value from the input. Whitespace ahead of the next JSON value is skipped. If a JSON value cannot be read from the input, an exception is thrown. This method will generally be useful in reading an entire JSON object, array, or number. It returns every character of input making up the JSON value (i.e., it does not discard whitespace within the JSON value, or translate escaped characters inside JSON strings). To read a JSON string, or the literals true, false, or null, see readString, readBoolean, and readNull.

Returns:
Throws:
Asn1Exception - if a JSON value cannot be read.
java.io.IOException

readString

public void readString(java.lang.String expectedValue)
                throws java.io.IOException
Convenience method which invokes readString() and throws an exception if the result is not the expectedValue.

Parameters:
expectedValue -
Throws:
java.io.IOException

readString

public java.lang.String readString()
                            throws java.io.IOException
Read a JSON string from the input. Whitespace ahead of the string is skipped. If a JSON string is not next on input, an exception is thrown.

Returns:
The JSON string, without the delimiting quote marks and with character escapes applied.
Throws:
Asn1Exception - if a JSON string is not on input.
java.io.IOException

readBoolean

public boolean readBoolean()
                    throws java.io.IOException
Reads "true" or "false" from input and returns the corresponding boolean value. If the input does not match "true" or "false", an exception is thrown. Whitespace ahead of the "true" or "false" value is skipped.

Returns:
Throws:
Asn1Exception - if a literal true or false value is not on input.
java.io.IOException

readNull

public void readNull()
              throws java.io.IOException
Reads "null" from input. If the input does not match "null", an exception is thrown. Whitespace ahead of the null value is skipped.

Throws:
Asn1Exception - if a literal null value is not on input.
java.io.IOException