Class FileBase

java.lang.Object
gov.nih.mipav.model.file.FileBase
Direct Known Subclasses:
AlgorithmASM.FileMATLAB, FileAfni, FileAnalyze, FileAvi, FileBFLOAT, FileBioRad, FileBMP, FileBRUKER, FileCheshire, FileCheshireVOI, FileCOR, FileCZI, FileDM3, FileFits, FileGESigna4X, FileGESigna5X, FileHistoLUT, FileICS, FileInterfile, FileJP2, FileJPEG_LS, FileJPEG_XL, FileJPEG2000, FileJSON, FileLIFF, FileLSM, FileMagnetomVision, FileMap, FileMATLAB, FileMedVision, FileMetaImage, FileMGH, FileMicroCat, FileMinc, FileMincHDF, FileMRC, FileNIFTI, FileNRRD, FileOME, FilePackBit, FilePARREC, FilePGM, FilePPM, FileRaw, FileRawChunk, FileSiemensText, FileSpar, FileSPM, FileSTK, FileSVS, FileTiff, FileTMG, FileTrackVis, FileVista, FileXML, FileZVI

public abstract class FileBase extends Object
FileBase is an abstract class that has many methods that support the reading/writing of files.
Version:
0.9 June 30, 1998
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static boolean
    Byte order.
    private boolean
    DOCUMENT ME!
    protected int
    DOCUMENT ME!
    private final byte[]
    byte array for double *
    private final byte[]
    byte array for float *
    private final byte[]
    byte array for int *
    private final byte[]
    byte array for long *
    private final byte[]
    byte array for short *
    private int
    DOCUMENT ME!
    protected String[]
    The file names which are opened.
    private final EventListenerList
    A list of the ChangeListeners which are interested in the ChangeEvent.
    static boolean
    Byte order.
    protected boolean
    Flag indicating if the progress bar should be shown.
    Pointer to file to read or write from.
    static final int
    Read only access.
    static final int
    Read-write access.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Empty constructor.
    FileBase(String[] fileNames)
    Creates a new FileBase object.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds the ProgressChangeListener to this FileBase object.
    static final double
    bytesToDouble(boolean bigEndian, int index, byte[] buffer)
    Converts from bytes to double
    static final float
    bytesToFloat(boolean bigEndian, int index, byte[] buffer)
    Converts from bytes to float
    static final int
    bytesToInt(boolean bigEndian, int index, byte[] buffer)
    Converts from bytes to int
    static final short
    bytesToShort(boolean bigEndian, int index, byte[] buffer)
    Converts from bytes to short
    static final byte[]
    doubleToBytes(double data, boolean bigEndian, byte[] buffer)
    converts from double to bytes
    void
    Prepares this class for cleanup.
    void
    Notifies all listeners that have registered interest for notification on this event type.
    void
    fireProgressStateChanged(int value, String title, String message)
    Notifies all listeners that have registered interest for notification on this event type.
    void
     
    static final byte[]
    floatToBytes(float data, boolean bigEndian, byte[] buffer)
    converts from float to bytes
    final double
    getBufferDouble(byte[] buffer, int index, boolean bigEndian)
    Converts byte data to double data.
    final float
    getBufferFloat(byte[] buffer, int index, boolean bigEndian)
    Converts byte data to float data.
    final int
    getBufferInt(byte[] buffer, int index, boolean bigEndian)
    Converts byte data to int data.
    final long
    getBufferLong(byte[] buffer, int index, boolean bigEndian)
    Converts byte data to int data.
    final short
    getBufferShort(byte[] buffer, int index, boolean bigEndian)
    Converts byte data to short data.
    final int
    getBufferUShort(byte[] buffer, int index, boolean bigEndian)
    Converts byte data to int data.
    int
    Gets datatype
    final double
    getDouble(boolean bigEndian)
    Reads eight unsigned bytes from file.
    final float
    getFloat(boolean bigEndian)
    Reads four unsigned bytes from file.
    final int
    getInt(boolean bigEndian)
    Reads four signed bytes from file.
    final long
    getLong(boolean bigEndian)
    Reads eight unsigned bytes from file.
     
     
    final int
    getSignedShort(boolean bigEndian)
    Reads two byte signed short from file.
    final String
    getString(int length)
    Reads a string from a file of given length.
    final long
    getUInt(boolean bigEndian)
    Reads four unsigned bytes from file.
    final int
    getUnsignedByte(byte[] buffer, int index)
    Converts byte data to unsigned int.
    final int
    getUnsignedShort(boolean bigEndian)
    Reads two unsigned bytes from file.
    static final byte[]
    intToBytes(int data, boolean bigEndian, byte[] buffer)
    converts from int to bytes
    boolean
    Return true if the byte order is big endian.
    boolean
    Returns flag that indicates that the progressBar is visible.
    protected void
     
    static byte[]
    longToBytes(long data, boolean bigEndian, byte[] buffer)
    converts from long to bytes
    final double
    readDouble(boolean bigEndian)
    reads double value
    final float
    readFloat(boolean bigEndian)
    reads float value
    final int
    readInt(boolean bigEndian)
    Reads int value
    final long
    readLong(boolean bigEndian)
    reads long value
    final short
    readShort(boolean bigEndian)
    reads short value
    final String
    readString(int length)
    Reads the length of the characters from the file.
    final int
    readUnsignedShort(boolean bigEndian)
    reads unsigned short value
    void
    Removes the ChangeListener from the FileBase object.
    void
    setBigEndian(boolean bigEndian)
    sets big endian
    final void
    setBufferFloat(byte[] buffer, float data, int i, boolean bigEndian)
    Sets byte buffer with int.
    final void
    setBufferInt(byte[] buffer, int data, int i, boolean bigEndian)
    Sets byte buffer with int.
    final void
    setBufferLong(byte[] buffer, long data, int i, boolean bigEndian)
    Sets byte buffer with long.
    final void
    setBufferShort(byte[] buffer, short data, int i, boolean bigEndian)
    Sets byte buffer with int.
    final void
    setBufferString(byte[] buffer, String str, int i)
    Sets byte buffer with int.
    void
    setDataType(int dataType)
    DOCUMENT ME!
    void
    setEndianess(boolean bigEndian)
    DOCUMENT ME!
    static final byte[]
    shortToBytes(short data, boolean bigEndian, byte[] buffer)
    converts from short to bytes
    final void
     
    final void
    writeDouble(double data, boolean bigEndian)
    Writes a double as eight bytes to a file.
    final void
    writeFloat(float data, boolean bigEndian)
    Writes a float as four bytes to a file.
    final void
    writeInt(int data, boolean bigEndian)
    Writes an int as four bytes to a file.
    final void
    writeLong(long data, boolean bigEndian)
    Writes a long as eight bytes to a file.
    final void
    writeShort(short data, boolean bigEndian)
    Writes a short as two bytes to a file.

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LITTLE_ENDIAN

      public static boolean LITTLE_ENDIAN
      Byte order. Rightmost byte is most significant.
    • BIG_ENDIAN

      public static boolean BIG_ENDIAN
      Byte order. Leftmost byte is most significant.
    • READ

      public static final int READ
      Read only access.
      See Also:
    • READ_WRITE

      public static final int READ_WRITE
      Read-write access.
      See Also:
    • bitsPerPixel

      protected int bitsPerPixel
      DOCUMENT ME!
    • fileNames

      protected String[] fileNames
      The file names which are opened.
    • pBarVisible

      protected boolean pBarVisible
      Flag indicating if the progress bar should be shown.
    • raFile

      public RandomAccessFile raFile
      Pointer to file to read or write from.
    • bigEndian

      private boolean bigEndian
      DOCUMENT ME!
    • dataType

      private int dataType
      DOCUMENT ME!
    • listenerList

      private final EventListenerList listenerList
      A list of the ChangeListeners which are interested in the ChangeEvent.
    • byteShortBuffer

      private final byte[] byteShortBuffer
      byte array for short *
    • byteIntBuffer

      private final byte[] byteIntBuffer
      byte array for int *
    • byteDoubleBuffer

      private final byte[] byteDoubleBuffer
      byte array for double *
    • byteFloatBuffer

      private final byte[] byteFloatBuffer
      byte array for float *
    • byteLongBuffer

      private final byte[] byteLongBuffer
      byte array for long *
  • Constructor Details

    • FileBase

      public FileBase()
      Empty constructor.
    • FileBase

      public FileBase(String[] fileNames)
      Creates a new FileBase object.
      Parameters:
      fileNames - DOCUMENT ME!
  • Method Details

    • bytesToFloat

      public static final float bytesToFloat(boolean bigEndian, int index, byte[] buffer)
      Converts from bytes to float
      Parameters:
      bigEndian -
      index -
      buffer -
      Returns:
      float value
    • bytesToDouble

      public static final double bytesToDouble(boolean bigEndian, int index, byte[] buffer)
      Converts from bytes to double
      Parameters:
      bigEndian -
      index -
      buffer -
      Returns:
      float value
    • bytesToInt

      public static final int bytesToInt(boolean bigEndian, int index, byte[] buffer)
      Converts from bytes to int
      Parameters:
      bigEndian -
      index -
      buffer -
      Returns:
      int value
    • bytesToShort

      public static final short bytesToShort(boolean bigEndian, int index, byte[] buffer)
      Converts from bytes to short
      Parameters:
      bigEndian -
      index -
      buffer -
      Returns:
      short value
    • floatToBytes

      public static final byte[] floatToBytes(float data, boolean bigEndian, byte[] buffer)
      converts from float to bytes
      Parameters:
      data -
      bigEndian -
      Returns:
      byte array
    • doubleToBytes

      public static final byte[] doubleToBytes(double data, boolean bigEndian, byte[] buffer)
      converts from double to bytes
      Parameters:
      data -
      bigEndian -
      Returns:
      byte array
    • intToBytes

      public static final byte[] intToBytes(int data, boolean bigEndian, byte[] buffer)
      converts from int to bytes
      Parameters:
      data -
      bigEndian -
      buffer -
      Returns:
      byte array
    • longToBytes

      public static byte[] longToBytes(long data, boolean bigEndian, byte[] buffer)
      converts from long to bytes
      Parameters:
      data -
      bigEndian -
      buffer -
      Returns:
      byte array
    • shortToBytes

      public static final byte[] shortToBytes(short data, boolean bigEndian, byte[] buffer)
      converts from short to bytes
      Parameters:
      data -
      bigEndian -
      buffer -
      Returns:
      byte array
    • addProgressChangeListener

      public void addProgressChangeListener(ProgressChangeListener l)
      Adds the ProgressChangeListener to this FileBase object.
      Parameters:
      l - DOCUMENT ME!
    • finalize

      public void finalize()
      Prepares this class for cleanup.
      Overrides:
      finalize in class Object
    • fireProgressStateChanged

      public void fireProgressStateChanged(int value)
      Notifies all listeners that have registered interest for notification on this event type.
      Parameters:
      value - the value of the progress bar.
    • fireProgressStateChanged

      public void fireProgressStateChanged(String message)
    • fireProgressStateChanged

      public void fireProgressStateChanged(int value, String title, String message)
      Notifies all listeners that have registered interest for notification on this event type.
      Parameters:
      value - the value of the progress bar.
      title - the title of the progress dialog.
      message - the message for that specific progress value.
    • getProgressChangeListeners

      public ProgressChangeListener[] getProgressChangeListeners()
    • linkProgress

      protected void linkProgress(FileBase fBase)
    • getBufferDouble

      public final double getBufferDouble(byte[] buffer, int index, boolean bigEndian)
      Converts byte data to double data.
      Parameters:
      buffer - Array of byte data.
      index - Index into array data.
      bigEndian - true indicates big endian byte order, false indicates little endian.
      Returns:
      Float value extracted from byte array.
    • getBufferFloat

      public final float getBufferFloat(byte[] buffer, int index, boolean bigEndian)
      Converts byte data to float data.
      Parameters:
      buffer - Array of byte data.
      index - Index into array data.
      bigEndian - true indicates big endian byte order, false indicates little endian.
      Returns:
      Float value extracted from byte array.
    • getBufferLong

      public final long getBufferLong(byte[] buffer, int index, boolean bigEndian)
      Converts byte data to int data.
      Parameters:
      buffer - Array of byte data.
      index - Index into array data.
      bigEndian - true indicates big endian byte order, false indicates little endian.
      Returns:
      Long value extracted from byte array.
    • getBufferInt

      public final int getBufferInt(byte[] buffer, int index, boolean bigEndian)
      Converts byte data to int data.
      Parameters:
      buffer - Array of byte data.
      index - Index into array data.
      bigEndian - true indicates big endian byte order, false indicates little endian.
      Returns:
      Integer value extracted from byte array.
    • getBufferShort

      public final short getBufferShort(byte[] buffer, int index, boolean bigEndian)
      Converts byte data to short data.
      Parameters:
      buffer - Array of byte data.
      index - Index into array data.
      bigEndian - true indicates big endian byte order, false indicates little endian.
      Returns:
      Short value extracted from byte array.
    • getBufferUShort

      public final int getBufferUShort(byte[] buffer, int index, boolean bigEndian)
      Converts byte data to int data.
      Parameters:
      buffer - Array of byte data.
      index - Index into array data.
      bigEndian - true indicates big endian byte order, false indicates little endian.
      Returns:
      int value extracted from byte array.
    • getDataType

      public int getDataType()
      Gets datatype
      Returns:
      datatype
    • getDouble

      public final double getDouble(boolean bigEndian) throws IOException
      Reads eight unsigned bytes from file.
      Parameters:
      bigEndian - true indicates big endian byte order, false indicates little endian.
      Returns:
      The value of the double read from the file.
      Throws:
      IOException - if there is an error reading the file
    • getFloat

      public final float getFloat(boolean bigEndian) throws IOException
      Reads four unsigned bytes from file.
      Parameters:
      bigEndian - true indicates big endian byte order, false indicates little endian.
      Returns:
      The value of the float read from the file.
      Throws:
      IOException - if there is an error reading the file
    • getInt

      public final int getInt(boolean bigEndian) throws IOException
      Reads four signed bytes from file.
      Parameters:
      bigEndian - true indicates big endian byte order, false indicates little endian.
      Returns:
      The value of the integer read from the file.
      Throws:
      IOException - if there is an error reading the file
    • getLong

      public final long getLong(boolean bigEndian) throws IOException
      Reads eight unsigned bytes from file.
      Parameters:
      bigEndian - true indicates big endian byte order, false indicates little endian.
      Returns:
      The value of the long read from the file.
      Throws:
      IOException - if there is an error reading the file
    • getRaFile

      public RandomAccessFile getRaFile()
    • getSignedShort

      public final int getSignedShort(boolean bigEndian) throws IOException
      Reads two byte signed short from file.
      Parameters:
      bigEndian - true indicates big endian byte order, false indicates little endian.
      Returns:
      The value of signed short read from the file returned as an int.
      Throws:
      IOException - if there is an error reading the file
    • getString

      public final String getString(int length) throws IOException
      Reads a string from a file of given length.
      Parameters:
      length - Number of bytes that form the string.
      Returns:
      The string read from the file.
      Throws:
      IOException - if there is an error reading the file
    • getUInt

      public final long getUInt(boolean bigEndian) throws IOException
      Reads four unsigned bytes from file.
      Parameters:
      bigEndian - true indicates big endian byte order, false indicates little endian.
      Returns:
      The value of the integer read from the file.
      Throws:
      IOException - if there is an error reading the file
    • getUnsignedByte

      public final int getUnsignedByte(byte[] buffer, int index)
      Converts byte data to unsigned int.
      Parameters:
      buffer - Buffer of signed bytes.
      index - Index points to location in buffer.
      Returns:
      Integer converted from as "signed byte".
    • getUnsignedShort

      public final int getUnsignedShort(boolean bigEndian) throws IOException
      Reads two unsigned bytes from file.
      Parameters:
      bigEndian - true indicates big endian byte order, false indicates little endian.
      Returns:
      The value of unsigned short read from the file returned as an int.
      Throws:
      IOException - if there is an error reading the file
    • isBigEndian

      public boolean isBigEndian()
      Return true if the byte order is big endian.
      Returns:
      true if the byte order is big endian.
    • isProgressBarVisible

      public boolean isProgressBarVisible()
      Returns flag that indicates that the progressBar is visible.
      Returns:
      true if progress bar is visible, false if not visible.
    • readDouble

      public final double readDouble(boolean bigEndian) throws IOException
      reads double value
      Parameters:
      bigEndian -
      Returns:
      double value
      Throws:
      IOException
    • readFloat

      public final float readFloat(boolean bigEndian) throws IOException
      reads float value
      Parameters:
      bigEndian -
      Returns:
      float value
      Throws:
      IOException
    • readInt

      public final int readInt(boolean bigEndian) throws IOException
      Reads int value
      Parameters:
      bigEndian -
      Returns:
      int value
      Throws:
      IOException
    • readLong

      public final long readLong(boolean bigEndian) throws IOException
      reads long value
      Parameters:
      bigEndian -
      Returns:
      long value
      Throws:
      IOException
    • readShort

      public final short readShort(boolean bigEndian) throws IOException
      reads short value
      Parameters:
      bigEndian -
      Returns:
      short value
      Throws:
      IOException
    • readString

      public final String readString(int length) throws IOException
      Reads the length of the characters from the file.
      Parameters:
      length - the length of the string
      Returns:
      the string read from the file.
      Throws:
      IOException - throw IOException if I/O error happens
    • readUnsignedShort

      public final int readUnsignedShort(boolean bigEndian) throws IOException
      reads unsigned short value
      Parameters:
      bigEndian -
      Returns:
      int
      Throws:
      IOException
    • removeProgressChangeListener

      public void removeProgressChangeListener(ProgressChangeListener l)
      Removes the ChangeListener from the FileBase object.
    • setBigEndian

      public void setBigEndian(boolean bigEndian)
      sets big endian
      Parameters:
      bigEndian -
    • setBufferFloat

      public final void setBufferFloat(byte[] buffer, float data, int i, boolean bigEndian)
      Sets byte buffer with int.
      Parameters:
      buffer - Byte buffers where data is to be stored.
      data - Float data is broken down in bytes and stored in the byte buffer.
      i - Index into byte buffer.
      bigEndian - true indicates big endian byte order, false indicates little endian.
    • setBufferInt

      public final void setBufferInt(byte[] buffer, int data, int i, boolean bigEndian)
      Sets byte buffer with int.
      Parameters:
      buffer - Byte buffers where data is to be stored.
      data - Integer data is broken down in bytes and stored in the byte buffer.
      i - Index into byte buffer.
      bigEndian - true indicates big endian byte order, false indicates little endian.
    • setBufferLong

      public final void setBufferLong(byte[] buffer, long data, int i, boolean bigEndian)
      Sets byte buffer with long.
      Parameters:
      buffer - Byte buffers where data is to be stored.
      data - Long data is broken down in bytes and stored in the byte buffer.
      i - Index into byte buffer.
      bigEndian - true indicates big endian byte order, false indicates little endian.
    • setBufferShort

      public final void setBufferShort(byte[] buffer, short data, int i, boolean bigEndian)
      Sets byte buffer with int.
      Parameters:
      buffer - Byte buffers where data is to be stored.
      data - Short data is broken down in bytes and stored in the byte buffer.
      i - Index into byte buffer.
      bigEndian - true indicates big endian byte order, false indicates little endian.
    • setBufferString

      public final void setBufferString(byte[] buffer, String str, int i)
      Sets byte buffer with int.
      Parameters:
      buffer - Byte buffers where data is to be stored.
      str - String containing integer data which is broken down in bytes and stored in the byte buffer.
      i - Index into byte buffer.
    • setDataType

      public void setDataType(int dataType)
      DOCUMENT ME!
      Parameters:
      dataType - DOCUMENT ME!
    • setEndianess

      public void setEndianess(boolean bigEndian)
      DOCUMENT ME!
      Parameters:
      bigEndian - DOCUMENT ME!
    • writeDouble

      public final void writeDouble(double data, boolean bigEndian) throws IOException
      Writes a double as eight bytes to a file.
      Parameters:
      data - Data to be written to file.
      bigEndian - true indicates big endian byte order, false indicates little endian.
      Throws:
      IOException - if there is an error writing the file
    • writeFloat

      public final void writeFloat(float data, boolean bigEndian) throws IOException
      Writes a float as four bytes to a file.
      Parameters:
      data - Data to be written to file.
      bigEndian - true indicates big endian byte order, false indicates little endian.
      Throws:
      IOException - if there is an error writing the file
    • writeInt

      public final void writeInt(int data, boolean bigEndian) throws IOException
      Writes an int as four bytes to a file.
      Parameters:
      data - Data to be written to file.
      bigEndian - true indicates big endian byte order, false indicates little endian.
      Throws:
      IOException - if there is an error writing the file
    • writeBytes

      public final void writeBytes(String s) throws IOException
      Throws:
      IOException
    • writeLong

      public final void writeLong(long data, boolean bigEndian) throws IOException
      Writes a long as eight bytes to a file.
      Parameters:
      data - Data to be written to file.
      bigEndian - true indicates big endian byte order, false indicates little endian.
      Throws:
      IOException - if there is an error writing the file
    • writeShort

      public final void writeShort(short data, boolean bigEndian) throws IOException
      Writes a short as two bytes to a file.
      Parameters:
      data - Data to be written to file.
      bigEndian - true indicates big endian byte order, false indicates little endian.
      Throws:
      IOException - if there is an error writing the file