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,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
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
FieldsModifier and TypeFieldDescriptionstatic booleanByte order.private booleanDOCUMENT ME!protected intDOCUMENT 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 intDOCUMENT ME!protected String[]The file names which are opened.private final EventListenerListA list of the ChangeListeners which are interested in the ChangeEvent.static booleanByte order.protected booleanFlag indicating if the progress bar should be shown.Pointer to file to read or write from.static final intRead only access.static final intRead-write access. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the ProgressChangeListener to this FileBase object.static final doublebytesToDouble(boolean bigEndian, int index, byte[] buffer) Converts from bytes to doublestatic final floatbytesToFloat(boolean bigEndian, int index, byte[] buffer) Converts from bytes to floatstatic final intbytesToInt(boolean bigEndian, int index, byte[] buffer) Converts from bytes to intstatic final shortbytesToShort(boolean bigEndian, int index, byte[] buffer) Converts from bytes to shortstatic final byte[]doubleToBytes(double data, boolean bigEndian, byte[] buffer) converts from double to bytesvoidfinalize()Prepares this class for cleanup.voidfireProgressStateChanged(int value) Notifies all listeners that have registered interest for notification on this event type.voidfireProgressStateChanged(int value, String title, String message) Notifies all listeners that have registered interest for notification on this event type.voidfireProgressStateChanged(String message) static final byte[]floatToBytes(float data, boolean bigEndian, byte[] buffer) converts from float to bytesfinal doublegetBufferDouble(byte[] buffer, int index, boolean bigEndian) Converts byte data to double data.final floatgetBufferFloat(byte[] buffer, int index, boolean bigEndian) Converts byte data to float data.final intgetBufferInt(byte[] buffer, int index, boolean bigEndian) Converts byte data to int data.final longgetBufferLong(byte[] buffer, int index, boolean bigEndian) Converts byte data to int data.final shortgetBufferShort(byte[] buffer, int index, boolean bigEndian) Converts byte data to short data.final intgetBufferUShort(byte[] buffer, int index, boolean bigEndian) Converts byte data to int data.intGets datatypefinal doublegetDouble(boolean bigEndian) Reads eight unsigned bytes from file.final floatgetFloat(boolean bigEndian) Reads four unsigned bytes from file.final intgetInt(boolean bigEndian) Reads four signed bytes from file.final longgetLong(boolean bigEndian) Reads eight unsigned bytes from file.final intgetSignedShort(boolean bigEndian) Reads two byte signed short from file.final StringgetString(int length) Reads a string from a file of givenlength.final longgetUInt(boolean bigEndian) Reads four unsigned bytes from file.final intgetUnsignedByte(byte[] buffer, int index) Converts byte data to unsigned int.final intgetUnsignedShort(boolean bigEndian) Reads two unsigned bytes from file.static final byte[]intToBytes(int data, boolean bigEndian, byte[] buffer) converts from int to bytesbooleanReturn true if the byte order is big endian.booleanReturns flag that indicates that the progressBar is visible.protected voidlinkProgress(FileBase fBase) static byte[]longToBytes(long data, boolean bigEndian, byte[] buffer) converts from long to bytesfinal doublereadDouble(boolean bigEndian) reads double valuefinal floatreadFloat(boolean bigEndian) reads float valuefinal intreadInt(boolean bigEndian) Reads int valuefinal longreadLong(boolean bigEndian) reads long valuefinal shortreadShort(boolean bigEndian) reads short valuefinal StringreadString(int length) Reads the length of the characters from the file.final intreadUnsignedShort(boolean bigEndian) reads unsigned short valuevoidRemoves the ChangeListener from the FileBase object.voidsetBigEndian(boolean bigEndian) sets big endianfinal voidsetBufferFloat(byte[] buffer, float data, int i, boolean bigEndian) Sets byte buffer with int.final voidsetBufferInt(byte[] buffer, int data, int i, boolean bigEndian) Sets byte buffer with int.final voidsetBufferLong(byte[] buffer, long data, int i, boolean bigEndian) Sets byte buffer with long.final voidsetBufferShort(byte[] buffer, short data, int i, boolean bigEndian) Sets byte buffer with int.final voidsetBufferString(byte[] buffer, String str, int i) Sets byte buffer with int.voidsetDataType(int dataType) DOCUMENT ME!voidsetEndianess(boolean bigEndian) DOCUMENT ME!static final byte[]shortToBytes(short data, boolean bigEndian, byte[] buffer) converts from short to bytesfinal voidwriteBytes(String s) final voidwriteDouble(double data, boolean bigEndian) Writes a double as eight bytes to a file.final voidwriteFloat(float data, boolean bigEndian) Writes a float as four bytes to a file.final voidwriteInt(int data, boolean bigEndian) Writes an int as four bytes to a file.final voidwriteLong(long data, boolean bigEndian) Writes a long as eight bytes to a file.final voidwriteShort(short data, boolean bigEndian) Writes a short as two bytes to a file.
-
Field Details
-
LITTLE_ENDIAN
public static boolean LITTLE_ENDIANByte order. Rightmost byte is most significant. -
BIG_ENDIAN
public static boolean BIG_ENDIANByte order. Leftmost byte is most significant. -
READ
public static final int READRead only access.- See Also:
-
READ_WRITE
public static final int READ_WRITERead-write access.- See Also:
-
bitsPerPixel
protected int bitsPerPixelDOCUMENT ME! -
fileNames
The file names which are opened. -
pBarVisible
protected boolean pBarVisibleFlag indicating if the progress bar should be shown. -
raFile
Pointer to file to read or write from. -
bigEndian
private boolean bigEndianDOCUMENT ME! -
dataType
private int dataTypeDOCUMENT ME! -
listenerList
A list of the ChangeListeners which are interested in the ChangeEvent. -
byteShortBuffer
private final byte[] byteShortBufferbyte array for short * -
byteIntBuffer
private final byte[] byteIntBufferbyte array for int * -
byteDoubleBuffer
private final byte[] byteDoubleBufferbyte array for double * -
byteFloatBuffer
private final byte[] byteFloatBufferbyte array for float * -
byteLongBuffer
private final byte[] byteLongBufferbyte array for long *
-
-
Constructor Details
-
FileBase
public FileBase()Empty constructor. -
FileBase
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
Adds the ProgressChangeListener to this FileBase object.- Parameters:
l- DOCUMENT ME!
-
finalize
public void finalize()Prepares this class for cleanup. -
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
-
fireProgressStateChanged
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
-
linkProgress
-
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-trueindicates big endian byte order,falseindicates 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-trueindicates big endian byte order,falseindicates 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-trueindicates big endian byte order,falseindicates 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-trueindicates big endian byte order,falseindicates 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-trueindicates big endian byte order,falseindicates 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-trueindicates big endian byte order,falseindicates little endian.- Returns:
- int value extracted from byte array.
-
getDataType
public int getDataType()Gets datatype- Returns:
- datatype
-
getDouble
Reads eight unsigned bytes from file.- Parameters:
bigEndian-trueindicates big endian byte order,falseindicates little endian.- Returns:
- The value of the double read from the file.
- Throws:
IOException- if there is an error reading the file
-
getFloat
Reads four unsigned bytes from file.- Parameters:
bigEndian-trueindicates big endian byte order,falseindicates little endian.- Returns:
- The value of the float read from the file.
- Throws:
IOException- if there is an error reading the file
-
getInt
Reads four signed bytes from file.- Parameters:
bigEndian-trueindicates big endian byte order,falseindicates little endian.- Returns:
- The value of the integer read from the file.
- Throws:
IOException- if there is an error reading the file
-
getLong
Reads eight unsigned bytes from file.- Parameters:
bigEndian-trueindicates big endian byte order,falseindicates little endian.- Returns:
- The value of the long read from the file.
- Throws:
IOException- if there is an error reading the file
-
getRaFile
-
getSignedShort
Reads two byte signed short from file.- Parameters:
bigEndian-trueindicates big endian byte order,falseindicates 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
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:
IOException- if there is an error reading the file
-
getUInt
Reads four unsigned bytes from file.- Parameters:
bigEndian-trueindicates big endian byte order,falseindicates 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
Reads two unsigned bytes from file.- Parameters:
bigEndian-trueindicates big endian byte order,falseindicates 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:
trueif progress bar is visible,falseif not visible.
-
readDouble
reads double value- Parameters:
bigEndian-- Returns:
- double value
- Throws:
IOException
-
readFloat
reads float value- Parameters:
bigEndian-- Returns:
- float value
- Throws:
IOException
-
readInt
Reads int value- Parameters:
bigEndian-- Returns:
- int value
- Throws:
IOException
-
readLong
reads long value- Parameters:
bigEndian-- Returns:
- long value
- Throws:
IOException
-
readShort
reads short value- Parameters:
bigEndian-- Returns:
- short value
- Throws:
IOException
-
readString
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
reads unsigned short value- Parameters:
bigEndian-- Returns:
- int
- Throws:
IOException
-
removeProgressChangeListener
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-trueindicates big endian byte order,falseindicates 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-trueindicates big endian byte order,falseindicates 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-trueindicates big endian byte order,falseindicates 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-trueindicates big endian byte order,falseindicates little endian.
-
setBufferString
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
Writes a double as eight bytes to a file.- Parameters:
data- Data to be written to file.bigEndian-trueindicates big endian byte order,falseindicates little endian.- Throws:
IOException- if there is an error writing the file
-
writeFloat
Writes a float as four bytes to a file.- Parameters:
data- Data to be written to file.bigEndian-trueindicates big endian byte order,falseindicates little endian.- Throws:
IOException- if there is an error writing the file
-
writeInt
Writes an int as four bytes to a file.- Parameters:
data- Data to be written to file.bigEndian-trueindicates big endian byte order,falseindicates little endian.- Throws:
IOException- if there is an error writing the file
-
writeBytes
- Throws:
IOException
-
writeLong
Writes a long as eight bytes to a file.- Parameters:
data- Data to be written to file.bigEndian-trueindicates big endian byte order,falseindicates little endian.- Throws:
IOException- if there is an error writing the file
-
writeShort
Writes a short as two bytes to a file.- Parameters:
data- Data to be written to file.bigEndian-trueindicates big endian byte order,falseindicates little endian.- Throws:
IOException- if there is an error writing the file
-