package ifc.bim.openecg.jtools.jparser; /** *
Title: SCP-ECG Section Header
*Description: The structure of a generic section, with methods to load header and data part from a file
*Company: Ist. Fisiologia Clinica del CNR via G.Moruzzi,1 54124 Pisa Italy
* @authors Giacomo Ciani - Fabrizio Conforti (conforti@ifc.cnr.it) * @version 1.0 */ import java.io.*; import java.nio.*; import java.util.*; import java.util.logging.*; import javax.imageio.stream.*; /** * The structure of a generic section, with methods to load header and data part from a file */ public class SectGen { /** Stores the section's header*/ public SectHeader head; /** Stores the section's data part*/ public byte[] data; /** Log error and info messages produced during the section's load operation*/ public Logger log; /** The start index for reading operations*/ public int indx; /** * Constructs a SectGen with an anonymous logger */ public SectGen(){ this( Logger.getAnonymousLogger() ); } /** * Constructs a SectGen that uses a specific logger * @param log the logger to be used */ public SectGen(Logger log){ this.log=log; head = new SectHeader(); } /** * Reads a byte from "data" starting at index "indx", and returns it as a byte value. * @return A byte value * @throws IndexOutOfBoundsException if the index "idx" is greater tha the array length. */ public byte readByte(){ return data[indx++]; } /** * Reads two bytes from "data" starting at index "indx", and (conceptually) concatenates * them according to Little Endian byte order, and returns the result as a short value. * @return A short value * @throws IndexOutOfBoundsException if the end of the array is reached before all bytes are read. */ public short readShort(){ int lsb=data[indx++]; int hsb=data[indx++]; return (short)(256*hsb+(0x000000ff&lsb)); } /** * Reads four bytes from "data" starting at index "indx", and (conceptually) concatenates * them according to Little Endian byte order, and returns the result as an int value. * @return An int value * @throws IndexOutOfBoundsException if the end of the array is reached before all bytes are read. */ public int readInt(){ int lsb=readShort(); int hsb=readShort(); return (65536*hsb+(0x0000ffff&lsb)); } /** * Reads "dest.len" bytes from "data" starting at index "idx", and stores them into "dest". * If the end of the "data" array is reached, an EOFException will be thrown. * @param dest an array of bytes * @throws IndexOutOfBoundsException if the stream reaches the end before reading all the bytes. * Bytes already read are stored anyway. */ public void readFully(byte[] dest) { for (int i=0; i