codesimian
Class Files

java.lang.Object
  extended by codesimian.Files

public class Files
extends java.lang.Object

problem: not all CSs are Serializable


Nested Class Summary
static class Files.DefaultDownloader
          P(0) is filename or url.
static interface Files.DownloadListener
          Watches a download of a file or URL many times as more and more bytes are downloaded.
static class Files.GrowingByteArrayInputStream
          same as ByteArrayInputStream except ByteArrayInputStream.count can be set by a function, which causes more and more bytes to be available (or less?), without replacing the byte[] array.
static class Files.LoadCSFromFile
          Puts the CS from the file in param0.
static class Files.SaveBytesP1IntoFileP0
           
static class Files.SaveCSToFile
          param0 is the CS to be Serialized and saved to file.
static class Files.TextFileWriter
          Maps a CS's params to a file.
 
Constructor Summary
Files()
           
 
Method Summary
static java.util.List<java.io.File> allFoldersRecursive(java.io.File folder)
          includes folder.
static java.lang.String changeBackToForwardSlashesAndAddSlashAtEndIfFolder(java.lang.String fileOrFolder)
           
static byte[] download(java.io.InputStream in)
          later, modify this to have a progress bar if data is large.
static byte[] download(java.lang.String fileNameOrURL)
          later, modify this to have a progress bar if data is large
static byte[] download(java.lang.String fileNameOrURL, Files.DownloadListener listener)
          Downloads the bytes from a file or URL, and tells a Files.DownloadListener about the progress downloading.
static byte[] downloadTEST(java.lang.String fileNameOrURL, Files.DownloadListener listener)
           
static java.io.InputStream fileNameOrURLToInputStream(java.lang.String fileNameOrURL)
           
static java.lang.String[] findFiles(CS fileNameJudger, CS fileSizeJudger, CS fileBytesJudger, CS searchingForTooLongJudger, int maxFileNamesReturned)
          Returns a list of paths + filenames of files on this computer's hard-drive(s).
static java.lang.String findFirstFileWithThisName(java.lang.String fileName, float maxSecondsToSearch)
          Example: findFirstFileWithThisName("javac.exe") may return "C:\\java\\jdk\\bin\\javac.exe"
static java.util.List<java.io.File> getAllFilesWithFoldersFirst(java.io.File fileOrFolder)
          example: x/ < x/y/ < x/y/z/ < x/y/file.txt
static byte[] getBytesFromFile(java.io.File file)
           
static java.io.ByteArrayInputStream getFolderOrURLAsZIP(java.lang.String folderNameOrURL)
          if folderNameOrURL is the name of a local folder (directory) then returns a ZIP file containing the files and subfolders of the specified folder.
static boolean isFolderPathName(java.lang.String folderPathName)
           
static void main(java.lang.String[] a)
           
static void saveBytesToFile(byte[] data, java.io.File file)
           
static java.io.File suggestNonexistantJarFile(java.io.File folder)
          returns the first File with name CodeSimianX.jar where X is a number (2 or higher) and that file does not exist on the hard-drive in that folder.
static void upload(java.io.OutputStream out, byte[] data)
          later, modify this to have a progress bar if data is large
static void upload(java.lang.String fileNameOrURL, byte[] data)
          later, modify this to have a progress bar if data is large
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Files

public Files()
Method Detail

saveBytesToFile

public static void saveBytesToFile(byte[] data,
                                   java.io.File file)
                            throws java.io.IOException
Throws:
java.io.IOException

getBytesFromFile

public static byte[] getBytesFromFile(java.io.File file)
                               throws java.io.IOException
Throws:
java.io.IOException

getFolderOrURLAsZIP

public static java.io.ByteArrayInputStream getFolderOrURLAsZIP(java.lang.String folderNameOrURL)
if folderNameOrURL is the name of a local folder (directory) then returns a ZIP file containing the files and subfolders of the specified folder.

If folderNameOrURL is a URL, it would need more intelligence to determine which subfolders and files are included in the zip, because the internet is too big. For example, getFolderOrURLAsZIP("http://sourceforge.net/") could be a size problem. Also, it ignores sourceforge's instructions for autonomous software in file http://sourceforge.net/robots.txt


download

public static byte[] download(java.lang.String fileNameOrURL)
later, modify this to have a progress bar if data is large


download

public static byte[] download(java.io.InputStream in)
later, modify this to have a progress bar if data is large. Files.download(String,DownloadListener) can have a progress bar if you code it in the DownLoadListener like SlowMP3 did.


upload

public static void upload(java.lang.String fileNameOrURL,
                          byte[] data)
later, modify this to have a progress bar if data is large


upload

public static void upload(java.io.OutputStream out,
                          byte[] data)
later, modify this to have a progress bar if data is large


main

public static void main(java.lang.String[] a)
                 throws java.io.IOException
Throws:
java.io.IOException

fileNameOrURLToInputStream

public static java.io.InputStream fileNameOrURLToInputStream(java.lang.String fileNameOrURL)
                                                      throws java.io.IOException
Throws:
java.io.IOException

downloadTEST

public static byte[] downloadTEST(java.lang.String fileNameOrURL,
                                  Files.DownloadListener listener)

download

public static byte[] download(java.lang.String fileNameOrURL,
                              Files.DownloadListener listener)
Downloads the bytes from a file or URL, and tells a Files.DownloadListener about the progress downloading. If IOException occurs, tells the listener and returns null.


suggestNonexistantJarFile

public static java.io.File suggestNonexistantJarFile(java.io.File folder)
returns the first File with name CodeSimianX.jar where X is a number (2 or higher) and that file does not exist on the hard-drive in that folder.


findFiles

public static java.lang.String[] findFiles(CS fileNameJudger,
                                           CS fileSizeJudger,
                                           CS fileBytesJudger,
                                           CS searchingForTooLongJudger,
                                           int maxFileNamesReturned)
Returns a list of paths + filenames of files on this computer's hard-drive(s). Tests go in order of fileNameJudger, fileSizeJudger, then fileBytesJudger. After every test, searchingForTooLongJudger and maxFileNamesReturned are checked

This function should be modified to include artificial-intelligence that tries to maximize what the JUDGES return by only considering files that are more likely to be judged well (predicted by previous judgements of similar files).

Parameters:
fileNameJudger - Param0 is set to a String filename. Return a number proportional to the chance the filename is one the caller is looking for. 0 or less means 0 chance of returning that file.

fileBytesJudger - Param0 is set to a list of bytes of the file. Returns positive if the bytes are more what the caller wants. Returns 0 or negative if cant use the file because its bytes fail this test.

fileSizeJudger - Param0 is set to the number of bytes of the file found. Returns positive if the file is small enough. Returns 0 or negative if it cant be returned because its too big.

continueSearchingJudger - Param0 is set to the number of seconds (using System.currentTimeMillis()) since this function was called. Param1 is set to quantity of good files found so far. Returns true if should continue searching

findFirstFileWithThisName

public static java.lang.String findFirstFileWithThisName(java.lang.String fileName,
                                                         float maxSecondsToSearch)
Example: findFirstFileWithThisName("javac.exe") may return "C:\\java\\jdk\\bin\\javac.exe"


isFolderPathName

public static boolean isFolderPathName(java.lang.String folderPathName)

changeBackToForwardSlashesAndAddSlashAtEndIfFolder

public static java.lang.String changeBackToForwardSlashesAndAddSlashAtEndIfFolder(java.lang.String fileOrFolder)

getAllFilesWithFoldersFirst

public static java.util.List<java.io.File> getAllFilesWithFoldersFirst(java.io.File fileOrFolder)
example: x/ < x/y/ < x/y/z/ < x/y/file.txt

allFoldersRecursive

public static java.util.List<java.io.File> allFoldersRecursive(java.io.File folder)
includes folder. Returns empty list if folder is not a folder.