CADI.Client.Network
Class JPIPMessageDecoder

java.lang.Object
  extended by CADI.Client.Network.JPIPMessageDecoder

public class JPIPMessageDecoder
extends java.lang.Object

This class reads JPIP messages as they are defined in ISO/IEC 15444-9 section A.2. Each time the readMessage() method is called, only one JPIP message is read. And the method who is calling must be taken into account when a JPIP End Of Response message is received, then it must not call the readMessage() method. If it call after the JPIP End Of Response message is received, a IOException will be thrown.

This class needs a input stram where data are readed from. This class only needs a read method to read a byte value and a readFully method to read a byte array.

Usage example:
  construct
  setParameters
  readMessage
  ....
  readMessage

Version:
1.0 2008/01/10
Author:
Group on Interactive Coding of Images (GICI)

Field Summary
private  long headerLength
          Indicates the length of the JPIP message header.
(package private)  HTTPResponseReader inputStreamReader
          It is the input stream where data are read from.
private  int lastClass
          Contains the last Class value.
private  int lastCSn
          Contains the last CSn value.
 
Constructor Summary
JPIPMessageDecoder()
          Constructor.
 
Method Summary
 void list(java.io.PrintStream out)
          Prints this JPIP Message Decoder fields out to the specified output stream.
private  JPIPMessage readEORMessage()
          Reads the End Of Response message.
 JPIPMessage readMessage()
          This method is used to read a JPIP messase.
private  long readVBAS()
          Reads a Variable-length Byte-Aligned Segment.
 void setParameters(HTTPResponseReader inputStreamReader)
          Sets the input stream where the data are read from.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

inputStreamReader

HTTPResponseReader inputStreamReader
It is the input stream where data are read from.


lastClass

private int lastClass
Contains the last Class value. It is a state variable used when dependent form is used.


lastCSn

private int lastCSn
Contains the last CSn value. It is a state variables used when dependent form is used.


headerLength

private long headerLength
Indicates the length of the JPIP message header. This attribute is useful for statistics.

Constructor Detail

JPIPMessageDecoder

public JPIPMessageDecoder()
Constructor.

Method Detail

setParameters

public void setParameters(HTTPResponseReader inputStreamReader)
Sets the input stream where the data are read from. This method must be called before another one is called.

Parameters:
inputStreamReader - definition in inputStreamReader

readMessage

public JPIPMessage readMessage()
                        throws java.net.ProtocolException,
                               java.io.IOException
This method is used to read a JPIP messase. Data are read from the input stream, they are decoded, and a JPIPMessage object is built.

Returns:
a JPIPMessage object.
Throws:
java.net.ProtocolException - if received data can not be decoded correctly.
java.io.IOException - if data can not be read from the input stream. It may be because the link is broken, the server closed the connection, ...

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

list

public void list(java.io.PrintStream out)
Prints this JPIP Message Decoder fields out to the specified output stream. This method is useful for debugging.

Parameters:
out - an output stream.

readVBAS

private long readVBAS()
               throws java.io.IOException
Reads a Variable-length Byte-Aligned Segment.

Returns:
the value which has been read from the VBAS.
Throws:
java.io.IOException - if an I/O error occurs.

readEORMessage

private JPIPMessage readEORMessage()
                            throws java.io.IOException
Reads the End Of Response message. Further information see ISO/IEC 15444-9 Annex D.3

Returns:
a JPIPMessage object with the End Of Response.
Throws:
java.io.IOException - if an I/O error occurs.


CADI - Copyright (C) 2007
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Group on Interactive Coding of Images (GICI) (contact)