|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object O2Plib.io.FileIO
public class FileIO
Class FileIO is used to read file I/O from local disk or URLs for the Open2Dprot projects. [TODO] It could be expanded to access JDBC RDBMS and client-server I/O. If a method fails, the error flag errFlag is set true and the errMsg contains the error message. This makes the code GUI independent. This code was derived and refactored from MAExplorer, Flicker, early Seg2Dgel Java code, and GELLAB-II C code.
This work was derived from MAExplorer under the Mozilla 1.1 Open Source Public License by Peter Lemkin of the National Cancer Institute, an agency of the United States Government subject to the limitations noted in the accompanying LEGAL file. See licence info on http://maexplorer.sourceforge.org/
This work was produced by Peter Lemkin of the National Cancer Institute, an agency of the United States Government. As a work of the United States Government there is no associated copyright. It is offered as open source software under the Mozilla Public License (version 1.1) subject to the limitations noted in the accompanying LEGAL file. This notice must be included with the code. The Open2Dprot Mozilla and Legal files are available on http://open2dprot.sourceforge.net/
Field Summary | |
---|---|
java.lang.String |
batchDir
Batch temporary data files used in exec'ing pipeline modules directory {projDir}/batch/ |
java.lang.String |
cacheDir
Cache database directory {projDir}/cache/ |
static int |
errCode
error code is 0 if succeed |
static java.lang.String |
fioErrStr
error code string if an error occurred, else null |
static int |
IO_EXCEPTION
|
static int |
IO_FILE_NOT_FOUND
|
static int |
IO_FILE_NOT_READ_ENABLED
|
static int |
IO_FILE_WRITE_ERROR
|
static int |
IO_FORMAT_FULL
File format for full tab-delimited format that includes data BEFORE the spot list and summary data AFTER the spot list |
static int |
IO_FORMAT_GELLAB
File format for old GELLAB-II formats |
static int |
IO_FORMAT_TAB_DELIM
File format for tab-delimited format for use with spreadsheets such as Excel. |
static int |
IO_FORMAT_XML
File format for XML for use with the Open2Dprot project |
static int |
IO_OK
I/O error codes |
static int |
IO_SECURITY_VIOLATION
|
java.lang.String |
ppxDir
Original sample images directory {projDir}/ppx/ |
static boolean |
printErrMsgFlag
To display error messages. |
java.lang.String |
projDir
Project directory that is either userDir, specified by -projDir:{path}, or extracted from the input file path it the image is in a "/ppx/" subdirectory. |
java.lang.String |
rdbmsDir
RDBMS database directory {projDir}/rdbms/ |
boolean |
subDirsOKflag
Flag indicating that subdirectories were ok or created ok. |
java.lang.String |
tmpDir
Tmp images directory {projDir}/tmp/ |
static java.lang.String |
VERSION
Version for this module |
java.lang.String |
xmlDir
Directory {projDir}/xml/ use to accession, landmark, SSF, SPF, CSD and other database files. |
Constructor Summary | |
---|---|
FileIO()
FileIO() - constructor. |
|
FileIO(boolean printErrorMsgFlag)
FileIO() - constructor |
|
FileIO(java.lang.String projectDir)
FileIO() - constructor. |
|
FileIO(java.lang.String projectDir,
boolean allowMkdirsFlag)
FileIO() - constructor. |
Method Summary | |
---|---|
static boolean |
atomicFileCopy(java.lang.String fromFile,
java.lang.String toFile)
atomicFileCopy() - do an atomic file move where we delete the toFile PRIOR to copying the fromFile to the toFile. |
static boolean |
copyFile(java.lang.String srcName,
java.lang.String dstName,
java.lang.String optUpdateMsg,
int optEstInputFileLth)
copyFile() - binary copy of one file or URL to a local file |
static boolean |
copyFile(java.lang.String srcName,
java.lang.String dstName,
java.lang.String optUpdateMsg,
int optEstInputFileLth,
boolean useAppendMsgFlag)
copyFile() - binary copy of one file or URL to a local file |
static boolean |
deleteLocalFile(java.lang.String fileName)
deleteLocalFile() - delete local file. |
static java.lang.String |
discoverFileExtension(java.lang.String dir,
java.lang.String fileName,
java.lang.String[] legalExtens)
discoverFileExtension() - discover file extension by trying to lookup the file discoverFileExtension(dir,fileName,legalExtens) |
static java.lang.String |
getDirPathByDirBrowser(java.lang.String defaultDir,
java.lang.String sPrompt)
getDirPathByDirBrowser() - set the output path by directory browser |
static java.lang.String[] |
getFilesInDir(java.lang.String dir,
java.lang.String ext)
getFilesInDir() - get list of files in directory with specified file extension |
static java.lang.String |
getFullPathPixFileName(java.lang.String ppxDir,
java.lang.String pixFileName,
java.lang.String[] legalExtens)
getFullPathPixFileName() - get the full path pix file name |
java.lang.String |
getProjectDirPaths()
getProjectDirPaths() - get printable string of project directory (batch/ cache/ ppx/ rdbms/ tmp/ xml/). |
boolean |
makeProjectDirs(java.lang.String projectDir,
boolean allowMkdirsFlag)
makeProjectDirs() - make a project directory and sub directories and create directory and sub directories: batch/ cache/ ppx/ rdbms/ tmp/ xml/. |
static java.io.File |
openReadFile(java.lang.String fileName,
java.lang.String directory)
openReadFile() - Try to open an input File for reading. |
static boolean |
out_it(java.lang.String txt,
java.io.FileWriter ochan)
out_it() - Output a String to the output channel 'oChan'. |
static byte[] |
readBytesFromURL(java.lang.String srcName,
java.lang.String optUpdateMsg)
readBytesFromURL() - read binary data from URL |
static java.lang.String |
readTextFile(java.lang.String fileName)
readTextFile() - Will read file from disk & returns as String |
static int |
resizeLAXfileData(java.lang.String applicationName,
java.lang.String userDir)
resizeLAXfileData() - resize {applicationName}.lax file data for applicationName. |
void |
setProjectDirs(java.lang.String projectDir)
setProjectDirs() - setup the project sub-directories from the project directory (batch/ cache/ ppx/ rdbms/ tmp/ xml/). |
static boolean |
testLegalFileExtension(java.lang.String fileNamePath,
java.lang.String[] legalExtens)
testLegalFileExtension() - test if file has a legal file extension by checking the list legalExtens[] |
static boolean |
updateFilesFromServer(java.lang.String serverURL,
java.lang.String userDir,
java.lang.String[] fileList,
java.lang.String fileTypeMsg)
updateFilesFromServer() - update a list of files from the current server into the program install area. |
static boolean |
writeStrToFileBuffer(java.lang.String txt,
java.io.FileWriter fd)
writeStrToFileBuffer() - Output a String to the output channel 'fd'. |
static boolean |
writeTextFile(java.lang.String fileName,
java.lang.String data)
writeTextFile() - write string data to a local disk file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String VERSION
public static final int IO_FORMAT_FULL
public static final int IO_FORMAT_GELLAB
public static final int IO_FORMAT_TAB_DELIM
public static final int IO_FORMAT_XML
public static final int IO_OK
public static final int IO_FILE_NOT_READ_ENABLED
public static final int IO_FILE_WRITE_ERROR
public static final int IO_FILE_NOT_FOUND
public static final int IO_SECURITY_VIOLATION
public static final int IO_EXCEPTION
public static int errCode
public static java.lang.String fioErrStr
public static boolean printErrMsgFlag
public java.lang.String projDir
public java.lang.String batchDir
public java.lang.String cacheDir
public java.lang.String ppxDir
public java.lang.String rdbmsDir
public java.lang.String tmpDir
public java.lang.String xmlDir
public boolean subDirsOKflag
Constructor Detail |
---|
public FileIO()
public FileIO(java.lang.String projectDir)
projectDir
- to check and possibly create subproject directoriespublic FileIO(java.lang.String projectDir, boolean allowMkdirsFlag)
projectDir
- to check and possibly create subproject directoriesallowMkdirsFlag
- to allow mkdirs() if directories not foundpublic FileIO(boolean printErrorMsgFlag)
printErrorMsgFlag
- to display error messages, else
just return. In either case, the (errCode,fioErrStr) is set.Method Detail |
---|
public static boolean out_it(java.lang.String txt, java.io.FileWriter ochan)
txt
- is the text to outputochan
- is the FileWriter channel to use for OUTPUT
public static boolean writeStrToFileBuffer(java.lang.String txt, java.io.FileWriter fd)
txt
- is the text to outputfd
- is the FileWriter channel to use for OUTPUT
public static java.lang.String readTextFile(java.lang.String fileName)
public static boolean writeTextFile(java.lang.String fileName, java.lang.String data)
fileName
- is the full path filename to write the datadata
- is the string to write to the file.
public static java.lang.String[] getFilesInDir(java.lang.String dir, java.lang.String ext)
dir
- directory to readext
- is the file exteneions (e.g. ".tif") to match if not null,
else accept all files
public static boolean deleteLocalFile(java.lang.String fileName)
public static boolean copyFile(java.lang.String srcName, java.lang.String dstName, java.lang.String optUpdateMsg, int optEstInputFileLth)
srcName
- is either a full path local file name or
a http:// prefixed URL string of the source file.dstName
- is the full path of the local destination file nameoptUpdateMsg
- (opt) will display message in showMsg() and
increasing ... in showMsg(). One '.' for every 10K bytes read.
This only is used when reading a URL. Set to null if not used.optEstInputFileLth
- is the estimate size of the input file if
known else 0. Used in progress bar.
public static boolean copyFile(java.lang.String srcName, java.lang.String dstName, java.lang.String optUpdateMsg, int optEstInputFileLth, boolean useAppendMsgFlag)
srcName
- is either a full path local file name or
a http:// prefixed URL string of the source file.dstName
- is the full path of the local destination file nameoptUpdateMsg
- (opt) will display message in showMsg() and
increasing ... in showMsg(). One '.' for every 10K bytes read.
This only is used when reading a URL. Set to null if not used.optEstInputFileLth
- is the estimate size of the input file if
known else 0. Used in progress bar.useAppendMsgFlag
- to add to append message window.
public static final boolean atomicFileCopy(java.lang.String fromFile, java.lang.String toFile)
fromFile
- is the source filetoFile
- is the destination file
public static byte[] readBytesFromURL(java.lang.String srcName, java.lang.String optUpdateMsg)
srcName
- is either a full path local file name or
a http:// prefixed URL string of the source file.optUpdateMsg
- (opt) will display message in showMsg() and
increasing ... in showMsg(). One '.' for every 10K bytes read.
This only is used when reading a URL. Set to null if not used.
public static java.lang.String discoverFileExtension(java.lang.String dir, java.lang.String fileName, java.lang.String[] legalExtens)
dir
- is diretory to testfileName
- is file name without "." file extension.legalExtens
- is list of possible legal file names
public static boolean testLegalFileExtension(java.lang.String fileNamePath, java.lang.String[] legalExtens)
fileNamePath
- is file name with or without a file extension.legalExtens
- is list of possible legal file names
public static java.lang.String getFullPathPixFileName(java.lang.String ppxDir, java.lang.String pixFileName, java.lang.String[] legalExtens)
ppxDir
- - directory to searchpixFileName
- - this may be base name or full path or partial pathlegalExtens
- is list of possible legal file names
public static java.lang.String getDirPathByDirBrowser(java.lang.String defaultDir, java.lang.String sPrompt)
defaultDir
- if not nullsPrompt
- to use if not null
public static java.io.File openReadFile(java.lang.String fileName, java.lang.String directory)
public static boolean updateFilesFromServer(java.lang.String serverURL, java.lang.String userDir, java.lang.String[] fileList, java.lang.String fileTypeMsg)
[1] Setup a list of files to download [2] For each file in docFile[0:nFiles], [2.1] Backup the old file with a .bkup extension [2.2] Open the url: from serverURL and read the file from the Web into local file docList[i]+".tmp" [2.3] Move the docList[i]+".tmp" file into docList[i] in the program directory
serverURL
- is the URL of the server where the files resideuserDir
- is the user directory where the fileList is foundfileList
- - contains the files on the server that are in the
save subdirectory order as in the install directoryfileTypeMsg
- is the type of file being downloaded,
e.g., "documentation", "demo", "jar", etc.
public static int resizeLAXfileData(java.lang.String applicationName, java.lang.String userDir)
applicationName
- is the name of the applicationuserDir
- is the user directory where the fileList is found
public void setProjectDirs(java.lang.String projectDir)
projectDir
- target project directorypublic boolean makeProjectDirs(java.lang.String projectDir, boolean allowMkdirsFlag)
projectDir
- to check and possibly createallowMkdirsFlag
- to allow mkdirs() if directories not found
public java.lang.String getProjectDirPaths()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |