Package gov.nih.mipav.model.file
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
,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 java.lang.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:
FileInfoBase
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
BIG_ENDIAN
Byte order.private boolean
bigEndian
DOCUMENT ME!protected int
bitsPerPixel
DOCUMENT ME!private byte[]
byteDoubleBuffer
byte array for double *private byte[]
byteFloatBuffer
byte array for float *private byte[]
byteIntBuffer
byte array for int *private byte[]
byteLongBuffer
byte array for long *private byte[]
byteShortBuffer
byte array for short *private int
dataType
DOCUMENT ME!protected java.lang.String[]
fileNames
The file names which are opened.private javax.swing.event.EventListenerList
listenerList
A list of the ChangeListeners which are interested in the ChangeEvent.static boolean
LITTLE_ENDIAN
Byte order.protected boolean
pBarVisible
Flag indicating if the progress bar should be shown.java.io.RandomAccessFile
raFile
Pointer to file to read or write from.static int
READ
Read only access.static int
READ_WRITE
Read-write access.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addProgressChangeListener(ProgressChangeListener l)
Adds the ProgressChangeListener to this FileBase object.static double
bytesToDouble(boolean bigEndian, int index, byte[] buffer)
Converts from bytes to doublestatic float
bytesToFloat(boolean bigEndian, int index, byte[] buffer)
Converts from bytes to floatstatic int
bytesToInt(boolean bigEndian, int index, byte[] buffer)
Converts from bytes to intstatic short
bytesToShort(boolean bigEndian, int index, byte[] buffer)
Converts from bytes to shortstatic byte[]
doubleToBytes(double data, boolean bigEndian, byte[] buffer)
converts from double to bytesvoid
finalize()
Prepares this class for cleanup.void
fireProgressStateChanged(int value)
Notifies all listeners that have registered interest for notification on this event type.void
fireProgressStateChanged(int value, java.lang.String title, java.lang.String message)
Notifies all listeners that have registered interest for notification on this event type.void
fireProgressStateChanged(java.lang.String message)
static byte[]
floatToBytes(float data, boolean bigEndian, byte[] buffer)
converts from float to bytesdouble
getBufferDouble(byte[] buffer, int index, boolean bigEndian)
Converts byte data to double data.float
getBufferFloat(byte[] buffer, int index, boolean bigEndian)
Converts byte data to float data.int
getBufferInt(byte[] buffer, int index, boolean bigEndian)
Converts byte data to int data.long
getBufferLong(byte[] buffer, int index, boolean bigEndian)
Converts byte data to int data.short
getBufferShort(byte[] buffer, int index, boolean bigEndian)
Converts byte data to short data.int
getBufferUShort(byte[] buffer, int index, boolean bigEndian)
Converts byte data to int data.int
getDataType()
Gets datatypedouble
getDouble(boolean bigEndian)
Reads eight unsigned bytes from file.float
getFloat(boolean bigEndian)
Reads four unsigned bytes from file.int
getInt(boolean bigEndian)
Reads four signed bytes from file.long
getLong(boolean bigEndian)
Reads eight unsigned bytes from file.ProgressChangeListener[]
getProgressChangeListeners()
java.io.RandomAccessFile
getRaFile()
int
getSignedShort(boolean bigEndian)
Reads two byte signed short from file.java.lang.String
getString(int length)
Reads a string from a file of givenlength
.long
getUInt(boolean bigEndian)
Reads four unsigned bytes from file.int
getUnsignedByte(byte[] buffer, int index)
Converts byte data to unsigned int.int
getUnsignedShort(boolean bigEndian)
Reads two unsigned bytes from file.static byte[]
intToBytes(int data, boolean bigEndian, byte[] buffer)
converts from int to bytesboolean
isBigEndian()
Return true if the byte order is big endian.boolean
isProgressBarVisible()
Returns flag that indicates that the progressBar is visible.protected void
linkProgress(FileBase fBase)
static byte[]
longToBytes(long data, boolean bigEndian, byte[] buffer)
converts from long to bytesdouble
readDouble(boolean bigEndian)
reads double valuefloat
readFloat(boolean bigEndian)
reads float valueint
readInt(boolean bigEndian)
Reads int valuelong
readLong(boolean bigEndian)
reads long valueshort
readShort(boolean bigEndian)
reads short valuejava.lang.String
readString(int length)
Reads the length of the characters from the file.int
readUnsignedShort(boolean bigEndian)
reads unsigned short valuevoid
removeProgressChangeListener(ProgressChangeListener l)
Removes the ChangeListener from the FileBase object.void
setBigEndian(boolean bigEndian)
sets big endianvoid
setBufferFloat(byte[] buffer, float data, int i, boolean bigEndian)
Sets byte buffer with int.void
setBufferInt(byte[] buffer, int data, int i, boolean bigEndian)
Sets byte buffer with int.void
setBufferLong(byte[] buffer, long data, int i, boolean bigEndian)
Sets byte buffer with long.void
setBufferShort(byte[] buffer, short data, int i, boolean bigEndian)
Sets byte buffer with int.void
setBufferString(byte[] buffer, java.lang.String str, int i)
Sets byte buffer with int.void
setDataType(int dataType)
DOCUMENT ME!void
setEndianess(boolean bigEndian)
DOCUMENT ME!static byte[]
shortToBytes(short data, boolean bigEndian, byte[] buffer)
converts from short to bytesvoid
writeBytes(java.lang.String s)
void
writeDouble(double data, boolean bigEndian)
Writes a double as eight bytes to a file.void
writeFloat(float data, boolean bigEndian)
Writes a float as four bytes to a file.void
writeInt(int data, boolean bigEndian)
Writes an int as four bytes to a file.void
writeLong(long data, boolean bigEndian)
Writes a long as eight bytes to a file.void
writeShort(short data, boolean bigEndian)
Writes a short as two bytes to a file.
-
-
-
Field Detail
-
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:
- Constant Field Values
-
READ_WRITE
public static final int READ_WRITE
Read-write access.- See Also:
- Constant Field Values
-
bitsPerPixel
protected int bitsPerPixel
DOCUMENT ME!
-
fileNames
protected java.lang.String[] fileNames
The file names which are opened.
-
pBarVisible
protected boolean pBarVisible
Flag indicating if the progress bar should be shown.
-
raFile
public java.io.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 javax.swing.event.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 *
-
-
Method Detail
-
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 classjava.lang.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(java.lang.String message)
-
fireProgressStateChanged
public void fireProgressStateChanged(int value, java.lang.String title, java.lang.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 java.io.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:
java.io.IOException
- if there is an error reading the file
-
getFloat
public final float getFloat(boolean bigEndian) throws java.io.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:
java.io.IOException
- if there is an error reading the file
-
getInt
public final int getInt(boolean bigEndian) throws java.io.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:
java.io.IOException
- if there is an error reading the file
-
getLong
public final long getLong(boolean bigEndian) throws java.io.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:
java.io.IOException
- if there is an error reading the file
-
getRaFile
public java.io.RandomAccessFile getRaFile()
-
getSignedShort
public final int getSignedShort(boolean bigEndian) throws java.io.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:
java.io.IOException
- if there is an error reading the file
-
getString
public final java.lang.String getString(int length) throws java.io.IOException
Reads a string from a file of givenlength
.- Parameters:
length
- Number of bytes that form the string.- Returns:
- The string read from the file.
- Throws:
java.io.IOException
- if there is an error reading the file
-
getUInt
public final long getUInt(boolean bigEndian) throws java.io.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:
java.io.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 java.io.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:
java.io.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 java.io.IOException
reads double value- Parameters:
bigEndian
-- Returns:
- double value
- Throws:
java.io.IOException
-
readFloat
public final float readFloat(boolean bigEndian) throws java.io.IOException
reads float value- Parameters:
bigEndian
-- Returns:
- float value
- Throws:
java.io.IOException
-
readInt
public final int readInt(boolean bigEndian) throws java.io.IOException
Reads int value- Parameters:
bigEndian
-- Returns:
- int value
- Throws:
java.io.IOException
-
readLong
public final long readLong(boolean bigEndian) throws java.io.IOException
reads long value- Parameters:
bigEndian
-- Returns:
- long value
- Throws:
java.io.IOException
-
readShort
public final short readShort(boolean bigEndian) throws java.io.IOException
reads short value- Parameters:
bigEndian
-- Returns:
- short value
- Throws:
java.io.IOException
-
readString
public final java.lang.String readString(int length) throws java.io.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:
java.io.IOException
- throw IOException if I/O error happens
-
readUnsignedShort
public final int readUnsignedShort(boolean bigEndian) throws java.io.IOException
reads unsigned short value- Parameters:
bigEndian
-- Returns:
- int
- Throws:
java.io.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, java.lang.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 java.io.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:
java.io.IOException
- if there is an error writing the file
-
writeFloat
public final void writeFloat(float data, boolean bigEndian) throws java.io.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:
java.io.IOException
- if there is an error writing the file
-
writeInt
public final void writeInt(int data, boolean bigEndian) throws java.io.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:
java.io.IOException
- if there is an error writing the file
-
writeBytes
public final void writeBytes(java.lang.String s) throws java.io.IOException
- Throws:
java.io.IOException
-
writeLong
public final void writeLong(long data, boolean bigEndian) throws java.io.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:
java.io.IOException
- if there is an error writing the file
-
writeShort
public final void writeShort(short data, boolean bigEndian) throws java.io.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:
java.io.IOException
- if there is an error writing the file
-
-