public class ASTFileIO
extends java.lang.Object
The methods in this class are declared static so that we can preserve the file chooser directory path between invocations. This does mean that the method initFileIO must be invoked at the beginning of an application to properly set things up. No harm is done if initFileIO is not called because the system defaults will still work.
Copyright (c) 2018
Modifier and Type | Field and Description |
---|---|
static int |
FILENAME_IDX
index for the filename in file open/save
|
static int |
FULLPATHNAME_IDX
index for the full pathname in file open/save
|
Constructor and Description |
---|
ASTFileIO() |
Modifier and Type | Method and Description |
---|---|
static boolean |
doesFileExist(java.lang.String fullFilename)
Determines whether a specified file already exists.
|
static java.lang.String[] |
getFileToRead(java.lang.String title,
java.lang.String btn,
javax.swing.filechooser.FileNameExtensionFilter filter)
Gets the file to open for reading.
|
static java.lang.String |
getNonBlankLine(java.io.BufferedReader br)
Reads the input file to get a non-blank line.
|
static java.lang.String |
getSimpleTaggedValue(java.io.BufferedReader br,
java.lang.String tag)
Reads the input file looking for a tag, then returns the value
found for that tag.
|
static void |
initFileIO(javax.swing.JFrame parent)
Does a one time initialization of this class, which primarily involves setting up
a file chooser.
|
static java.lang.String |
readTillStr(java.io.BufferedReader br,
java.lang.String target)
Reads the input file until the expected string is found or an error occurs.
|
static java.lang.String |
readTillStr(java.io.BufferedReader br,
java.lang.String target,
boolean showErrors)
Reads the input file until the expected string is found or an error occurs.
|
public static final int FILENAME_IDX
public static final int FULLPATHNAME_IDX
public static boolean doesFileExist(java.lang.String fullFilename)
fullFilename
- full pathname and filename to be checkedpublic static java.lang.String[] getFileToRead(java.lang.String title, java.lang.String btn, javax.swing.filechooser.FileNameExtensionFilter filter)
title
- title to display for the dialogbtn
- label to put on the "load" buttonfilter
- filter to use for displaying files by extension typepublic static java.lang.String getNonBlankLine(java.io.BufferedReader br)
br
- file to read frompublic static java.lang.String getSimpleTaggedValue(java.io.BufferedReader br, java.lang.String tag)
For example, a tag might be <Epoch> and could exist in the file in multiple ways: (1) <Epoch>, next line has value, next line has </Epoch>, (2) <Epoch>value</Epoch> on a single line, (3) <Epoch>, next line has value</Epoch>, and so on. This method is only intended to be used for XML-style tags that have simple values and not for tags (such as <Data>) that will likely have multiple lines of input. If used for a multi-line tag, only the first line will be extracted as the tag value.
br
- file to read from.tag
- Simple "XML-like" tag to search forpublic static void initFileIO(javax.swing.JFrame parent)
parent
- parent frame for the main GUI so that we can center the chooser on the parentpublic static java.lang.String readTillStr(java.io.BufferedReader br, java.lang.String target)
The string to search for is not case sensitive. This method is overloaded.
br
- file to read fromtarget
- string to search forpublic static java.lang.String readTillStr(java.io.BufferedReader br, java.lang.String target, boolean showErrors)
The string to search for is not case sensitive. This method is overloaded.
br
- file to read fromtarget
- string to search forshowErrors
- true if error messages should be displayed