codesimian
Class Jars

java.lang.Object
  extended by codesimian.Jars

public class Jars
extends java.lang.Object

9/06 This class is not finished, but findSelf(boolean) usually works assuming you're not in an applet, and often has problems finding CodeSimian.jar in non-Windows operating-systems. Needs to be fixed asap. Finding self is necessary for codesimian's more advanced abilities.

Contains static functions for using, combining, breeding, and evolving JAR files.

For example, find 1 CodeSimian.jar that contains a few different files from this program (an executing CodeSimian.jar) or find 2 different CodeSimian.jar's, and combine some of their different files to create a new CodeSimian.jar with different behaviors. Each software is 1 file (CodeSimian4.jar CodeSimian556.jar etc) and can modify other similar softwares.

NEED TO BUILD: a way to create and execute new JAR files IN MEMORY ONLY for if a hard-drive is not available like in an APPLET in a webpage.


Nested Class Summary
static class Jars.JarTest
           
static class Jars.SaveUpdatedSelf
          saves a new CodeSimian.jar somewhere.
static class Jars.ZipEntryAndByteArray
           
 
Method Summary
static java.io.ByteArrayInputStream breed(java.io.ByteArrayInputStream[] jars)
          Breeds 2 or more modified CodeSimian.jar's into a single CodeSimian.jar which is returned
static java.io.ByteArrayInputStream consumeAnotherProgram(java.io.ByteArrayInputStream anyOtherJarProgram)
          any JAR file contains classes and maybe other files that CodeSimian might consume by copying it into a new CodeSimian.jar

This class should search for a license text file and license at top of source-code files and announce this info to a LicenseListener object (LicenseListener interface not yet created 9/06).
static java.io.ByteArrayInputStream consumeAnyBytes(java.lang.String nameOrDescription, java.io.InputStream anything)
          Creates a new JAR file (a new version of the currently-executing CodeSimian.jar) after consuming some bytes.
static java.io.ByteArrayInputStream consumeSimilar(java.io.ByteArrayInputStream similarToMe, int minBytesToConsume, int maxBytesToConsume)
          Modifies this program executing now and saves it in a new CodeSimian.jar.
static java.io.ByteArrayInputStream[] findAnythingOnTheInternet(CS byteJudger, java.net.URL[] startSearchingHere, int howManyFilesDoYouWant, long maxMilliseconds, long minBytesEach, long maxBytesEach)
           
static java.io.ByteArrayInputStream[] findJarsOnTheInternet(CS jarJudger, java.net.URL[] startSearchingHere, int howManyJarsDoYouWant, long maxMilliseconds, long minBytesEachJar, long maxBytesEachJar)
          Uses jarJudger.setL(ByteArrayInputStream) then executes jarJudger.D() to judge JARs it finds on the internet, and based on how jarJudger judges, tries to find better JARs on the internet next time you call this function with the same (or similar?) jarJudger object.
static java.lang.String[] findLicenses(java.io.ByteArrayInputStream anyJar)
          should return strings like "GNU GPL" "GNU LGPL" "public domain" "new BSD" "License of Guile" etc, or whichever licenses your program that uses CodeSimian allows.
static java.io.ByteArrayInputStream findSelf(boolean createApproximateSelfIfCanOnlyFindPartsOfSelf)
          returns the CodeSimian.jar that contains this program executing now, or null if could not find it.
static java.io.ByteArrayInputStream[] findSimilarToSelf()
          returns Jar files it thinks are most similar to the CodeSimian.jar currently executing.
static float GPLcompatible(java.io.ByteArrayInputStream anyJar)
          is a JAR file compatible with the GNU GPL license? All LGPL, new BSD, and many other licenses are GPL-compatible.
static float LGPLcompatible(java.io.ByteArrayInputStream anyJar)
          is a JAR file compatible with the GNU LGPL license? Unlike GPL, LGPL allows you to sell modifications of software.
static byte[] readBytesForCurrentEntry(java.util.zip.ZipEntry currentEntry, java.util.zip.ZipInputStream jarIn)
          jarIn.getNextJarEntry() must have returned currentEntry the last time it was called, because that positions the ByteArrayInputStream to the beginning of the entry.
static Jars.ZipEntryAndByteArray[] unzip(java.util.zip.ZipInputStream zipIn)
          unzip all files in zipIn
static java.io.ByteArrayInputStream updateSelf(boolean createFromParts)
          returns the bytes for a new CodeSimian.jar, including all files in the original CodeSimian.jar (returned by findSelf()), except for files deleted by deleteInternalFile and files added or modified by setInternalFile (in InternalFiles.java).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

findSelf

public static java.io.ByteArrayInputStream findSelf(boolean createApproximateSelfIfCanOnlyFindPartsOfSelf)
returns the CodeSimian.jar that contains this program executing now, or null if could not find it.

The purpose of this function is to get the bytes of CodeSimian's internal files, and to help new versions of CodeSimian.jar (containing any new files including code files) be automaticly created without the need for a Java compiler or files or the command-line. CodeSimian will literally create new versions of CodeSimian as a single file (a new CodeSimian.jar). But Jars.findSelf(boolean) only GETS CodeSimian.jar. It does not modify it except if it creates it from parts it finds in different places.

If your program contains Codesimian.jar and hides CodeSimian.jar inside a Jar or other place, you should modify this function to look for CodeSimian.jar wherever you put it, or if your program is a Jar and is similar to CodeSimian, and if you keep the file/folder structure in CodeSimian.jar at root level of your new Jar, it may work to make findSelf(boolean) return your own Jar instead of CodeSimian.jar.

WARNING: somebody may rename CodeSimian.jar to some other .jar name. If CodeSimian.jar is on your hard-drive, it can probably find itself by using system property "java.class.path" (finds a file whose name is similar to "CodeSimian.jar), but if this program is in an applet, access is dened to java's classpath and only by knowing the exact text "/CodeSimian.jar" can you find CodeSimian.jar. If somebody renames CodeSimian.jar, applets will probably get an error or null from Jars.findSelf(boolean). It works for some applets, depending on your web browser and which version of Java is installed.

Use arbitrary strings to get CodeSimian.jar from an applet, if this program is now in an applet. If that doesnt work, search the CLASSPATH then find the JAR with the name (case insensitive) that ends with .jar and is most similar to "CodeSimian.jar".

This function needs to be tested many times on many different types of computers, from the hard-drive, from an applet in a webpage, and from memory directly (probably wont work here, but try to make it).

Parameters:
createApproximateSelfIfCanOnlyFindPartsOfSelf - WARNING: approximate self Jars often do not work because they are made of less than all the files inside CodeSimian.jar and some files are required. 9/06 no code exists to approximate a JAR, but this ability should be added later in case all the files cant be found, or if a JAR needs to be repaired...

findSimilarToSelf

public static java.io.ByteArrayInputStream[] findSimilarToSelf()
returns Jar files it thinks are most similar to the CodeSimian.jar currently executing. If findSelf() returns a valid ByteArrayInputStream, it will be first in the returned array. More similar at lower index. If findSelf() fails, a less similar Jar will be in index 0 or the array could be empty.

This function should be modified to search the internet and optionally your hard-drive for Jar files with names similar to CodeSimian.jar or any Jar file that contains almost the same files as CodeSimian.jar.


consumeSimilar

public static java.io.ByteArrayInputStream consumeSimilar(java.io.ByteArrayInputStream similarToMe,
                                                          int minBytesToConsume,
                                                          int maxBytesToConsume)
Modifies this program executing now and saves it in a new CodeSimian.jar. SimilarToMe is a modified CodeSimian.jar which contains some things that this program does not. Some of those things will be included (and modified?) in the returned JAR.


consumeAnotherProgram

public static java.io.ByteArrayInputStream consumeAnotherProgram(java.io.ByteArrayInputStream anyOtherJarProgram)
any JAR file contains classes and maybe other files that CodeSimian might consume by copying it into a new CodeSimian.jar

This class should search for a license text file and license at top of source-code files and announce this info to a LicenseListener object (LicenseListener interface not yet created 9/06). It is easy to get sued if you use somebody elses Java code without permission. Scan for compatible licenses like "GPL" "LGPL" "NEW BSD" "PUBLIC DOMAIN" etc in the files in anyOtherJarProgram, and put the code to do all that in a separate function or class.


findJarsOnTheInternet

public static java.io.ByteArrayInputStream[] findJarsOnTheInternet(CS jarJudger,
                                                                   java.net.URL[] startSearchingHere,
                                                                   int howManyJarsDoYouWant,
                                                                   long maxMilliseconds,
                                                                   long minBytesEachJar,
                                                                   long maxBytesEachJar)
Uses jarJudger.setL(ByteArrayInputStream) then executes jarJudger.D() to judge JARs it finds on the internet, and based on how jarJudger judges, tries to find better JARs on the internet next time you call this function with the same (or similar?) jarJudger object.

It might be better for jarJudger to take a list of bytes (bytes of the JAR file) as a parameter in addition to allowing jarJudger.setL(anyByteArrayInputStream) and jarJudger.L(ByteArrayInputStream.class). For efficiency, the list of bytes can be a subclass of PrimitiveArray.ByteArray.

This function should search for licenses like consumeAnotherProgram(ByteArrayInputStream) does, and tell the user if an incompatible license for software is in the returned ByteArrayInputStream[] array.


findAnythingOnTheInternet

public static java.io.ByteArrayInputStream[] findAnythingOnTheInternet(CS byteJudger,
                                                                       java.net.URL[] startSearchingHere,
                                                                       int howManyFilesDoYouWant,
                                                                       long maxMilliseconds,
                                                                       long minBytesEach,
                                                                       long maxBytesEach)

consumeAnyBytes

public static java.io.ByteArrayInputStream consumeAnyBytes(java.lang.String nameOrDescription,
                                                           java.io.InputStream anything)
Creates a new JAR file (a new version of the currently-executing CodeSimian.jar) after consuming some bytes. The bytes can be from anywhere: a file from your hard-drive or the internet, images, videos, Java programs, anything it can theoretically be coded to use...

Parameters:
nameOrDescription - a filename, for example. Can be null.

breed

public static java.io.ByteArrayInputStream breed(java.io.ByteArrayInputStream[] jars)
Breeds 2 or more modified CodeSimian.jar's into a single CodeSimian.jar which is returned


GPLcompatible

public static float GPLcompatible(java.io.ByteArrayInputStream anyJar)
is a JAR file compatible with the GNU GPL license? All LGPL, new BSD, and many other licenses are GPL-compatible.

CodeSimian (created by Benjamin F Rayfield, copyright 2006) is licensed by GPL (no L), or a different license if you pay him enough $$$.

9/06 I can not think of any way to know if a JAR is GPL-compatible except to search it for "GPL" in a sentence that does not contain "not", or find the GPL license in a text file.

Returns:
-2 to 1: between -2 to -1 if NOT GPL compatible, -1 to 0 if dont know, and 0 - 1 if it is. Compatible with CodeSimian's boolean system where positive numbers are true and 0 and negative are false.

LGPLcompatible

public static float LGPLcompatible(java.io.ByteArrayInputStream anyJar)
is a JAR file compatible with the GNU LGPL license? Unlike GPL, LGPL allows you to sell modifications of software. A GPL software may use an LGPL software, but not the reverse.

The purpose of this function is to INFORM (if the info is easy to get), NOT to ENFORCE or tell any damn government.

CodeSimian (created by Benjamin F Rayfield, copyright 2006) is licensed by GPL (no L), or a different license if you pay him enough $$$.

9/06 I can not think of any way to know if a JAR is LGPL-compatible except to search it for "LGPL" in a sentence that does not contain "not", or find the LGPL license in a text file in the JAR.

Returns:
-2 to 1: between -2 to -1 if NOT LGPL compatible, -1 to 0 if dont know, and 0 - 1 if it is. Compatible with CodeSimian's boolean system where positive numbers are true and 0 and negative are false.

findLicenses

public static java.lang.String[] findLicenses(java.io.ByteArrayInputStream anyJar)
should return strings like "GNU GPL" "GNU LGPL" "public domain" "new BSD" "License of Guile" etc, or whichever licenses your program that uses CodeSimian allows.

Your program MUST allow GNU GPL, unless you have Benjamin F Rayfield's permission not to. Also, GNU GPL prevents you from using certain other licenses (example: "public domain"), unless you have permission not to.

The purpose of this function is to INFORM (if the info is easy to get), NOT to ENFORCE or tell any damn government.

If anyJar is null then returns the license(s) for THIS SOFTWARE: probably CodeSimian

Legally findLicenses(findSelf()) must always return at least "GNU GPL" and may not return any GPL-INcompatible licenses except by written permission of Benjamin F Rayfield.


readBytesForCurrentEntry

public static byte[] readBytesForCurrentEntry(java.util.zip.ZipEntry currentEntry,
                                              java.util.zip.ZipInputStream jarIn)
jarIn.getNextJarEntry() must have returned currentEntry the last time it was called, because that positions the ByteArrayInputStream to the beginning of the entry. Can not use ByteArrayInputStream.available() to determine size because it always returns 0 or 1.

NEED TO MODIFY THIS FUNCTION TO WORK FOR ZipEntry and ZipInputStream also.


unzip

public static Jars.ZipEntryAndByteArray[] unzip(java.util.zip.ZipInputStream zipIn)
unzip all files in zipIn


updateSelf

public static java.io.ByteArrayInputStream updateSelf(boolean createFromParts)
returns the bytes for a new CodeSimian.jar, including all files in the original CodeSimian.jar (returned by findSelf()), except for files deleted by deleteInternalFile and files added or modified by setInternalFile (in InternalFiles.java).