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 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.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 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 byte[] getBytesFromFile(java.io.File file)
           
static java.util.zip.ZipInputStream 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 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 CodeSimianXXXX.jar where XXXX 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.util.zip.ZipInputStream 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 CodeSimianXXXX.jar where XXXX is a number (2 or higher) and that file does not exist on the hard-drive in that folder.