java.lang.Object
org.jpo.datamodel.Tools
separate class to hold a collection of static methods that are frequently
needed.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
checkEDT()
This helper method checks if the execution is on the EventDisplayThread and throws an Error if it is not.static long
method to copy any file from a source stream to an output streamstatic File
correctFilenameExtension
(String extension, File testFile) method that tests the file extension of a File object for being the correct extension.static int
countFiles
(File[] fileArray) Counts the number of real files in the array of files.static void
Brings up a popup about having run out of memory and runs a Garbage Collectionstatic void
freeMem()
convenience method to log the amount of free memorystatic String
convenience method to log the amount of free memory.static boolean
hasPictures
(File subDirectory) This method looks into the supplied subdirectory and tries to see if there is at least one picture in it for which our Java Environment has a decoder.static @NotNull File
inventFilename
(File targetDir, String startName) Method that returns a file object that does not exist in the target directory based on the supplied name.static Calendar
static void
This method writes a warning to the log that we are on the EDT and should not be.
-
Method Details
-
correctFilenameExtension
method that tests the file extension of a File object for being the correct extension. Either the same file object is returned or a new one is created with the correct extension. If not the correct extension is added. The case of the extension is ignored.- Parameters:
extension
- The extensiontestFile
- File to test- Returns:
- the file
-
countFiles
Counts the number of real files in the array of files.- Parameters:
fileArray
- The files to count- Returns:
- the number of real files in the array of files
-
hasPictures
This method looks into the supplied subdirectory and tries to see if there is at least one picture in it for which our Java Environment has a decoder.- Parameters:
subDirectory
- The File representing the subdirectory to be recursively searched- Returns:
- true if there is at least one picture in the subdirectory, false if there is nothing.
-
copyBufferedStream
public static long copyBufferedStream(BufferedInputStream bin, BufferedOutputStream bout) throws IOException method to copy any file from a source stream to an output stream- Parameters:
bin
- Buffered Input Streambout
- Buffered Output Stream- Returns:
- the crc of the file
- Throws:
IOException
- Exception if things went wrong
-
inventFilename
Method that returns a file object that does not exist in the target directory based on the supplied name. If the name doesn't exist you get that back. If it exists it tries a suffix of _0 up to _49. If those are all taken it tries 50 random strings. If that all fails (how could it?) then it returns a random filename of 50 chars.- Parameters:
targetDir
- the directory in which the picture needs to gostartName
- the name to start trying- Returns:
- the new filename
-
freeMem
public static void freeMem()convenience method to log the amount of free memory -
freeMemory
convenience method to log the amount of free memory. Shows freeMemory, totalMemory and maxMemory- Returns:
- free memory
-
dealOutOfMemoryError
public static void dealOutOfMemoryError()Brings up a popup about having run out of memory and runs a Garbage Collection -
parseDate
-
checkEDT
public static void checkEDT()This helper method checks if the execution is on the EventDisplayThread and throws an Error if it is not. It is a Java Swing requirement that graphical operations must be done on the EDT or strange things SOMETIMES happen. This method allows easy checking by writing:Tools.checkEDT()
-
warnOnEDT
public static void warnOnEDT()This method writes a warning to the log that we are on the EDT and should not be. It also dumps a stack trace. Intended for debugging slow running processes that should not be on the EDT.
-