Class DelimitedRandomAccessFile

  • All Implemented Interfaces:
    java.io.Closeable, java.io.DataInput, java.io.DataOutput, java.lang.AutoCloseable

    public class DelimitedRandomAccessFile
    extends java.io.RandomAccessFile
    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 
      Modifier and Type Field Description
      private char delim
      The 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 to delim.
      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 to delim.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      char getDelimiter()  
      static void main​(java.lang.String[] args)  
      java.lang.String readDelimitedBytes()
      Reads a string from the file up to the current delimiter.
      java.lang.String 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.
      void setDelimiter​(char delim)  
      void writeDelimitedBytes​(java.lang.String str)
      Writes a string terminated by the current delimiter.
      void writeDelimitedBytes​(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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • delim

        private char delim
        The delimiter that separates each str chunk.
    • Constructor Detail

      • DelimitedRandomAccessFile

        public DelimitedRandomAccessFile​(java.lang.String name,
                                         java.lang.String mode,
                                         char delim)
                                  throws java.io.FileNotFoundException
        This constructor first performs the same actions as RandomAccessFile(String name, String mode), it then sets the file's delimiter to delim.
        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.FileNotFoundException
        This constructor first performs the same actions as RandomAccessFile(File file, String mode), it then sets the file's delimiter to delim.
        Throws:
        java.io.FileNotFoundException
        See Also:
        RandomAccessFile(File file, String mode)
    • Method Detail

      • writeDelimitedBytes

        public void writeDelimitedBytes​(java.lang.String str)
                                 throws java.io.IOException
        Writes 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.IOException
        Allows 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.IOException
        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:
        java.io.IOException
        See Also:
        EOFException
      • readDelimitedBytes

        public java.lang.String readDelimitedBytes​(char tempDelim)
                                            throws java.io.IOException
        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:
        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