CADI.Server.Network
Class JPIPMessageEncoder

java.lang.Object
  extended by CADI.Server.Network.JPIPMessageEncoder

public class JPIPMessageEncoder
extends java.lang.Object

The class JPIPMessageEncoder is usefull to encode JPIP messages. It contains the JPIP header that provides descriptive information to identify the JPIP message in the data-bin.

Usage example:
  constructor
  [setIndependentForm]
  encoderHeader

Version:
1.0.1 2009/08/13
Author:
Group on Interactive Coding of Images (GICI)

Field Summary
private  byte[] encodedHeader
          It is an byte array where the encoded JPIP Message Header is stored.
private  JPIPMessageHeader header
          Contains the JPIP message header.
private  boolean independentForm
          Message header can take an independent form and a dependent form.
private  int lastClass
          Contains the last Class value.
private  int lastCSn
          Contains the last CSn value.
private  int position
          It is an index that indicates the position in jpipMessageHeader.
 
Constructor Summary
JPIPMessageEncoder()
          Default constructor.
JPIPMessageEncoder(boolean independentForm)
          Constructor
 
Method Summary
private static int calculateNecessaryBytes(long value)
          Calculate the number of bytes that are necessary to encode a value using the VBAS.
private  void encodeEOR()
          ISO/IEC 15444-9 section D.3
private  byte[] encoderHeader(boolean completeDataBin, long InClassIdentifier, int Class, int CSn, long MsgOffset, long MsgLength, int Aux)
          The message header consists of a sequence of bytes, all but the last of which has a most significant bit (bit 7) of 1.
 byte[] encoderHeader(JPIPMessageHeader header)
          Encodes a JPIP Message Header following a sequence of variable-length byte-aligned segments (VBAS).
 void list(java.io.PrintStream out)
          Prints this JPIP Message Encoder fields out to the specified output stream.
 void reset()
          Sets the attributes to its initial vaules.
 void setIndependentForm(boolean independentForm)
          Sets the independent form for encoding the JPIP message header or the dependent form.
 java.lang.String toString()
          Returns this JPIP Message as a String.
private  void writeVBASInteger(long value)
          Encodes a value with with a VBAS in a buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

header

private JPIPMessageHeader header
Contains the JPIP message header.


encodedHeader

private byte[] encodedHeader
It is an byte array where the encoded JPIP Message Header is stored.


position

private int position
It is an index that indicates the position in jpipMessageHeader. This variable is used in the encodeHeader and writeVBASInteger methods.


independentForm

private boolean independentForm
Message header can take an independent form and a dependent form. The independent form is a long form where the message headers are completely self-describing; their interpretation is independent of any other message headers. The optional shorter dependent form message headers make use of information in the headers of previous message; their decoding is dependant on the previous message.


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.

Constructor Detail

JPIPMessageEncoder

public JPIPMessageEncoder()
Default constructor.


JPIPMessageEncoder

public JPIPMessageEncoder(boolean independentForm)
Constructor

Parameters:
independentForm - definition in independentForm.
Method Detail

reset

public void reset()
Sets the attributes to its initial vaules.


setIndependentForm

public void setIndependentForm(boolean independentForm)
Sets the independent form for encoding the JPIP message header or the dependent form.

Parameters:
independentForm - if true, the independent form is used. False, the header is built using the dependent form.

encoderHeader

public byte[] encoderHeader(JPIPMessageHeader header)
Encodes a JPIP Message Header following a sequence of variable-length byte-aligned segments (VBAS). The message header consists of a sequence of bytes, all but the last of which has a most significant bit (bit 7) of 1. The least significant 7 bits of each byte in the VBAS ar concatenated to form a bit stream which is used in differents ways for differents VBASs.

Message header format:
Bin-ID [,Class] [,CSn], Msg-Offset, Msg-Length [,Aux] where Bin-ID = BinIDIndicator, completeDataBin InClassIdentifier


toString

public java.lang.String toString()
Returns this JPIP Message as a String. It is useful for debugging purposes.

Overrides:
toString in class java.lang.Object

list

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

Parameters:
out - an output stream.

encodeEOR

private void encodeEOR()
ISO/IEC 15444-9 section D.3


encoderHeader

private byte[] encoderHeader(boolean completeDataBin,
                             long InClassIdentifier,
                             int Class,
                             int CSn,
                             long MsgOffset,
                             long MsgLength,
                             int Aux)
The message header consists of a sequence of bytes, all but the last of which has a most significant bit (bit 7) of 1. The least significant 7 bits of each byte in the VBAS ar concatenatedto form a bit stream which is used in differents ways for differents VBASs.

Message header format:
Bin-ID [,Class] [,CSn], Msg-Offset, Msg-Length [,Aux] where Bin-ID = BinIDIndicator, completeDataBin InClassIdentifier


writeVBASInteger

private void writeVBASInteger(long value)
Encodes a value with with a VBAS in a buffer. The first encoded byte will be located in a specified position of the buffer.

Parameters:
value - the value to be encoded.

calculateNecessaryBytes

private static int calculateNecessaryBytes(long value)
Calculate the number of bytes that are necessary to encode a value using the VBAS.

Parameters:
value - the value to encode
Returns:
the necessary bytes


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)