FileDocCategorySizeDatePackage
FileInstaller.javaAPI DocphoneME MR2 API (J2ME)5466Wed May 02 18:00:04 BST 2007com.sun.midp.installer

FileInstaller

public class FileInstaller extends Installer
An Installer allowing to install a midlet suite from a file. If the midlet suite is given by a descriptor file, the jar URL specified in the descriptor must have a "file" scheme.

Fields Summary
private static final int
CHUNK_SIZE
Number of bytes to read at one time when copying a file.
Constructors Summary
public FileInstaller()
Constructor of the FileInstaller.


             
      
        super();
    
Methods Summary
protected byte[]downloadJAD()
Downloads an application descriptor file from the given URL.

return
a byte array representation of the file or null if not found
exception
IOException is thrown if any error prevents the download of the JAD

        RandomAccessStream jadInputStream;
        ByteArrayOutputStream bos = new ByteArrayOutputStream(CHUNK_SIZE);
        String jadFilename = getUrlPath(info.jadUrl);

        state.beginTransferDataStatus = DOWNLOADING_JAD;
        state.transferStatus = DOWNLOADED_1K_OF_JAD;

        jadInputStream = new RandomAccessStream();
        jadInputStream.connect(jadFilename, Connector.READ);

        transferData(jadInputStream.openInputStream(), bos, CHUNK_SIZE);

        jadInputStream.close();

        return bos.toByteArray();
    
protected intdownloadJAR(java.lang.String filename)
Downloads an application archive file from the given URL into the given file. Automatically handle re-tries.

param
filename name of the file to write. This file resides in the storage area of the given application
return
size of the JAR
exception
IOException is thrown if any error prevents the download of the JAR

        int jarSize;
        RandomAccessStream jarInputStream, jarOutputStream;
        String jarFilename = getUrlPath(info.jarUrl);

        // Open source (jar) file
        jarInputStream = new RandomAccessStream();
        jarInputStream.connect(jarFilename, Connector.READ);

        // Open destination (temporary) file
        jarOutputStream = new RandomAccessStream();
        jarOutputStream.connect(filename,
                                RandomAccessStream.READ_WRITE_TRUNCATE);

        // transfer data
        state.beginTransferDataStatus = DOWNLOADING_JAR;
        state.transferStatus = DOWNLOADED_1K_OF_JAR;

        jarSize = transferData(jarInputStream.openInputStream(),
                               jarOutputStream.openOutputStream(), CHUNK_SIZE);

        jarInputStream.close();
        jarOutputStream.disconnect();

        return jarSize;
    
protected booleanisSameUrl(java.lang.String url1, java.lang.String url2)
Compares two URLs for equality in sense that they have the same scheme, host and path.

param
url1 the first URL for comparision
param
url2 the second URL for comparision
return
true if the scheme, host and path of the first given url is identical to the scheme, host and path of the second given url; false otherwise

        try {
            String defaultScheme = "file";
            String scheme1 = getUrlScheme(url1, defaultScheme);
            String scheme2 = getUrlScheme(url2, defaultScheme);

            if (url1.equals(url2)) {
                return true;
            }
        } catch (NullPointerException npe) {
            // no match, fall through
        }

        return true;
    
public booleanstopInstalling()
Stops the installation. If installer is not installing then this method has no effect. This will cause the install method to throw an IOException if the install is not writing the suite to storage which is the point of no return.

return
true if the install will stop, false if it is too late


        boolean res = super.stopInstalling();
        if (!res) {
            return res;
        }

        /* some additional actions can be added here */

        return true;