Class SegmentedFile


  • public class SegmentedFile
    extends Object
    ALlows reading and writing individual segments of a file where the segments are separated by a regular expression.
    • Field Detail

      • file

        protected final File file
      • separatorPatterns

        protected final List<Pattern> separatorPatterns
      • segments

        protected List<String> segments
        Segment before first separator, content matching first separator, segment before second separator, content matching second separator , and so forth, and then the rest of the file.
    • Constructor Detail

      • SegmentedFile

        public SegmentedFile​(@Nonnull
                             File file,
                             @Nonnull
                             String... separatorRegexes)
                      throws IOException
        Reads the file and checks that the separators can be found and that they don't match at other places.
        Throws:
        IOException
    • Method Detail

      • readAndParseFile

        protected void readAndParseFile()
                                 throws IOException
        Reads the file and splits it according to the separators.
        Throws:
        IOException
      • getSegment

        public String getSegment​(int i)
        Retrieves the segment - 0 is before first separator, 1 is between first and second separator, and so forth, segments.size()-1 is the rest of the file.
      • writeSegment

        public void writeSegment​(int i,
                                 String newSegment)
                          throws IOException
        Retrieves the segment - 0 is before first separator, 1 is between first and second separator, and so forth, segments.size()-1 is the rest of the file.
        Throws:
        IOException
      • getFile

        public File getFile()
        The basic file we write into.
      • sanityCheck

        protected void sanityCheck​(String content)
      • joinSegments

        protected String joinSegments()
      • wholeLineRegex

        public static String wholeLineRegex​(String separator)
      • infilePrompting

        public static String[] infilePrompting​(String id)
        Generates the patterns for storing prompt and generated data within one file.