Package org.eclipse.osgi.storage.bundlefile

# Class CloseableBundleFile<E>

java.lang.Object
org.eclipse.osgi.storage.bundlefile.BundleFile
org.eclipse.osgi.storage.bundlefile.CloseableBundleFile<E>

Type Parameters:
  `E` - a type specified by extending classes to call `getInputStream(Object)`

Direct Known Subclasses:
  `ZipBundleFile`

public abstract class CloseableBundleFile<E> extends BundleFile
A BundleFile that manages the number of open bundle files by using the MRUBundleFileList

## Field Summary

Fields
Modifier and Type
Field
Description
`protected final org.eclipse.osgi.internal.debug.Debug`
`debug`
`protected final BundleInfo.Generation`
`generation`

### Fields inherited from class org.eclipse.osgi.storage.bundlefile.BundleFile

`basefile`

## Constructor Summary

Constructors
Constructor
Description
`CloseableBundleFile(File basefile, BundleInfo.Generation generation, MRUBundleFileList mruList, org.eclipse.osgi.internal.debug.Debug debug)`

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
Closes the BundleFile.
`boolean`
`containsDir(String dir)`
Determines if any BundleEntries exist in the given directory path.
`protected abstract void`
`doClose()`
Closes the bundle file
`protected abstract InputStream`
`doGetInputStream(E entry)`
Gets the input stream for the specified entry.
`protected abstract void`
`doOpen()`
Opens the bundle file
`protected abstract BundleEntry`
`findEntry(String path)`
Finds the bundle entry for the specified path
`BundleEntry`
`getEntry(String path)`
Locates a file name in this bundle and returns a BundleEntry object
`Enumeration<String>`
`getEntryPaths(String path, boolean recurse)`
Allows to access the entries of the bundle.
`File`
`getFile(String entry, boolean nativeCode)`
Returns a File for the bundle entry specified by the path.
`InputStream`
`getInputStream(E entry)`
Gets the input stream for the specified entry.
`protected abstract Iterable<String>`
`getPaths()`
`protected boolean`
`lockOpen()`
Checks if the bundle file is open
`void`
`open()`
Opens the BundleFiles.
`protected abstract void`
`postClose()`
Called after closing the bundle file.
`protected void`
`releaseOpen()`
Unlocks the open lock

### Methods inherited from class org.eclipse.osgi.storage.bundlefile.BundleFile

`createResourceURL, createURL, fixTrailingSlash, getBaseFile, getEntryPaths, getResourceURL, toString`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Field Details

### generation

protected final BundleInfo.Generation generation

### debug

protected final org.eclipse.osgi.internal.debug.Debug debug

## Constructor Details

### CloseableBundleFile

public CloseableBundleFile(File basefile, BundleInfo.Generation generation, MRUBundleFileList mruList, org.eclipse.osgi.internal.debug.Debug debug)

## Method Details

### lockOpen

protected boolean lockOpen()
Checks if the bundle file is open

Returns:
  true if the bundle file is open and locked

### releaseOpen

protected void releaseOpen()
Unlocks the open lock

### doOpen

protected abstract void doOpen() throws IOException
Opens the bundle file

Throws:
  `IOException` - if an error occurs

### getPaths

protected abstract Iterable<String> getPaths()

### getFile

public File getFile(String entry, boolean nativeCode)
Description copied from class: `BundleFile`
Returns a File for the bundle entry specified by the path. If required the content of the bundle entry is extracted into a file on the file system.

Specified by:
  `getFile` in class `BundleFile`
Parameters:
  `entry` - The path to the entry to locate a File for.
  `nativeCode` - true if the path is native code.
Returns:
  A File object to access the contents of the bundle entry.

### containsDir

public boolean containsDir(String dir)
Description copied from class: `BundleFile`
Determines if any BundleEntries exist in the given directory path.

Specified by:
  `containsDir` in class `BundleFile`
Parameters:
  `dir` - The directory path to check existence of.
Returns:
  true if the BundleFile contains entries under the given directory path; false otherwise.

### getEntry

public BundleEntry getEntry(String path)
Description copied from class: `BundleFile`
Locates a file name in this bundle and returns a BundleEntry object

Specified by:
  `getEntry` in class `BundleFile`
Parameters:
  `path` - path of the entry to locate in the bundle
Returns:
  BundleEntry object or null if the file name does not exist in the bundle

### findEntry

protected abstract BundleEntry findEntry(String path)
Finds the bundle entry for the specified path

Parameters:
  `path` - the path of the entry to find
Returns:
  the entry or `null` if no entry exists

### getEntryPaths

public Enumeration<String> getEntryPaths(String path, boolean recurse)
Description copied from class: `BundleFile`
Allows to access the entries of the bundle. Since the bundle content is usually a jar, this allows to access the jar contents. GetEntryPaths allows to enumerate the content of "path". If path is a directory, it is equivalent to listing the directory contents. The returned names are either files or directories themselves. If a returned name is a directory, it finishes with a slash. If a returned name is a file, it does not finish with a slash.

Specified by:
  `getEntryPaths` in class `BundleFile`
Parameters:
  `path` - path of the entry to locate in the bundle
  `recurse` - - If `true`, provide entries for the files and directories within the directory denoted by `path` plus all sub-directories and files; otherwise, provide only the entries within the immediate directory.
Returns:
  an Enumeration of Strings that indicate the paths found or null if the path does not exist.

### close

public void close() throws IOException
Description copied from class: `BundleFile`
Closes the BundleFile.

Specified by:
  `close` in class `BundleFile`
Throws:
  `IOException` - if any error occurs.

### doClose

protected abstract void doClose() throws IOException
Closes the bundle file

Throws:
  `IOException` - if an error occurs closing

### postClose

protected abstract void postClose()
Called after closing the bundle file.

### open

public void open() throws IOException
Description copied from class: `BundleFile`
Opens the BundleFiles.

Specified by:
  `open` in class `BundleFile`
Throws:
  `IOException` - if any error occurs.

### getInputStream

public InputStream getInputStream(E entry) throws IOException
Gets the input stream for the specified entry. This method will ensure the bundle file is open, call `doGetInputStream(Object)` to get the actual input stream, then if the bundle file limit is enabled it will wrapper the input stream in a special input stream that keeps track of active input streams to prevent the bundle file from being closed until the stream is closed (or a timeout happens).

Parameters:
  `entry` - the entry to get the input stream for
Returns:
  the input stream for the entry
Throws:
  `IOException`

### doGetInputStream

protected abstract InputStream doGetInputStream(E entry) throws IOException
Gets the input stream for the specified entry.

Parameters:
  `entry` - the entry to get the input stream for. The type is specified by the extending class.
Returns:
  the input steam for the entry
Throws:
  `IOException` - if an error occurs