Package gov.nih.mipav.model.file
Class DelimitedRandomAccessFile
java.lang.Object
java.io.RandomAccessFile
gov.nih.mipav.model.file.DelimitedRandomAccessFile
- All Implemented Interfaces:
Closeable,DataInput,DataOutput,AutoCloseable
This class is a random access file that has an internal delimiter for fast
processing of text files. It can be used to read in legacy text files, such
as comma-separated VOIs.
- Author:
- Justin Senseney
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDelimitedRandomAccessFile(File file, String mode, char delim) This constructor first performs the same actions as RandomAccessFile(File file, String mode), it then sets the file's delimiter todelim.DelimitedRandomAccessFile(String name, String mode, char delim) This constructor first performs the same actions as RandomAccessFile(String name, String mode), it then sets the file's delimiter todelim. -
Method Summary
Modifier and TypeMethodDescriptioncharstatic voidReads a string from the file up to the current delimiter.readDelimitedBytes(char tempDelim) This method retrieves a String consisting of all characters from the current pointer location in the random access file and the temporary delimiter.voidsetDelimiter(char delim) voidWrites a string terminated by the current delimiter.voidwriteDelimitedBytes(String str, char tempDelim) Allows for writing with a temporary delimiter.Methods inherited from class java.io.RandomAccessFile
close, getChannel, getFD, getFilePointer, length, read, read, read, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, seek, setLength, skipBytes, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
-
Field Details
-
delim
private char delimThe delimiter that separates each str chunk.
-
-
Constructor Details
-
DelimitedRandomAccessFile
This constructor first performs the same actions as RandomAccessFile(String name, String mode), it then sets the file's delimiter todelim.- Throws:
FileNotFoundException- See Also:
-
DelimitedRandomAccessFile
This constructor first performs the same actions as RandomAccessFile(File file, String mode), it then sets the file's delimiter todelim.- Throws:
FileNotFoundException- See Also:
-
-
Method Details
-
writeDelimitedBytes
Writes a string terminated by the current delimiter.- Parameters:
str- the string to be written- Throws:
IOException
-
writeDelimitedBytes
Allows for writing with a temporary delimiter.- Parameters:
tempDelim- delimiter to be used for this method call only- Throws:
IOException- See Also:
-
readDelimitedBytes
Reads a string from the file up to the current delimiter. Note that an EOF exception is caught, with the final string of the file returned- Returns:
- the read string
- Throws:
IOException- See Also:
-
readDelimitedBytes
This method retrieves a String consisting of all characters from the current pointer location in the random access file and the temporary delimiter.- Parameters:
tempDelim- the temporary delimiter for this class- Returns:
- the string up to tempDelim (exclusive)
- Throws:
IOException
-
getDelimiter
public char getDelimiter() -
setDelimiter
public void setDelimiter(char delim) -
main
- Throws:
IOException
-