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
This 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:
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 Summary
Nested ClassesModifier and TypeClassDescriptionprotected classSimple inner class to facilitate the memory allocation of of a byte buffer used in DICOM_Comms to support I/O. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intFlag used to indicate Big Endianess.protected intDefaults to the maximum buffer size in streaming.private byte[]One byte array allocated once to speed process and reduced the need to reallocate memory.private byte[]Two byte array allocated once to speed process and reduced the need to reallocate memory.private byte[]Four byte array allocated once to speed process and reduced the need to reallocate memory.private booleanDebug flag.private booleanFlag indicating whether the first byte has been looked at.protected intLength of the total input data (Not buffer size but total length of data ).protected Vector<DICOM_Comms.ByteBuffer> Vector of ByteBuffer's of incoming data.private intEndianess of the input stream.static final intFlag used to indicate Little Endianess.static final intThe maximum read buffer size.protected intLength of the total output data (Not buffer size but total length of data ).private intEndianess of the output stream.protected Vector<DICOM_Comms.ByteBuffer> Vector of ByteBuffer's of outgoing data.private byteStorage for the first byte (i.e. the PDU type )private byte[]Source byte array allocated ONCE used in reading from the stream. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final intbufferToInt16(byte[] buffer, int index, int endianess) Copies a 2 byte array into a 16 bit integer of proper endianess.static final 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 DICOMSocketintReturns constant indicating endianess of incoming data.intReturns the incoming data size.intReturns constant indicating endianess of outgoing data.intReturns the outgoing data size.static final 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 final 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.byteTypically used to determine the PDUTYPE (i.e.intDOCUMENT 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.final bytereadByte()Reads a single byte from the data stream.final 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.final intReads a 4 byte integer (otherwise known as an int).final intReads a 2 byte integer (otherwise known as a short).voidStrips 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.final 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.final voidwriteByte(byte value) Writes a byte to the outgoing buffers.final 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.final voidwriteInt32(int value) Writes a 32 (4 byte) integer to the outgoing buffers.final voidwriteInt32In(int value, DICOM_FileIO ioBuffer) Writes a 32 (4 byte) integer to the incoming buffers.final voidwriteShort16(int value) Writes a 16 (2 byte) integer to the outgoing buffers.final voidwriteShort16In(int value, DICOM_FileIO ioBuffer) Writes a 16 (2 byte) integer to the incomming buffers.
-
Field Details
-
BIG_ENDIAN
public static final int BIG_ENDIANFlag used to indicate Big Endianess.- See Also:
-
LITTLE_ENDIAN
public static final int LITTLE_ENDIANFlag used to indicate Little Endianess.- See Also:
-
MAX_READ_LENGTH
public static final int MAX_READ_LENGTHThe maximum read buffer size.- See Also:
-
breakSize
protected int breakSizeDefaults to the maximum buffer size in streaming. -
inBuffersLength
protected int inBuffersLengthLength of the total input data (Not buffer size but total length of data ). -
incomingBuffers
Vector of ByteBuffer's of incoming data. -
outBuffersLength
protected int outBuffersLengthLength of the total output data (Not buffer size but total length of data ). -
outgoingBuffers
Vector of ByteBuffer's of outgoing data. -
byteArray1
private byte[] byteArray1One byte array allocated once to speed process and reduced the need to reallocate memory. -
byteArray2
private byte[] byteArray2Two byte array allocated once to speed process and reduced the need to reallocate memory. -
byteArray4
private byte[] byteArray4Four byte array allocated once to speed process and reduced the need to reallocate memory. -
debugFlag
private boolean debugFlagDebug flag. -
havePeeked
private boolean havePeekedFlag indicating whether the first byte has been looked at. -
inEndianess
private int inEndianessEndianess of the input stream. -
outEndianess
private int outEndianessEndianess of the output stream. -
peekedByte
private byte peekedByteStorage for the first byte (i.e. the PDU type ) -
srcByteArray
private byte[] srcByteArraySource byte array allocated ONCE used in reading from the stream.
-
-
Constructor Details
-
DICOM_Comms
public DICOM_Comms()Constructor for DICOM network I/O class. Sets byte ordering for read and write to big endian.
-
-
Method Details
-
bufferToInt16
public 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 arrayindex- index into bufferendianess- Byte ordering as defined above.- Returns:
- 16 bit integer value
-
bufferToInt32
public 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 arrayindex- index into bufferendianess- endianess- Returns:
- 32 bit integer value
-
int16ToBuffer
public 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 arrayindex- index into buffervalue- 16 bit integer valueendianess- endianess
-
int32ToBuffer
public 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 arrayindex- index into buffervalue- 16 bit integer valueendianess- endianess
-
flush
Sends all byte buffers of the outgoing buffer vector out the port. see DICOM PDUService.sendBinary and DICOMSocket- Throws:
DICOM_Exception- DOCUMENT ME!
-
flush
Sends 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!
-
getIncomingEndian
public int getIncomingEndian()Returns constant indicating endianess of incoming data.- Returns:
- the endianess of the incoming data
-
getIncomingSize
public int getIncomingSize()Returns the incoming data size.- Returns:
- the number of bytes in the incoming data
-
getOutgoingEndian
public int getOutgoingEndian()Returns constant indicating endianess of outgoing data.- Returns:
- the endianess of the outgoing data
-
getOutgoingSize
public int getOutgoingSize()Returns the outgoing data size.- Returns:
- the number of bytes in the outgoing data
-
peekFirstByte
Typically used to determine the PDUTYPE (i.e. PDUTYPE_PresentationContextAccept)- Returns:
- the PDU type identifier
- Throws:
DICOM_Exception- DOCUMENT ME!
-
peekForEndOfSequence
DOCUMENT ME!- Returns:
- DOCUMENT ME!
- Throws:
DICOM_Exception- DOCUMENT ME!
-
read
Simple 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!
-
read
Reads 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.
-
readBinary
Dummy 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!
-
readByte
Reads 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.
-
readBytes
Allocates and.- Parameters:
length- DOCUMENT ME!- Returns:
- DOCUMENT ME!
- Throws:
DICOM_Exception- DOCUMENT ME!
-
readFill
Reads 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!
-
readInt32
Reads a 4 byte integer (otherwise known as an int).- Returns:
- an integer
- Throws:
DICOM_Exception- DOCUMENT ME!
-
readShort16
Reads a 2 byte integer (otherwise known as a short).- Returns:
- an integer of the 2 byte data.
- Throws:
DICOM_Exception- DOCUMENT ME!
-
seekToEndOfGroupTwoTags
public void seekToEndOfGroupTwoTags()Strips preamble and group 2 tags from ioBuffer if present. -
sendBinary
Dummy method and should be overloaded by DICOMPDUService.- Parameters:
data- Buffer of data send out the port (connection).startIndex- starting offsetnbytes- Number of bytes to be sent.- Throws:
DICOM_Exception- DOCUMENT ME!
-
setIncomingEndianess
public void setIncomingEndianess(int endianess) Sets the endianess for the incoming data.- Parameters:
endianess- the byte ordering (endianess) of the incoming data
-
setOutgoingEndianess
public void setOutgoingEndianess(int endianess) Sets the endianess for the outgoing data.- Parameters:
endianess- the byte ordering (endianess) of the outgoing data
-
write
public final void write(byte[] byteArray) Writes a byte arrary to the outgoing buffers.- Parameters:
byteArray- the array of data.
-
write
public 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 bufferdataOffset- DOCUMENT ME!nBytes- number of bytes to write
-
writeIn
Writes a specified number of bytes from the byte buffer into incomming ByteBuffer list of byte buffers.- Parameters:
data- byte bufferdataOffset- DOCUMENT ME!nBytes- number of bytes to writeioBuffer-
-
writeByte
public final void writeByte(byte value) Writes a byte to the outgoing buffers.- Parameters:
value- byte value
-
writeByteIn
Writes a byte to the incoming buffers.- Parameters:
value- byte valueioBuffer-
-
writeInt32
public 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.
-
writeInt32In
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-
-
writeShort16
public 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.
-
writeShort16In
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-
-
finalize
protected void finalize()Prepares this class for destruction. -
readBlock
This 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.
-