Class DICOM_Socket


  • public class DICOM_Socket
    extends java.lang.Object
    Simple class to setup and the socket and streams.
    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/
     
    • Field Summary

      Fields 
      Modifier and Type Field Description
      boolean connected
      Flag indicating whether of not the socket is connected.
      java.io.InputStream inStream
      Input stream object acquired from the socket.
      java.io.OutputStream outStream
      Output stream object acquired from the socket.
      java.net.Socket socket
      Socket object.
      static int timeout
      DOCUMENT ME!
    • Constructor Summary

      Constructors 
      Constructor Description
      DICOM_Socket()
      DICOMSocket constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void attach​(java.net.Socket socket)
      Attaches this DICOMSocket to a JAVA socket.
      void close()
      Closes the socket.
      private static char convertToASCII​(int num)
      Simple utility to convert a number to ASCII.
      private static char convertToHex​(int num)
      Simple utility to convert a number [0:15] to hex.
      void open​(java.lang.String ip, int port)
      Open (and connect) a socket.
      int readBinary​(byte[] data, int count)
      Low level socket read.
      private static void showDataBuffer​(byte[] data, int offset, int count)
      Utility method to dump hex and ASCII to the MIPAV debug frame.
      void writeBinary​(byte[] data, int offset, int count)
      Low level socket write.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • connected

        public boolean connected
        Flag indicating whether of not the socket is connected.
      • inStream

        public java.io.InputStream inStream
        Input stream object acquired from the socket.
      • outStream

        public java.io.OutputStream outStream
        Output stream object acquired from the socket.
      • socket

        public java.net.Socket socket
        Socket object.
    • Constructor Detail

      • DICOM_Socket

        public DICOM_Socket()
        DICOMSocket constructor.
    • Method Detail

      • attach

        public void attach​(java.net.Socket socket)
                    throws DICOM_Exception
        Attaches this DICOMSocket to a JAVA socket.
        Parameters:
        socket - the socket to attach
        Throws:
        DICOM_Exception - DOCUMENT ME!
      • close

        public void close()
        Closes the socket.
      • open

        public void open​(java.lang.String ip,
                         int port)
                  throws DICOM_Exception
        Open (and connect) a socket.
        Parameters:
        ip - the ip address to connect to
        port - the port number to connect to
        Throws:
        DICOM_Exception - DOCUMENT ME!
      • readBinary

        public int readBinary​(byte[] data,
                              int count)
                       throws DICOM_Exception
        Low level socket read.
        Parameters:
        data - buffer to store the data
        count - number of bytes to be read
        Returns:
        DOCUMENT ME!
        Throws:
        DICOM_Exception - DOCUMENT ME!
      • writeBinary

        public void writeBinary​(byte[] data,
                                int offset,
                                int count)
                         throws DICOM_Exception
        Low level socket write.
        Parameters:
        data - buffer of data send out the port (connection)\
        offset - offset
        count - number of bytes to be sent
        Throws:
        DICOM_Exception - DOCUMENT ME!
      • convertToASCII

        private static char convertToASCII​(int num)
        Simple utility to convert a number to ASCII.
        Parameters:
        num - an ASCII number
        Returns:
        a string with the corresponding ASCII value.
      • convertToHex

        private static char convertToHex​(int num)
        Simple utility to convert a number [0:15] to hex.
        Parameters:
        num - a number [0:15] to be converted to hex String
        Returns:
        hex string. If number is outside range then a space is returned.
      • showDataBuffer

        private static void showDataBuffer​(byte[] data,
                                           int offset,
                                           int count)
        Utility method to dump hex and ASCII to the MIPAV debug frame.
        Parameters:
        data - data buffer to be displayed
        offset - starting offset
        count - number of bytes to be displayed from data buffer