Package gov.nih.mipav.model.dicomcomm
Class DICOM_Comms
- java.lang.Object
- 
- gov.nih.mipav.model.dicomcomm.DICOM_Comms
 
- 
- Direct Known Subclasses:
- DICOM_CommsLink,- DICOM_FileIO,- DICOM_PDUService
 
 public class DICOM_Comms extends java.lang.ObjectThis class is used as a base class for all DICOM file and network I/O.
 This DICOM communication package was originally based on the Java Dicom Package, whose license is below:Java Dicom Package (com.zmed.dicom) Copyright (c) 1996-1997 Z Medical Imaging Systems, Inc. This software is provided, as is, for non-commercial educational purposes only. Use or incorporation of this software or derivative works in commercial applications requires written consent from Z Medical Imaging Systems, Inc. Z MEDICAL IMAGING SYSTEMS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, OR CONFORMANCE TO ANY SPECIFICATION OR STANDARD. Z MEDICAL IMAGING SYSTEMS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING OR MODIFYING THIS SOFTWARE OR ITS DERIVATIVES. ============================================================================= This software package is implemented similarly to the UC Davis public domain C++ DICOM implementation which contains the following copyright notice: Copyright (C) 1995, University of California, Davis THIS SOFTWARE IS MADE AVAILABLE, AS IS, AND THE UNIVERSITY OF CALIFORNIA DOES NOT MAKE ANY WARRANTY ABOUT THE SOFTWARE, ITS PERFORMANCE, ITS MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES OR ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH THE USER. Copyright of the software and supporting documentation is owned by the University of California, and free access is hereby granted as a license to use this software, copy this software and prepare derivative works based upon this software. However, any distribution of this software source code or supporting documentation or derivative works (source code and supporting documentation) must include this copyright notice. The UC Davis C++ source code is publicly available from the following anonymous ftp site: ftp://imrad.ucdmc.ucdavis.edu/pub/dicom/UCDMC/ 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description protected classDICOM_Comms.ByteBufferSimple inner class to facilitate the memory allocation of of a byte buffer used in DICOM_Comms to support I/O.
 - 
Field SummaryFields Modifier and Type Field Description static intBIG_ENDIANFlag used to indicate Big Endianess.protected intbreakSizeDefaults to the maximum buffer size in streaming.private byte[]byteArray1One byte array allocated once to speed process and reduced the need to reallocate memory.private byte[]byteArray2Two byte array allocated once to speed process and reduced the need to reallocate memory.private byte[]byteArray4Four byte array allocated once to speed process and reduced the need to reallocate memory.private booleandebugFlagDebug flag.private booleanhavePeekedFlag indicating whether the first byte has been looked at.protected intinBuffersLengthLength of the total input data (Not buffer size but total length of data ).protected java.util.Vector<DICOM_Comms.ByteBuffer>incomingBuffersVector of ByteBuffer's of incoming data.private intinEndianessEndianess of the input stream.static intLITTLE_ENDIANFlag used to indicate Little Endianess.static intMAX_READ_LENGTHThe maximum read buffer size.protected intoutBuffersLengthLength of the total output data (Not buffer size but total length of data ).private intoutEndianessEndianess of the output stream.protected java.util.Vector<DICOM_Comms.ByteBuffer>outgoingBuffersVector of ByteBuffer's of outgoing data.private bytepeekedByteStorage for the first byte (i.e. the PDU type )private byte[]srcByteArraySource byte array allocated ONCE used in reading from the stream.
 - 
Constructor SummaryConstructors Constructor Description DICOM_Comms()Constructor for DICOM network I/O class.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static intbufferToInt16(byte[] buffer, int index, int endianess)Copies a 2 byte array into a 16 bit integer of proper endianess.static intbufferToInt32(byte[] buffer, int index, int endianess)Copies a 4 byte array into a 32 bit integer of proper endianess.protected voidfinalize()Prepares this class for destruction.voidflush()Sends all byte buffers of the outgoing buffer vector out the port. see DICOM PDUService.sendBinary and DICOMSocketvoidflush(int nBytes)Sends specified number of bytes out the port. see DICOM PDUService.sendBinary and DICOMSocketintgetIncomingEndian()Returns constant indicating endianess of incoming data.intgetIncomingSize()Returns the incoming data size.intgetOutgoingEndian()Returns constant indicating endianess of outgoing data.intgetOutgoingSize()Returns the outgoing data size.static voidint16ToBuffer(byte[] buffer, int index, int value, int endianess)Copies a 16 bit (2 bytes) integer into the specified portion of the byte array of proper endianess.static voidint32ToBuffer(byte[] buffer, int index, int value, int endianess)Copies a 32 bit (4 bytes) integer into the specified portion of the byte array of proper endianess.bytepeekFirstByte()Typically used to determine the PDUTYPE (i.e.intpeekForEndOfSequence()DOCUMENT ME!voidread(byte[] data)Simple method that take a byte array and call read with two parameters: byte array and array length.voidread(byte[] data, int nBytes)Reads a specified number of bytes into the byte data buffer.intreadBinary(byte[] data, int nbytes)Dummy method and should be overloaded by DICOMPDUService.private voidreadBlock(int useBreakSize)This is the method that actually reads in the data from the socket or IO stream.bytereadByte()Reads a single byte from the data stream.byte[]readBytes(int length)Allocates and.voidreadFill(int nBytes)Reads in a nBytes and puts them in a ByteBuffer and puts the byte buffer in the vector of incomingBuffers.intreadInt32()Reads a 4 byte integer (otherwise known as an int).intreadShort16()Reads a 2 byte integer (otherwise known as a short).voidseekToEndOfGroupTwoTags()Strips preamble and group 2 tags from ioBuffer if present.voidsendBinary(byte[] data, int startIndex, int nbytes)Dummy method and should be overloaded by DICOMPDUService.voidsetIncomingEndianess(int endianess)Sets the endianess for the incoming data.voidsetOutgoingEndianess(int endianess)Sets the endianess for the outgoing data.voidwrite(byte[] byteArray)Writes a byte arrary to the outgoing buffers.voidwrite(byte[] data, int dataOffset, int nBytes)Writes a specified number of bytes from the byte buffer into outGoing ByteBuffer list of byte buffers.voidwriteByte(byte value)Writes a byte to the outgoing buffers.voidwriteByteIn(byte value, DICOM_FileIO ioBuffer)Writes a byte to the incoming buffers.voidwriteIn(byte[] data, int dataOffset, int nBytes, DICOM_FileIO ioBuffer)Writes a specified number of bytes from the byte buffer into incomming ByteBuffer list of byte buffers.voidwriteInt32(int value)Writes a 32 (4 byte) integer to the outgoing buffers.voidwriteInt32In(int value, DICOM_FileIO ioBuffer)Writes a 32 (4 byte) integer to the incoming buffers.voidwriteShort16(int value)Writes a 16 (2 byte) integer to the outgoing buffers.voidwriteShort16In(int value, DICOM_FileIO ioBuffer)Writes a 16 (2 byte) integer to the incomming buffers.
 
- 
- 
- 
Field Detail- 
BIG_ENDIANpublic static final int BIG_ENDIAN Flag used to indicate Big Endianess.- See Also:
- Constant Field Values
 
 - 
LITTLE_ENDIANpublic static final int LITTLE_ENDIAN Flag used to indicate Little Endianess.- See Also:
- Constant Field Values
 
 - 
MAX_READ_LENGTHpublic static final int MAX_READ_LENGTH The maximum read buffer size.- See Also:
- Constant Field Values
 
 - 
breakSizeprotected int breakSize Defaults to the maximum buffer size in streaming.
 - 
inBuffersLengthprotected int inBuffersLength Length of the total input data (Not buffer size but total length of data ).
 - 
incomingBuffersprotected java.util.Vector<DICOM_Comms.ByteBuffer> incomingBuffers Vector of ByteBuffer's of incoming data.
 - 
outBuffersLengthprotected int outBuffersLength Length of the total output data (Not buffer size but total length of data ).
 - 
outgoingBuffersprotected java.util.Vector<DICOM_Comms.ByteBuffer> outgoingBuffers Vector of ByteBuffer's of outgoing data.
 - 
byteArray1private byte[] byteArray1 One byte array allocated once to speed process and reduced the need to reallocate memory.
 - 
byteArray2private byte[] byteArray2 Two byte array allocated once to speed process and reduced the need to reallocate memory.
 - 
byteArray4private byte[] byteArray4 Four byte array allocated once to speed process and reduced the need to reallocate memory.
 - 
debugFlagprivate boolean debugFlag Debug flag.
 - 
havePeekedprivate boolean havePeeked Flag indicating whether the first byte has been looked at.
 - 
inEndianessprivate int inEndianess Endianess of the input stream.
 - 
outEndianessprivate int outEndianess Endianess of the output stream.
 - 
peekedByteprivate byte peekedByte Storage for the first byte (i.e. the PDU type )
 - 
srcByteArrayprivate byte[] srcByteArray Source byte array allocated ONCE used in reading from the stream.
 
- 
 - 
Method Detail- 
bufferToInt16public static final int bufferToInt16(byte[] buffer, int index, int endianess)Copies a 2 byte array into a 16 bit integer of proper endianess.- Parameters:
- buffer- source byte array
- index- index into buffer
- endianess- Byte ordering as defined above.
- Returns:
- 16 bit integer value
 
 - 
bufferToInt32public static final int bufferToInt32(byte[] buffer, int index, int endianess)Copies a 4 byte array into a 32 bit integer of proper endianess.- Parameters:
- buffer- source byte array
- index- index into buffer
- endianess- endianess
- Returns:
- 32 bit integer value
 
 - 
int16ToBufferpublic static final void int16ToBuffer(byte[] buffer, int index, int value, int endianess)Copies a 16 bit (2 bytes) integer into the specified portion of the byte array of proper endianess.- Parameters:
- buffer- destination byte array
- index- index into buffer
- value- 16 bit integer value
- endianess- endianess
 
 - 
int32ToBufferpublic static final void int32ToBuffer(byte[] buffer, int index, int value, int endianess)Copies a 32 bit (4 bytes) integer into the specified portion of the byte array of proper endianess.- Parameters:
- buffer- destination byte array
- index- index into buffer
- value- 16 bit integer value
- endianess- endianess
 
 - 
flushpublic void flush() throws DICOM_ExceptionSends all byte buffers of the outgoing buffer vector out the port. see DICOM PDUService.sendBinary and DICOMSocket- Throws:
- DICOM_Exception- DOCUMENT ME!
 
 - 
flushpublic void flush(int nBytes) throws DICOM_ExceptionSends specified number of bytes out the port. see DICOM PDUService.sendBinary and DICOMSocket- Parameters:
- nBytes- number of bytes to flush
- Throws:
- DICOM_Exception- Throws an error when attempting to flush more bytes than are present!
 
 - 
getIncomingEndianpublic int getIncomingEndian() Returns constant indicating endianess of incoming data.- Returns:
- the endianess of the incoming data
 
 - 
getIncomingSizepublic int getIncomingSize() Returns the incoming data size.- Returns:
- the number of bytes in the incoming data
 
 - 
getOutgoingEndianpublic int getOutgoingEndian() Returns constant indicating endianess of outgoing data.- Returns:
- the endianess of the outgoing data
 
 - 
getOutgoingSizepublic int getOutgoingSize() Returns the outgoing data size.- Returns:
- the number of bytes in the outgoing data
 
 - 
peekFirstBytepublic byte peekFirstByte() throws DICOM_ExceptionTypically used to determine the PDUTYPE (i.e. PDUTYPE_PresentationContextAccept)- Returns:
- the PDU type identifier
- Throws:
- DICOM_Exception- DOCUMENT ME!
 
 - 
peekForEndOfSequencepublic int peekForEndOfSequence() throws DICOM_ExceptionDOCUMENT ME!- Returns:
- DOCUMENT ME!
- Throws:
- DICOM_Exception- DOCUMENT ME!
 
 - 
readpublic void read(byte[] data) throws DICOM_ExceptionSimple method that take a byte array and call read with two parameters: byte array and array length.- Parameters:
- data- byte buffer in which to store the data
- Throws:
- DICOM_Exception- DOCUMENT ME!
 
 - 
readpublic void read(byte[] data, int nBytes) throws DICOM_ExceptionReads a specified number of bytes into the byte data buffer.- Parameters:
- data- byte data array ( destination )
- nBytes- the number of bytes to read into the buffer
- Throws:
- DICOM_Exception- Throws error if there is an error reading data from the port.
 
 - 
readBinarypublic int readBinary(byte[] data, int nbytes) throws DICOM_ExceptionDummy method and should be overloaded by DICOMPDUService.- Parameters:
- data- Buffer to store the data.
- nbytes- Number of bytes to be read.
- Returns:
- The actual number of bytes read.
- Throws:
- DICOM_Exception- Throws error if method is not overwritten!
 
 - 
readBytepublic final byte readByte() throws DICOM_ExceptionReads a single byte from the data stream.- Returns:
- a single byte of data
- Throws:
- DICOM_Exception- Throws error if there is an error reading data from the port.
 
 - 
readBytespublic final byte[] readBytes(int length) throws DICOM_ExceptionAllocates and.- Parameters:
- length- DOCUMENT ME!
- Returns:
- DOCUMENT ME!
- Throws:
- DICOM_Exception- DOCUMENT ME!
 
 - 
readFillpublic void readFill(int nBytes) throws DICOM_ExceptionReads in a nBytes and puts them in a ByteBuffer and puts the byte buffer in the vector of incomingBuffers.- Parameters:
- nBytes- number of bytes to read
- Throws:
- DICOM_Exception- DOCUMENT ME!
 
 - 
readInt32public final int readInt32() throws DICOM_ExceptionReads a 4 byte integer (otherwise known as an int).- Returns:
- an integer
- Throws:
- DICOM_Exception- DOCUMENT ME!
 
 - 
readShort16public final int readShort16() throws DICOM_ExceptionReads a 2 byte integer (otherwise known as a short).- Returns:
- an integer of the 2 byte data.
- Throws:
- DICOM_Exception- DOCUMENT ME!
 
 - 
seekToEndOfGroupTwoTagspublic void seekToEndOfGroupTwoTags() Strips preamble and group 2 tags from ioBuffer if present.
 - 
sendBinarypublic void sendBinary(byte[] data, int startIndex, int nbytes) throws DICOM_ExceptionDummy method and should be overloaded by DICOMPDUService.- Parameters:
- data- Buffer of data send out the port (connection).
- startIndex- starting offset
- nbytes- Number of bytes to be sent.
- Throws:
- DICOM_Exception- DOCUMENT ME!
 
 - 
setIncomingEndianesspublic void setIncomingEndianess(int endianess) Sets the endianess for the incoming data.- Parameters:
- endianess- the byte ordering (endianess) of the incoming data
 
 - 
setOutgoingEndianesspublic void setOutgoingEndianess(int endianess) Sets the endianess for the outgoing data.- Parameters:
- endianess- the byte ordering (endianess) of the outgoing data
 
 - 
writepublic final void write(byte[] byteArray) Writes a byte arrary to the outgoing buffers.- Parameters:
- byteArray- the array of data.
 
 - 
writepublic void write(byte[] data, int dataOffset, int nBytes)Writes a specified number of bytes from the byte buffer into outGoing ByteBuffer list of byte buffers.- Parameters:
- data- byte buffer
- dataOffset- DOCUMENT ME!
- nBytes- number of bytes to write
 
 - 
writeInpublic void writeIn(byte[] data, int dataOffset, int nBytes, DICOM_FileIO ioBuffer)Writes a specified number of bytes from the byte buffer into incomming ByteBuffer list of byte buffers.- Parameters:
- data- byte buffer
- dataOffset- DOCUMENT ME!
- nBytes- number of bytes to write
- ioBuffer-
 
 - 
writeBytepublic final void writeByte(byte value) Writes a byte to the outgoing buffers.- Parameters:
- value- byte value
 
 - 
writeByteInpublic final void writeByteIn(byte value, DICOM_FileIO ioBuffer)Writes a byte to the incoming buffers.- Parameters:
- value- byte value
- ioBuffer-
 
 - 
writeInt32public final void writeInt32(int value) Writes a 32 (4 byte) integer to the outgoing buffers.- Parameters:
- value- the value to be sent. The value is put into a 4 byte "byte" buffer in the order indicated by the specified endianess of this class.
 
 - 
writeInt32Inpublic final void writeInt32In(int value, DICOM_FileIO ioBuffer)Writes a 32 (4 byte) integer to the incoming buffers.- Parameters:
- value- the value to be sent. The value is put into a 4 byte "byte" buffer in the order indicated by the specified endianess of this class.
- ioBuffer-
 
 - 
writeShort16public final void writeShort16(int value) Writes a 16 (2 byte) integer to the outgoing buffers.- Parameters:
- value- the value to be sent. The value is put into a 2 byte "byte" buffer in the order indicated by the specified endianess of this class.
 
 - 
writeShort16Inpublic final void writeShort16In(int value, DICOM_FileIO ioBuffer)Writes a 16 (2 byte) integer to the incomming buffers.- Parameters:
- value- the value to be sent. The value is put into a 2 byte "byte" buffer in the order indicated by the specified endianess of this class.
- ioBuffer-
 
 - 
finalizeprotected void finalize() Prepares this class for destruction.- Overrides:
- finalizein class- java.lang.Object
 
 - 
readBlockprivate void readBlock(int useBreakSize) throws DICOM_ExceptionThis is the method that actually reads in the data from the socket or IO stream.- Parameters:
- useBreakSize- the recommended size of the read buffer
- Throws:
- DICOM_Exception- Throws error if there is an error reading data from the port.
 
 
- 
 
-