org.norther.tammi.acorn.util.zip
Class JarHandler

java.lang.Object
  extended by org.norther.tammi.acorn.util.zip.JarHandler

public class JarHandler
extends Object

A small handler around a Jar

Based on JarHolder in the Apache Jakarta Velocity project.

Version:
$Id: JarHandler.java,v 1.9 2010-05-05 20:15:26 cvsimp Exp $
Author:
Dave Bryson, Ilkka Priha

Field Summary
static String JAR_ENTRY_DELIMITER
          The jar entry delimiter.
static String JAR_FILE_PROTOCOL
          The jar file protocol.
static String JAR_FILE_PROTOCOL_PREFIX
          The jar file protocol prefix.
static String JAR_HTTP_PROTOCOL
          The jar http protocol.
static String JAR_PROTOCOL
          The jar protocol.
static String JAR_PROTOCOL_PREFIX
          The jar protocol prefix.
 
Constructor Summary
JarHandler(File file)
          Constructs a new jar handler.
JarHandler(File file, String dir)
          Constructs a new jar handler.
JarHandler(String path)
          Constructs a new jar handler.
JarHandler(URL url)
          Constructs a new jar handler.
 
Method Summary
 void close()
          Closes the jar.
 Map<String,String> getEntries()
          Gets entries from the URL directory of the jar.
 JarEntry getEntry(String source)
          Gets a resource entry.
 JarFile getJar()
          Gets the jar.
static String getJarEntryPath(String path)
          Gets the jar entry path of the specified jar path.
static String getJarEntryPath(URL url)
          Gets the jar entry path of the specified jar URL.
static String getJarFilePath(String path)
          Gets the jar file path of the specified jar path.
static String getJarFilePath(URL url)
          Gets the jar file path of the specified jar URL.
static String getJarProtocol(String path)
          Gets the jar protocol of the specified jar path.
static String getJarProtocol(URL url)
          Gets the jar protocol of the specified jar URL.
 InputStream getResourceAsStream(String source)
          Gets a resource stream.
 String getURLPath()
          Gets the URL path of the jar.
static URL toJarURL(String protocol, String path)
          Converts the specified path into a jar URL.
static URL toJarURL(String protocol, String path, String entry)
          Converts the specified path and entry into a jar URL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JAR_PROTOCOL

public static final String JAR_PROTOCOL
The jar protocol.

See Also:
Constant Field Values

JAR_FILE_PROTOCOL

public static final String JAR_FILE_PROTOCOL
The jar file protocol.

See Also:
Constant Field Values

JAR_HTTP_PROTOCOL

public static final String JAR_HTTP_PROTOCOL
The jar http protocol.

See Also:
Constant Field Values

JAR_PROTOCOL_PREFIX

public static final String JAR_PROTOCOL_PREFIX
The jar protocol prefix.

See Also:
Constant Field Values

JAR_FILE_PROTOCOL_PREFIX

public static final String JAR_FILE_PROTOCOL_PREFIX
The jar file protocol prefix.

See Also:
Constant Field Values

JAR_ENTRY_DELIMITER

public static final String JAR_ENTRY_DELIMITER
The jar entry delimiter.

See Also:
Constant Field Values
Constructor Detail

JarHandler

public JarHandler(URL url)
Constructs a new jar handler.

Parameters:
url - URL to the jar.
Throws:
IllegalStateException - if not available.

JarHandler

public JarHandler(File file)
Constructs a new jar handler.

Parameters:
file - the jar file.
Throws:
IllegalStateException - if not available.

JarHandler

public JarHandler(File file,
                  String dir)
Constructs a new jar handler.

Parameters:
file - the jar file.
dir - the directory.
Throws:
IllegalStateException - if not available.

JarHandler

public JarHandler(String path)
Constructs a new jar handler.

Parameters:
path - the URL path of the jar.
Throws:
IllegalStateException - if not available.
Method Detail

getJarProtocol

public static String getJarProtocol(URL url)
Gets the jar protocol of the specified jar URL.

Parameters:
url - the jar URL.
Returns:
the protocol or null.

getJarProtocol

public static String getJarProtocol(String path)
Gets the jar protocol of the specified jar path.

Parameters:
path - the jar path.
Returns:
the protocol or null.

getJarFilePath

public static String getJarFilePath(URL url)
Gets the jar file path of the specified jar URL.

Parameters:
url - the jar URL.
Returns:
the jar file path or null.

getJarFilePath

public static String getJarFilePath(String path)
Gets the jar file path of the specified jar path.

Parameters:
path - the jar path.
Returns:
the jar file path or null.

getJarEntryPath

public static String getJarEntryPath(URL url)
Gets the jar entry path of the specified jar URL.

Parameters:
url - the jar URL.
Returns:
the jar entry path or null.

getJarEntryPath

public static String getJarEntryPath(String path)
Gets the jar entry path of the specified jar path.

Parameters:
path - the jar path.
Returns:
the jar entry path or null.

toJarURL

public static URL toJarURL(String protocol,
                           String path)
                    throws MalformedURLException
Converts the specified path into a jar URL.

Parameters:
protocol - the protocol.
path - the path.
Returns:
the jar URL.
Throws:
MalformedURLException - for an invalid path.

toJarURL

public static URL toJarURL(String protocol,
                           String path,
                           String entry)
                    throws MalformedURLException
Converts the specified path and entry into a jar URL.

Parameters:
protocol - the protocol.
path - the path.
entry - the entry.
Returns:
the jar URL.
Throws:
MalformedURLException - for an invalid path.

close

public void close()
Closes the jar.


getEntry

public JarEntry getEntry(String source)
Gets a resource entry.

Parameters:
source - the resource.
Returns:
the resource as an entry or null.
Throws:
IllegalStateException - if already closed.

getResourceAsStream

public InputStream getResourceAsStream(String source)
                                throws IOException
Gets a resource stream.

Parameters:
source - the resource.
Returns:
the resource as a stream or null.
Throws:
IOException - on I/O errors.
IllegalStateException - if already closed.

getEntries

public Map<String,String> getEntries()
Gets entries from the URL directory of the jar.

Returns:
a map of jar entries.
Throws:
IllegalStateException - if already closed.

getJar

public JarFile getJar()
Gets the jar.

Returns:
the jar.
Throws:
IllegalStateException - if already closed.

getURLPath

public String getURLPath()
Gets the URL path of the jar.

Returns:
the URL path.


Copyright © 2004 The Norther Organization. All rights reserved.