Package gov.nih.mipav.model.file
Class DelimitedRandomAccessFile
- java.lang.Object
-
- java.io.RandomAccessFile
-
- gov.nih.mipav.model.file.DelimitedRandomAccessFile
-
- All Implemented Interfaces:
java.io.Closeable,java.io.DataInput,java.io.DataOutput,java.lang.AutoCloseable
public class DelimitedRandomAccessFile extends java.io.RandomAccessFileThis 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 Modifier and Type Field Description private chardelimThe delimiter that separates each str chunk.
-
Constructor Summary
Constructors Constructor Description DelimitedRandomAccessFile(java.io.File file, java.lang.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(java.lang.String name, java.lang.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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description chargetDelimiter()static voidmain(java.lang.String[] args)java.lang.StringreadDelimitedBytes()Reads a string from the file up to the current delimiter.java.lang.StringreadDelimitedBytes(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)voidwriteDelimitedBytes(java.lang.String str)Writes a string terminated by the current delimiter.voidwriteDelimitedBytes(java.lang.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
-
-
-
-
Constructor Detail
-
DelimitedRandomAccessFile
public DelimitedRandomAccessFile(java.lang.String name, java.lang.String mode, char delim) throws java.io.FileNotFoundExceptionThis constructor first performs the same actions as RandomAccessFile(String name, String mode), it then sets the file's delimiter todelim.- Throws:
java.io.FileNotFoundException- See Also:
RandomAccessFile(String name, String mode)
-
DelimitedRandomAccessFile
public DelimitedRandomAccessFile(java.io.File file, java.lang.String mode, char delim) throws java.io.FileNotFoundExceptionThis constructor first performs the same actions as RandomAccessFile(File file, String mode), it then sets the file's delimiter todelim.- Throws:
java.io.FileNotFoundException- See Also:
RandomAccessFile(File file, String mode)
-
-
Method Detail
-
writeDelimitedBytes
public void writeDelimitedBytes(java.lang.String str) throws java.io.IOExceptionWrites a string terminated by the current delimiter.- Parameters:
str- the string to be written- Throws:
java.io.IOException
-
writeDelimitedBytes
public void writeDelimitedBytes(java.lang.String str, char tempDelim) throws java.io.IOExceptionAllows for writing with a temporary delimiter.- Parameters:
tempDelim- delimiter to be used for this method call only- Throws:
java.io.IOException- See Also:
writeDelimitedBytes(java.lang.String)
-
readDelimitedBytes
public java.lang.String readDelimitedBytes() throws java.io.IOExceptionReads 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:
java.io.IOException- See Also:
EOFException
-
readDelimitedBytes
public java.lang.String readDelimitedBytes(char tempDelim) throws java.io.IOExceptionThis 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:
java.io.IOException
-
getDelimiter
public char getDelimiter()
-
setDelimiter
public void setDelimiter(char delim)
-
main
public static void main(java.lang.String[] args) throws java.io.IOException- Throws:
java.io.IOException
-
-