FileDocCategorySizeDatePackage
MemoryMappedArchive.javaAPI DocGlassfish v2 API8219Fri May 04 22:31:36 BST 2007com.sun.enterprise.deployment.deploy.shared

MemoryMappedArchive

public class MemoryMappedArchive extends com.sun.enterprise.deployment.deploy.shared.AbstractArchive
author
Jerome Dochez

Fields Summary
byte[]
file
Constructors Summary
protected MemoryMappedArchive()
Creates a new instance of MemoryMappedArchive

	// for use by subclasses
    
public MemoryMappedArchive(InputStream is)
Creates a new instance of MemoryMappedArchive

        read(is);
    
public MemoryMappedArchive(com.sun.enterprise.deployment.deploy.shared.AbstractArchive source)

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        JarOutputStream jos = new JarOutputStream(new BufferedOutputStream(baos));
        for (Enumeration elements = source.entries();elements.hasMoreElements();) {
            String elementName = (String) elements.nextElement();
            InputStream is = source.getEntry(elementName); 
            jos.putNextEntry(new ZipEntry(elementName));
            ArchivistUtils.copyWithoutClose(is, jos);            
            is.close();
            jos.flush();
            jos.closeEntry();
        }
        jos.close();
        file = baos.toByteArray();            
    
Methods Summary
public voidclose()
close the abstract archive

    
public voidcloseEntry()
close a previously returned @see java.io.OutputStream returned by an addEntry call

    
public voidcloseEntry(com.sun.enterprise.deployment.deploy.shared.AbstractArchive os)
close a previously returned @see java.io.OutputStream returned by an addEntry call

param
the output stream to close

    
public booleandelete()
delete the archive

        return false;
    
public java.util.Enumerationentries()

return
an @see java.util.Enumeration of entries in this abstract archive

        Vector entries = new Vector();
        try {
            JarInputStream jis = new JarInputStream(new ByteArrayInputStream(file));
            ZipEntry ze;
            while ((ze=jis.getNextEntry())!=null) {
                entries.add(ze.getName());
            }
            jis.close();
        } catch(IOException ioe) {
            ioe.printStackTrace();
        }
        return entries.elements();        
    
public java.util.Enumerationentries(java.util.Enumeration embeddedArchives)

return
an @see java.util.Enumeration of entries in this abstract archive, providing the list of embedded archive to not count their entries as part of this archive

	// jar file are not recursive    
	return entries();
	
public booleanexists()

return
true if this archive exists

        return false;
    
public longgetArchiveSize()
Get the size of the archive

return
tje the size of this archive or -1 on error

        return(file.length);
    
public java.lang.StringgetArchiveUri()

return
the archive uri

        return null;
    
public byte[]getByteArray()

        return file;
    
public com.sun.enterprise.deployment.deploy.shared.AbstractArchivegetEmbeddedArchive(java.lang.String name)
create or obtain an embedded archive within this abstraction.

param
the name of the embedded archive.

        InputStream is = getEntry(name);
        if (is!=null) {
            AbstractArchive archive = new MemoryMappedArchive(is);
            is.close();
            return archive;
        }
        return null;
    
public java.io.InputStreamgetEntry(java.lang.String name)

return
a @see java.io.InputStream for an existing entry in the current abstract archive
param
the entry name

        JarInputStream jis = new JarInputStream(new ByteArrayInputStream(file));
        ZipEntry ze;
        while ((ze=jis.getNextEntry())!=null) {
            if (ze.getName().equals(name)) 
                return new BufferedInputStream(jis);
        }
        return null;        
    
public java.util.jar.ManifestgetManifest()

return
the manifest information for this abstract archive

        JarInputStream jis = new JarInputStream(new ByteArrayInputStream(file));
        Manifest m = jis.getManifest();
        jis.close();
        return m;
    
public java.net.URIgetURI()

        return null;
    
public voidopen(java.lang.String path)

        File in = new File(path);
        if (!in.exists()) {
            throw new FileNotFoundException(path);            
        }
        FileInputStream is = new FileInputStream(in);
        read(is);
    
public java.io.OutputStreamputNextEntry(java.lang.String name)

returns
an @see java.io.OutputStream for a new entry in this current abstract archive.
param
the entry name

        return null;
    
private voidread(java.io.InputStream is)

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ArchivistUtils.copy(new BufferedInputStream(is), new BufferedOutputStream(baos));
        file = baos.toByteArray();
        
    
public booleanrenameTo(java.lang.String name)
rename the archive

param
name the archive name

        return false;