edu.rice.cs.util.jar
Class JarBuilder

java.lang.Object
  extended by edu.rice.cs.util.jar.JarBuilder

public class JarBuilder
extends Object


Field Summary
private  JarOutputStream _output
           
 
Constructor Summary
JarBuilder(File file)
          Creates a file file without a manifest
JarBuilder(File jar, File manifest)
          Creates an empty jar file with the given manifest
JarBuilder(File jar, Manifest manifest)
          Creates an empty jar file with the given manifest
 
Method Summary
 void addDirectoryRecursive(File dir, String parent)
          Add the directory into the directory specified by parent
 void addDirectoryRecursive(File dir, String parent, FileFilter filter)
          Add the directory into the directory specified by parent
private  boolean addDirectoryRecursiveHelper(File dir, String parent, byte[] buffer, FileFilter filter)
          Add the contents of a directory that match a filter to the archive
 void addFile(File file, String parent, String fileName)
          Adds the file to the given path and name
 void close()
          Close writing on the jar file
 boolean makeDirectory(String parent, String dirName)
          Makes a directory in the jar file
private  String makeName(String parent, String name)
          Takes a parent name and a field name and returns the concatenation of them correctly
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_output

private JarOutputStream _output
Constructor Detail

JarBuilder

public JarBuilder(File file)
           throws IOException
Creates a file file without a manifest

Parameters:
file - the file to write the jar to
Throws:
IOException - thrown if the file cannot be opened for writing

JarBuilder

public JarBuilder(File jar,
                  File manifest)
           throws IOException
Creates an empty jar file with the given manifest

Parameters:
jar - the file to write the jar to
manifest - the file that is the manifest for the archive
Throws:
IOException - thrown if either file cannot be opened for reading

JarBuilder

public JarBuilder(File jar,
                  Manifest manifest)
Creates an empty jar file with the given manifest

Parameters:
jar - the file to write the jar to
manifest - the manifest file for the jar
See Also:
ManifestWriter
Method Detail

makeName

private String makeName(String parent,
                        String name)
Takes a parent name and a field name and returns the concatenation of them correctly

Parameters:
parent - The parent directory
name - The name of the file or directory
Returns:
the string concatenation of the parent and the name

addFile

public void addFile(File file,
                    String parent,
                    String fileName)
             throws IOException
Adds the file to the given path and name

Parameters:
file - the file to be added
parent - the directory to the path in which the file is to be added
fileName - the name of the file in the archive
Throws:
IOException

addDirectoryRecursive

public void addDirectoryRecursive(File dir,
                                  String parent)
Add the directory into the directory specified by parent

Parameters:
dir - the directory to add
parent - the path inside the jar that the directory should be added to

addDirectoryRecursive

public void addDirectoryRecursive(File dir,
                                  String parent,
                                  FileFilter filter)
Add the directory into the directory specified by parent

Parameters:
dir - the directory to add
parent - the path inside the jar that the directory should be added to
filter - the filter used to filter the files

addDirectoryRecursiveHelper

private boolean addDirectoryRecursiveHelper(File dir,
                                            String parent,
                                            byte[] buffer,
                                            FileFilter filter)
Add the contents of a directory that match a filter to the archive

Parameters:
dir - the directory to add
parent - the directory to add into
buffer - a buffer that is 2048 bytes
filter - the FileFilter to filter the files by
Returns:
true on success, false on failure

makeDirectory

public boolean makeDirectory(String parent,
                             String dirName)
Makes a directory in the jar file

Parameters:
parent - The name of the parent that the directory is to be created in
dirName - The name of the directory to be created
Returns:
Returns true on success, false on failure

close

public void close()
           throws IOException
Close writing on the jar file

Throws:
IOException