Class BundleFile

java.lang.Object
org.eclipse.osgi.storage.bundlefile.BundleFile
Direct Known Subclasses:
BundleFileWrapper, CloseableBundleFile, DirBundleFile, NestedDirBundleFile, SystemBundleFile

public abstract class BundleFile extends Object
The BundleFile API is used by Adaptors to read resources out of an installed Bundle in the Framework.

Clients wishing to modify or extend the functionality of this class at runtime should extend the associated decorator instead.

  • Field Details

    • basefile

      protected File basefile
      The File object for this BundleFile.
  • Constructor Details

    • BundleFile

      protected BundleFile(File basefile)
      BundleFile constructor
      Parameters:
      basefile - The File object where this BundleFile is persistently stored.
  • Method Details

    • getFile

      public abstract File getFile(String path, boolean nativeCode)
      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.
      Parameters:
      path - 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.
    • getEntry

      public abstract BundleEntry getEntry(String path)
      Locates a file name in this bundle and returns a BundleEntry object
      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
    • getEntryPaths

      public Enumeration<String> getEntryPaths(String path)
      Performs the same function as calling getEntryPaths(String, boolean) with recurse equal to false.
      Parameters:
      path - path of the entry to locate in the bundle
      Returns:
      an Enumeration of Strings that indicate the paths found or null if the path does not exist.
    • getEntryPaths

      public abstract Enumeration<String> getEntryPaths(String path, boolean recurse)
      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.
      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 abstract void close() throws IOException
      Closes the BundleFile.
      Throws:
      IOException - if any error occurs.
    • open

      public abstract void open() throws IOException
      Opens the BundleFiles.
      Throws:
      IOException - if any error occurs.
    • containsDir

      public abstract boolean containsDir(String dir)
      Determines if any BundleEntries exist in the given directory path.
      Parameters:
      dir - The directory path to check existence of.
      Returns:
      true if the BundleFile contains entries under the given directory path; false otherwise.
    • getResourceURL

      public URL getResourceURL(String path, Module hostModule, int index)
      Returns a URL to access the contents of the entry specified by the path. This method first calls getEntry(String) to locate the entry at the specified path. If no entry is found null is returned; otherwise createResourceURL(BundleEntry, Module, int, String) is called in order to create the URL. Subclasses should not override this method. Instead the methods getEntry(String) and/or createResourceURL(BundleEntry, Module, int, String) may be overriden to augment the behavior.
      Parameters:
      path - the path to the resource
      hostModule - the host module
      index - the resource index
      Returns:
      a URL to access the contents of the entry specified by the path
    • createResourceURL

      protected URL createResourceURL(BundleEntry bundleEntry, Module hostModule, int index, String path)
      Creates a URL to access the content of the specified entry
      Parameters:
      bundleEntry - the bundle entry
      hostModule - the host module
      index - the resource index
      Returns:
      a URL to access the contents of the specified entry
    • getBaseFile

      public File getBaseFile()
      Returns the base file for this BundleFile
      Returns:
      the base file for this BundleFile
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • createURL

      public static URL createURL(String protocol, long bundleId, ModuleContainer container, BundleEntry entry, int index, String path, URLStreamHandler handler)
    • fixTrailingSlash

      public static String fixTrailingSlash(String path, BundleEntry entry)