org.eclipse.osgi_3.8.2.v20130124-134944

abstract class BundleFile
{
  protected static final String PROP_SETPERMS_CMD = "osgi.filepermissions.command";
  static final SecureAction secureAction = (SecureAction)AccessController.doPrivileged(SecureAction.createSecureAction());
  protected File basefile;
  private int mruIndex = -1;
  
  public BundleFile() {}
  
  public BundleFile(File basefile)
  {
    this.basefile = basefile;
  }
  
  public abstract File getFile(String paramString, boolean paramBoolean);
  
  public abstract BundleEntry getEntry(String paramString);
  
  public abstract Enumeration<String> getEntryPaths(String paramString);
  
  public abstract void close()
    throws IOException;
  
  public abstract void open()
    throws IOException;
  
  public abstract boolean containsDir(String paramString);
  
  /**
   * @deprecated
   */
  public URL getResourceURL(String path, long hostBundleID)
  {
    return getResourceURL(path, hostBundleID, 0);
  }
  
  /**
   * @deprecated
   */
  public URL getResourceURL(String path, long hostBundleID, int index)
  {
    return internalGetResourceURL(path, null, hostBundleID, index);
  }
  
  public URL getResourceURL(String path, BaseData hostData, int index)
  {
    return internalGetResourceURL(path, hostData, 0L, index);
  }
  
  private URL internalGetResourceURL(String path, BaseData hostData, long hostBundleID, int index)
  {
    BundleEntry bundleEntry = getEntry(path);
    if (bundleEntry == null) {
      return null;
    }
    if (hostData != null) {
      hostBundleID = hostData.getBundleID();
    }
    path = fixTrailingSlash(path, bundleEntry);
    try
    {
      return secureAction.getURL("bundleresource", Long.toString(hostBundleID) + ".fwk" + Integer.toString(hostData.getAdaptor().hashCode()), index, path, new Handler(bundleEntry, hostData == null ? null : hostData.getAdaptor()));
    }
    catch (MalformedURLException localMalformedURLException) {}
    return null;
  }
  
  public File getBaseFile()
  {
    return basefile;
  }
  
  void setMruIndex(int index)
  {
    mruIndex = index;
  }
  
  int getMruIndex()
  {
    return mruIndex;
  }
  
  public static void setPermissions(File file)
  {
    String commandProp = FrameworkProperties.getProperty("osgi.filepermissions.command");
    if (commandProp == null) {
      commandProp = FrameworkProperties.getProperty("org.osgi.framework.command.execpermission");
    }
    if (commandProp == null) {
      return;
    }
    String[] temp = ManifestElement.getArrayFromList(commandProp, " ");
    List<String> command = new ArrayList(temp.length + 1);
    boolean foundFullPath = false;
    for (int i = 0; i < temp.length; i++) {
      if (("[fullpath]".equals(temp[i])) || ("${abspath}".equals(temp[i])))
      {
        command.add(file.getAbsolutePath());
        foundFullPath = true;
      }
      else
      {
        command.add(temp[i]);
      }
    }
    if (!foundFullPath) {
      command.add(file.getAbsolutePath());
    }
    try
    {
      Runtime.getRuntime().exec((String[])command.toArray(new String[command.size()])).waitFor();
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
  
  public String toString()
  {
    return String.valueOf(basefile);
  }
  
  public static String fixTrailingSlash(String path, BundleEntry entry)
  {
    if (path.length() == 0) {
      return "/";
    }
    if (path.charAt(0) != '/') {
      path = '/' + path;
    }
    String name = entry.getName();
    if (name.length() == 0) {
      return path;
    }
    boolean pathSlash = path.charAt(path.length() - 1) == '/';
    boolean entrySlash = (name.length() > 0) && (name.charAt(name.length() - 1) == '/');
    if (entrySlash != pathSlash) {
      if (entrySlash) {
        path = path + '/';
      } else {
        path = path.substring(0, path.length() - 1);
      }
    }
    return path;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.baseadaptor.bundlefile.BundleFile
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.baseadaptor.bundlefile;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import org.eclipse.osgi.baseadaptor.BaseData;

public class BundleFileWrapperChain
  extends BundleFile
{
  private final BundleFile wrapped;
  private final BundleFileWrapperChain next;
  
  public BundleFileWrapperChain(BundleFile wrapped, BundleFileWrapperChain next)
  {
    this.wrapped = wrapped;
    this.next = next;
  }
  
  public void close()
    throws IOException
  {
    wrapped.close();
  }
  
  public boolean containsDir(String dir)
  {
    return wrapped.containsDir(dir);
  }
  
  public BundleEntry getEntry(String path)
  {
    return wrapped.getEntry(path);
  }
  
  public Enumeration<String> getEntryPaths(String path)
  {
    return wrapped.getEntryPaths(path);
  }
  
  public File getFile(String path, boolean nativeCode)
  {
    return wrapped.getFile(path, nativeCode);
  }
  
  public void open()
    throws IOException
  {
    wrapped.open();
  }
  
  public File getBaseFile()
  {
    return wrapped.getBaseFile();
  }
  
  public URL getResourceURL(String path, BaseData hostData, int index)
  {
    return wrapped.getResourceURL(path, hostData, index);
  }
  
  public String toString()
  {
    return wrapped.toString();
  }
  
  public BundleFile getWrapped()
  {
    return wrapped;
  }
  
  public BundleFileWrapperChain getNext()
  {
    return next;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.baseadaptor.bundlefile.BundleFileWrapperChain
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.baseadaptor.bundlefile;

import java.io.File;
import java.util.Enumeration;
import java.util.NoSuchElementException;
import org.eclipse.osgi.framework.util.SecureAction;

class DirBundleFile$1
  implements Enumeration<String>
{
  int cur = 0;
  final DirBundleFile this$0;
  
  DirBundleFile$1(DirBundleFile paramDirBundleFile, String[] paramArrayOfString, File paramFile, String paramString) {}
  
  public boolean hasMoreElements()
  {
    return (val$fileList != null) && (cur < val$fileList.length);
  }
  
  public String nextElement()
  {
    if (!hasMoreElements()) {
      throw new NoSuchElementException();
    }
    File childFile = new File(val$pathFile, val$fileList[cur]);
    StringBuffer sb = new StringBuffer(val$dirPath).append(val$fileList[(cur++)]);
    if (BundleFile.secureAction.isDirectory(childFile)) {
      sb.append("/");
    }
    return sb.toString();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.baseadaptor.bundlefile.DirBundleFile.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.baseadaptor.bundlefile;

import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.NoSuchElementException;
import org.eclipse.osgi.framework.util.SecureAction;
import org.eclipse.osgi.internal.baseadaptor.AdaptorMsg;
import org.eclipse.osgi.util.NLS;

public class DirBundleFile
  extends BundleFile
{
  public DirBundleFile(File basefile)
    throws IOException
  {
    super(basefile);
    if ((!BundleFile.secureAction.exists(basefile)) || (!BundleFile.secureAction.isDirectory(basefile))) {
      throw new IOException(NLS.bind(AdaptorMsg.ADAPTOR_DIRECTORY_EXCEPTION, basefile));
    }
  }
  
  public File getFile(String path, boolean nativeCode)
  {
    boolean checkInBundle = (path != null) && (path.indexOf("..") >= 0);
    File file = new File(basefile, path);
    if (!BundleFile.secureAction.exists(file)) {
      return null;
    }
    if (checkInBundle) {
      try
      {
        if (!BundleFile.secureAction.getCanonicalPath(file).startsWith(BundleFile.secureAction.getCanonicalPath(basefile))) {
          return null;
        }
      }
      catch (IOException localIOException)
      {
        return null;
      }
    }
    return file;
  }
  
  public BundleEntry getEntry(String path)
  {
    File filePath = getFile(path, false);
    if (filePath == null) {
      return null;
    }
    return new FileBundleEntry(filePath, path);
  }
  
  public boolean containsDir(String dir)
  {
    File dirPath = getFile(dir, false);
    return (dirPath != null) && (BundleFile.secureAction.isDirectory(dirPath));
  }
  
  public Enumeration<String> getEntryPaths(String path)
  {
    if ((path.length() > 0) && (path.charAt(0) == '/')) {
      path = path.substring(1);
    }
    final File pathFile = getFile(path, false);
    if ((pathFile == null) || (!BundleFile.secureAction.isDirectory(pathFile))) {
      return null;
    }
    final String[] fileList = BundleFile.secureAction.list(pathFile);
    if ((fileList == null) || (fileList.length == 0)) {
      return null;
    }
    final String dirPath = path + '/';
    new Enumeration()
    {
      int cur = 0;
      
      public boolean hasMoreElements()
      {
        return (fileList != null) && (cur < fileList.length);
      }
      
      public String nextElement()
      {
        if (!hasMoreElements()) {
          throw new NoSuchElementException();
        }
        File childFile = new File(pathFile, fileList[cur]);
        StringBuffer sb = new StringBuffer(dirPath).append(fileList[(cur++)]);
        if (BundleFile.secureAction.isDirectory(childFile)) {
          sb.append("/");
        }
        return sb.toString();
      }
    };
  }
  
  public void close() {}
  
  public void open() {}
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.baseadaptor.bundlefile.DirBundleFile
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.baseadaptor.bundlefile;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

public class DirZipBundleEntry
  extends BundleEntry
{
  private ZipBundleFile bundleFile;
  String name;
  
  public DirZipBundleEntry(ZipBundleFile bundleFile, String name)
  {
    this.name = ((name.length() > 0) && (name.charAt(0) == '/') ? name.substring(1) : name);
    this.bundleFile = bundleFile;
  }
  
  public InputStream getInputStream()
    throws IOException
  {
    return new ByteArrayInputStream(new byte[0]);
  }
  
  public long getSize()
  {
    return 0L;
  }
  
  public String getName()
  {
    return name;
  }
  
  public long getTime()
  {
    return 0L;
  }
  
  public URL getLocalURL()
  {
    try
    {
      return new URL("jar:" + bundleFile.basefile.toURL() + "!/" + name);
    }
    catch (MalformedURLException localMalformedURLException) {}
    return null;
  }
  
  public URL getFileURL()
  {
    try
    {
      return bundleFile.extractDirectory(name).toURL();
    }
    catch (MalformedURLException localMalformedURLException) {}
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.baseadaptor.bundlefile.DirZipBundleEntry
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.baseadaptor.bundlefile;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.osgi.framework.util.SecureAction;

public class FileBundleEntry
  extends BundleEntry
{
  private final File file;
  private final String name;
  
  FileBundleEntry(File file, String name)
  {
    this.file = file;
    boolean endsInSlash = (name.length() > 0) && (name.charAt(name.length() - 1) == '/');
    if (BundleFile.secureAction.isDirectory(file))
    {
      if (!endsInSlash) {
        name = name + '/';
      }
    }
    else if (endsInSlash) {
      name = name.substring(0, name.length() - 1);
    }
    this.name = name;
  }
  
  public InputStream getInputStream()
    throws IOException
  {
    return BundleFile.secureAction.getFileInputStream(file);
  }
  
  public long getSize()
  {
    return BundleFile.secureAction.length(file);
  }
  
  public String getName()
  {
    return name;
  }
  
  public long getTime()
  {
    return BundleFile.secureAction.lastModified(file);
  }
  
  public URL getLocalURL()
  {
    return getFileURL();
  }
  
  public URL getFileURL()
  {
    try
    {
      return file.toURL();
    }
    catch (MalformedURLException localMalformedURLException) {}
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.baseadaptor.bundlefile.FileBundleEntry
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.baseadaptor.bundlefile;

import java.util.Map;
import org.eclipse.osgi.framework.eventmgr.CopyOnWriteIdentityMap;
import org.eclipse.osgi.framework.eventmgr.EventDispatcher;
import org.eclipse.osgi.framework.eventmgr.EventManager;
import org.eclipse.osgi.framework.eventmgr.ListenerQueue;
import org.eclipse.osgi.framework.util.SecureAction;

public class MRUBundleFileList
  implements EventDispatcher<Object, Object, BundleFile>
{
  private static final String PROP_FILE_LIMIT = "osgi.bundlefile.limit";
  private static final int MIN = 10;
  private static final int PROP_FILE_LIMIT_VALUE;
  private static final ThreadLocal<BundleFile> closingBundleFile = new ThreadLocal();
  private final BundleFile[] bundleFileList;
  private final long[] useStampList;
  private final int fileLimit;
  
  static
  {
    int propValue = 100;
    try
    {
      String prop = BundleFile.secureAction.getProperty("osgi.bundlefile.limit");
      if (prop != null) {
        propValue = Integer.parseInt(prop);
      }
    }
    catch (NumberFormatException localNumberFormatException) {}
    PROP_FILE_LIMIT_VALUE = propValue;
  }
  
  private EventManager bundleFileCloserManager = null;
  private final Map<Object, Object> bundleFileCloser;
  private int numOpen = 0;
  private long curUseStamp = 0L;
  private boolean firstDispatch = true;
  
  public MRUBundleFileList()
  {
    this(PROP_FILE_LIMIT_VALUE);
  }
  
  public MRUBundleFileList(int fileLimit)
  {
    this.fileLimit = fileLimit;
    if (fileLimit >= 10)
    {
      bundleFileList = new BundleFile[fileLimit];
      useStampList = new long[fileLimit];
      bundleFileCloser = new CopyOnWriteIdentityMap();
      bundleFileCloser.put(this, this);
    }
    else
    {
      bundleFileList = null;
      useStampList = null;
      bundleFileCloser = null;
    }
  }
  
  public void add(BundleFile bundleFile)
  {
    if (fileLimit < 10) {
      return;
    }
    BundleFile toRemove = null;
    EventManager manager = null;
    synchronized (this)
    {
      if (bundleFile.getMruIndex() >= 0) {
        return;
      }
      int index = 0;
      if (numOpen < fileLimit)
      {
        for (int i = 0; i < fileLimit; i++) {
          if (bundleFileList[i] == null)
          {
            index = i;
            break;
          }
        }
      }
      else
      {
        index = 0;
        for (int i = 1; i < fileLimit; i++) {
          if (useStampList[i] < useStampList[index]) {
            index = i;
          }
        }
        toRemove = bundleFileList[index];
        if (toRemove.getMruIndex() != index) {
          throw new IllegalStateException("The BundleFile has the incorrect mru index: " + index + " != " + toRemove.getMruIndex());
        }
        removeInternal(toRemove);
      }
      bundleFileList[index] = bundleFile;
      bundleFile.setMruIndex(index);
      incUseStamp(index);
      numOpen += 1;
      if (toRemove != null)
      {
        if (bundleFileCloserManager == null) {
          bundleFileCloserManager = new EventManager("Bundle File Closer");
        }
        manager = bundleFileCloserManager;
      }
    }
    closeBundleFile(toRemove, manager);
  }
  
  public boolean remove(BundleFile bundleFile)
  {
    if (fileLimit < 10) {
      return false;
    }
    synchronized (this)
    {
      int index = bundleFile.getMruIndex();
      if ((index >= 0) && (index < fileLimit) && (bundleFileList[index] == bundleFile))
      {
        removeInternal(bundleFile);
        return true;
      }
    }
    return false;
  }
  
  private void removeInternal(BundleFile bundleFile)
  {
    int index = bundleFile.getMruIndex();
    bundleFile.setMruIndex(-1);
    bundleFileList[index] = null;
    useStampList[index] = -1L;
    numOpen -= 1;
  }
  
  public void use(BundleFile bundleFile)
  {
    if (fileLimit < 10) {
      return;
    }
    synchronized (this)
    {
      int index = bundleFile.getMruIndex();
      if ((index >= 0) && (index < fileLimit) && (bundleFileList[index] == bundleFile)) {
        incUseStamp(index);
      }
    }
  }
  
  private void incUseStamp(int index)
  {
    if (curUseStamp == Long.MAX_VALUE)
    {
      for (int i = 0; i < fileLimit; i++) {
        useStampList[i] = 0L;
      }
      curUseStamp = 0L;
    }
    useStampList[index] = (++curUseStamp);
  }
  
  /* Error */
  public final void dispatchEvent(Object eventListener, Object listenerObject, int eventAction, BundleFile eventObject)
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 186	org/eclipse/osgi/baseadaptor/bundlefile/MRUBundleFileList:firstDispatch	Z
    //   4: ifeq +15 -> 19
    //   7: invokestatic 200	java/lang/Thread:currentThread	()Ljava/lang/Thread;
    //   10: aconst_null
    //   11: invokevirtual 199	java/lang/Thread:setContextClassLoader	(Ljava/lang/ClassLoader;)V
    //   14: aload_0
    //   15: iconst_0
    //   16: putfield 186	org/eclipse/osgi/baseadaptor/bundlefile/MRUBundleFileList:firstDispatch	Z
    //   19: getstatic 188	org/eclipse/osgi/baseadaptor/bundlefile/MRUBundleFileList:closingBundleFile	Ljava/lang/ThreadLocal;
    //   22: aload 4
    //   24: invokevirtual 203	java/lang/ThreadLocal:set	(Ljava/lang/Object;)V
    //   27: aload 4
    //   29: invokevirtual 205	org/eclipse/osgi/baseadaptor/bundlefile/BundleFile:close	()V
    //   32: goto +26 -> 58
    //   35: pop
    //   36: getstatic 188	org/eclipse/osgi/baseadaptor/bundlefile/MRUBundleFileList:closingBundleFile	Ljava/lang/ThreadLocal;
    //   39: aconst_null
    //   40: invokevirtual 203	java/lang/ThreadLocal:set	(Ljava/lang/Object;)V
    //   43: goto +22 -> 65
    //   46: astore 5
    //   48: getstatic 188	org/eclipse/osgi/baseadaptor/bundlefile/MRUBundleFileList:closingBundleFile	Ljava/lang/ThreadLocal;
    //   51: aconst_null
    //   52: invokevirtual 203	java/lang/ThreadLocal:set	(Ljava/lang/Object;)V
    //   55: aload 5
    //   57: athrow
    //   58: getstatic 188	org/eclipse/osgi/baseadaptor/bundlefile/MRUBundleFileList:closingBundleFile	Ljava/lang/ThreadLocal;
    //   61: aconst_null
    //   62: invokevirtual 203	java/lang/ThreadLocal:set	(Ljava/lang/Object;)V
    //   65: return
    // Line number table:
    //   Java source line #181	-> byte code offset #0
    //   Java source line #183	-> byte code offset #7
    //   Java source line #184	-> byte code offset #14
    //   Java source line #187	-> byte code offset #19
    //   Java source line #188	-> byte code offset #27
    //   Java source line #189	-> byte code offset #32
    //   Java source line #192	-> byte code offset #36
    //   Java source line #191	-> byte code offset #46
    //   Java source line #192	-> byte code offset #48
    //   Java source line #193	-> byte code offset #55
    //   Java source line #192	-> byte code offset #58
    //   Java source line #194	-> byte code offset #65
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	66	0	this	MRUBundleFileList
    //   0	66	1	eventListener	Object
    //   0	66	2	listenerObject	Object
    //   0	66	3	eventAction	int
    //   0	66	4	eventObject	BundleFile
    //   46	10	5	localObject	Object
    //   35	1	6	localIOException	java.io.IOException
    // Exception table:
    //   from	to	target	type
    //   19	32	35	java/io/IOException
    //   19	36	46	finally
  }
  
  private void closeBundleFile(BundleFile toRemove, EventManager manager)
  {
    if (toRemove == null) {
      return;
    }
    try
    {
      ListenerQueue<Object, Object, BundleFile> queue = new ListenerQueue(manager);
      
      queue.queueListeners(bundleFileCloser.entrySet(), this);
      
      queue.dispatchEventAsynchronous(0, toRemove);
    }
    catch (Throwable localThrowable) {}
  }
  
  public void shutdown()
  {
    synchronized (this)
    {
      if (bundleFileCloserManager != null) {
        bundleFileCloserManager.close();
      }
      bundleFileCloserManager = null;
    }
  }
  
  public boolean isClosing(BundleFile bundleFile)
  {
    if (fileLimit < 10) {
      return false;
    }
    return closingBundleFile.get() == bundleFile;
  }
  
  public boolean isEnabled()
  {
    return fileLimit >= 10;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.baseadaptor.bundlefile.MRUBundleFileList
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.baseadaptor.bundlefile;

import java.util.Enumeration;

class NestedDirBundleFile$1
  implements Enumeration<String>
{
  final NestedDirBundleFile this$0;
  
  NestedDirBundleFile$1(NestedDirBundleFile paramNestedDirBundleFile, Enumeration paramEnumeration, int paramInt) {}
  
  public boolean hasMoreElements()
  {
    return val$basePaths.hasMoreElements();
  }
  
  public String nextElement()
  {
    String next = (String)val$basePaths.nextElement();
    return next.substring(val$cpLength);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.baseadaptor.bundlefile.NestedDirBundleFile.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.baseadaptor.bundlefile;

import java.io.File;
import java.io.IOException;
import java.util.Enumeration;

public class NestedDirBundleFile
  extends BundleFile
{
  private final BundleFile baseBundleFile;
  private final String cp;
  
  public NestedDirBundleFile(BundleFile baseBundlefile, String cp)
  {
    super(baseBundlefile.getBaseFile());
    baseBundleFile = baseBundlefile;
    if (cp.charAt(cp.length() - 1) != '/') {
      cp = cp + '/';
    }
    this.cp = cp;
  }
  
  public void close() {}
  
  public BundleEntry getEntry(String path)
  {
    return baseBundleFile.getEntry(prependNestedDir(path));
  }
  
  public boolean containsDir(String dir)
  {
    if (dir == null) {
      return false;
    }
    return baseBundleFile.containsDir(prependNestedDir(dir));
  }
  
  private String prependNestedDir(String path)
  {
    if ((path.length() > 0) && (path.charAt(0) == '/')) {
      path = path.substring(1);
    }
    return cp + path;
  }
  
  public Enumeration<String> getEntryPaths(String path)
  {
    final Enumeration<String> basePaths = baseBundleFile.getEntryPaths(prependNestedDir(path));
    final int cpLength = cp.length();
    if (basePaths == null) {
      return null;
    }
    new Enumeration()
    {
      public boolean hasMoreElements()
      {
        return basePaths.hasMoreElements();
      }
      
      public String nextElement()
      {
        String next = (String)basePaths.nextElement();
        return next.substring(cpLength);
      }
    };
  }
  
  public File getFile(String entry, boolean nativeCode)
  {
    return null;
  }
  
  public void open()
    throws IOException
  {}
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.baseadaptor.bundlefile.NestedDirBundleFile
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.baseadaptor.bundlefile;

import java.io.IOException;
import java.io.InputStream;

class ZipBundleEntry$ZipBundleEntryInputStream
  extends InputStream
{
  private final InputStream stream;
  private boolean closed = false;
  final ZipBundleEntry this$0;
  
  public ZipBundleEntry$ZipBundleEntryInputStream(ZipBundleEntry paramZipBundleEntry, InputStream stream)
  {
    this.stream = stream;
  }
  
  public int available()
    throws IOException
  {
    return stream.available();
  }
  
  /* Error */
  public void close()
    throws IOException
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 62	org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry$ZipBundleEntryInputStream:stream	Ljava/io/InputStream;
    //   4: invokevirtual 67	java/io/InputStream:close	()V
    //   7: goto +43 -> 50
    //   10: astore_1
    //   11: aload_0
    //   12: dup
    //   13: astore_2
    //   14: monitorenter
    //   15: aload_0
    //   16: getfield 61	org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry$ZipBundleEntryInputStream:closed	Z
    //   19: ifeq +6 -> 25
    //   22: aload_2
    //   23: monitorexit
    //   24: return
    //   25: aload_0
    //   26: iconst_1
    //   27: putfield 61	org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry$ZipBundleEntryInputStream:closed	Z
    //   30: aload_2
    //   31: monitorexit
    //   32: goto +6 -> 38
    //   35: aload_2
    //   36: monitorexit
    //   37: athrow
    //   38: aload_0
    //   39: getfield 63	org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry$ZipBundleEntryInputStream:this$0	Lorg/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry;
    //   42: getfield 60	org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry:bundleFile	Lorg/eclipse/osgi/baseadaptor/bundlefile/ZipBundleFile;
    //   45: invokevirtual 74	org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleFile:decrementReference	()V
    //   48: aload_1
    //   49: athrow
    //   50: aload_0
    //   51: dup
    //   52: astore_2
    //   53: monitorenter
    //   54: aload_0
    //   55: getfield 61	org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry$ZipBundleEntryInputStream:closed	Z
    //   58: ifeq +6 -> 64
    //   61: aload_2
    //   62: monitorexit
    //   63: return
    //   64: aload_0
    //   65: iconst_1
    //   66: putfield 61	org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry$ZipBundleEntryInputStream:closed	Z
    //   69: aload_2
    //   70: monitorexit
    //   71: goto +6 -> 77
    //   74: aload_2
    //   75: monitorexit
    //   76: athrow
    //   77: aload_0
    //   78: getfield 63	org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry$ZipBundleEntryInputStream:this$0	Lorg/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry;
    //   81: getfield 60	org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry:bundleFile	Lorg/eclipse/osgi/baseadaptor/bundlefile/ZipBundleFile;
    //   84: invokevirtual 74	org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleFile:decrementReference	()V
    //   87: return
    // Line number table:
    //   Java source line #133	-> byte code offset #0
    //   Java source line #134	-> byte code offset #7
    //   Java source line #135	-> byte code offset #11
    //   Java source line #136	-> byte code offset #15
    //   Java source line #137	-> byte code offset #22
    //   Java source line #138	-> byte code offset #25
    //   Java source line #135	-> byte code offset #30
    //   Java source line #140	-> byte code offset #38
    //   Java source line #141	-> byte code offset #48
    //   Java source line #135	-> byte code offset #50
    //   Java source line #136	-> byte code offset #54
    //   Java source line #137	-> byte code offset #61
    //   Java source line #138	-> byte code offset #64
    //   Java source line #135	-> byte code offset #69
    //   Java source line #140	-> byte code offset #77
    //   Java source line #142	-> byte code offset #87
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	88	0	this	ZipBundleEntryInputStream
    //   10	39	1	localObject1	Object
    // Exception table:
    //   from	to	target	type
    //   0	10	10	finally
    //   15	24	35	finally
    //   25	32	35	finally
    //   35	37	35	finally
    //   54	63	74	finally
    //   64	71	74	finally
    //   74	76	74	finally
  }
  
  public void mark(int var0)
  {
    stream.mark(var0);
  }
  
  public boolean markSupported()
  {
    return stream.markSupported();
  }
  
  public int read()
    throws IOException
  {
    return stream.read();
  }
  
  public int read(byte[] var0, int var1, int var2)
    throws IOException
  {
    return stream.read(var0, var1, var2);
  }
  
  public int read(byte[] var0)
    throws IOException
  {
    return stream.read(var0);
  }
  
  public void reset()
    throws IOException
  {
    stream.reset();
  }
  
  public long skip(long var0)
    throws IOException
  {
    return stream.skip(var0);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.baseadaptor.bundlefile.ZipBundleEntry.ZipBundleEntryInputStream
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.baseadaptor.bundlefile;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class ZipBundleEntry
  extends BundleEntry
{
  protected final ZipEntry zipEntry;
  protected final ZipBundleFile bundleFile;
  
  ZipBundleEntry(ZipEntry zipEntry, ZipBundleFile bundleFile)
  {
    this.zipEntry = zipEntry;
    this.bundleFile = bundleFile;
  }
  
  public InputStream getInputStream()
    throws IOException
  {
    ZipBundleFile zipBundleFile = bundleFile;
    if (!zipBundleFile.isMruEnabled()) {
      return bundleFile.getZipFile().getInputStream(zipEntry);
    }
    zipBundleFile.incrementReference();
    InputStream result = null;
    try
    {
      return result = new ZipBundleEntryInputStream(zipBundleFile.getZipFile().getInputStream(zipEntry));
    }
    finally
    {
      if (result == null) {
        zipBundleFile.decrementReference();
      }
    }
  }
  
  public long getSize()
  {
    return zipEntry.getSize();
  }
  
  public String getName()
  {
    return zipEntry.getName();
  }
  
  public long getTime()
  {
    return zipEntry.getTime();
  }
  
  public URL getLocalURL()
  {
    try
    {
      return new URL("jar:" + bundleFile.basefile.toURL() + "!/" + zipEntry.getName());
    }
    catch (MalformedURLException localMalformedURLException) {}
    return null;
  }
  
  public URL getFileURL()
  {
    try
    {
      File file = bundleFile.getFile(zipEntry.getName(), false);
      if (file != null) {
        return file.toURL();
      }
    }
    catch (MalformedURLException localMalformedURLException) {}
    return null;
  }
  
  private class ZipBundleEntryInputStream
    extends InputStream
  {
    private final InputStream stream;
    private boolean closed = false;
    
    public ZipBundleEntryInputStream(InputStream stream)
    {
      this.stream = stream;
    }
    
    public int available()
      throws IOException
    {
      return stream.available();
    }
    
    /* Error */
    public void close()
      throws IOException
    {
      // Byte code:
      //   0: aload_0
      //   1: getfield 62	org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry$ZipBundleEntryInputStream:stream	Ljava/io/InputStream;
      //   4: invokevirtual 67	java/io/InputStream:close	()V
      //   7: goto +43 -> 50
      //   10: astore_1
      //   11: aload_0
      //   12: dup
      //   13: astore_2
      //   14: monitorenter
      //   15: aload_0
      //   16: getfield 61	org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry$ZipBundleEntryInputStream:closed	Z
      //   19: ifeq +6 -> 25
      //   22: aload_2
      //   23: monitorexit
      //   24: return
      //   25: aload_0
      //   26: iconst_1
      //   27: putfield 61	org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry$ZipBundleEntryInputStream:closed	Z
      //   30: aload_2
      //   31: monitorexit
      //   32: goto +6 -> 38
      //   35: aload_2
      //   36: monitorexit
      //   37: athrow
      //   38: aload_0
      //   39: getfield 63	org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry$ZipBundleEntryInputStream:this$0	Lorg/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry;
      //   42: getfield 60	org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry:bundleFile	Lorg/eclipse/osgi/baseadaptor/bundlefile/ZipBundleFile;
      //   45: invokevirtual 74	org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleFile:decrementReference	()V
      //   48: aload_1
      //   49: athrow
      //   50: aload_0
      //   51: dup
      //   52: astore_2
      //   53: monitorenter
      //   54: aload_0
      //   55: getfield 61	org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry$ZipBundleEntryInputStream:closed	Z
      //   58: ifeq +6 -> 64
      //   61: aload_2
      //   62: monitorexit
      //   63: return
      //   64: aload_0
      //   65: iconst_1
      //   66: putfield 61	org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry$ZipBundleEntryInputStream:closed	Z
      //   69: aload_2
      //   70: monitorexit
      //   71: goto +6 -> 77
      //   74: aload_2
      //   75: monitorexit
      //   76: athrow
      //   77: aload_0
      //   78: getfield 63	org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry$ZipBundleEntryInputStream:this$0	Lorg/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry;
      //   81: getfield 60	org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry:bundleFile	Lorg/eclipse/osgi/baseadaptor/bundlefile/ZipBundleFile;
      //   84: invokevirtual 74	org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleFile:decrementReference	()V
      //   87: return
      // Line number table:
      //   Java source line #133	-> byte code offset #0
      //   Java source line #134	-> byte code offset #7
      //   Java source line #135	-> byte code offset #11
      //   Java source line #136	-> byte code offset #15
      //   Java source line #137	-> byte code offset #22
      //   Java source line #138	-> byte code offset #25
      //   Java source line #135	-> byte code offset #30
      //   Java source line #140	-> byte code offset #38
      //   Java source line #141	-> byte code offset #48
      //   Java source line #135	-> byte code offset #50
      //   Java source line #136	-> byte code offset #54
      //   Java source line #137	-> byte code offset #61
      //   Java source line #138	-> byte code offset #64
      //   Java source line #135	-> byte code offset #69
      //   Java source line #140	-> byte code offset #77
      //   Java source line #142	-> byte code offset #87
      // Local variable table:
      //   start	length	slot	name	signature
      //   0	88	0	this	ZipBundleEntryInputStream
      //   10	39	1	localObject1	Object
      // Exception table:
      //   from	to	target	type
      //   0	10	10	finally
      //   15	24	35	finally
      //   25	32	35	finally
      //   35	37	35	finally
      //   54	63	74	finally
      //   64	71	74	finally
      //   74	76	74	finally
    }
    
    public void mark(int var0)
    {
      stream.mark(var0);
    }
    
    public boolean markSupported()
    {
      return stream.markSupported();
    }
    
    public int read()
      throws IOException
    {
      return stream.read();
    }
    
    public int read(byte[] var0, int var1, int var2)
      throws IOException
    {
      return stream.read(var0, var1, var2);
    }
    
    public int read(byte[] var0)
      throws IOException
    {
      return stream.read(var0);
    }
    
    public void reset()
      throws IOException
    {
      stream.reset();
    }
    
    public long skip(long var0)
      throws IOException
    {
      return stream.skip(var0);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.baseadaptor.bundlefile.ZipBundleEntry
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.baseadaptor.bundlefile;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.eclipse.osgi.baseadaptor.BaseAdaptor;
import org.eclipse.osgi.baseadaptor.BaseData;
import org.eclipse.osgi.framework.adaptor.EventPublisher;
import org.eclipse.osgi.framework.debug.Debug;
import org.eclipse.osgi.framework.util.SecureAction;
import org.eclipse.osgi.internal.baseadaptor.AdaptorMsg;
import org.eclipse.osgi.internal.baseadaptor.AdaptorUtil;
import org.eclipse.osgi.util.NLS;

public class ZipBundleFile
  extends BundleFile
{
  private final MRUBundleFileList mruList;
  protected BaseData bundledata;
  protected volatile ZipFile zipFile;
  protected volatile boolean closed = true;
  private int referenceCount = 0;
  
  public ZipBundleFile(File basefile, BaseData bundledata)
    throws IOException
  {
    this(basefile, bundledata, null);
  }
  
  public ZipBundleFile(File basefile, BaseData bundledata, MRUBundleFileList mruList)
    throws IOException
  {
    super(basefile);
    if (!BundleFile.secureAction.exists(basefile)) {
      throw new IOException(NLS.bind(AdaptorMsg.ADAPTER_FILEEXIST_EXCEPTION, basefile));
    }
    this.bundledata = bundledata;
    closed = true;
    this.mruList = mruList;
  }
  
  protected boolean checkedOpen()
  {
    try
    {
      return getZipFile() != null;
    }
    catch (IOException e)
    {
      if (bundledata != null) {
        bundledata.getAdaptor().getEventPublisher().publishFrameworkEvent(2, bundledata.getBundle(), e);
      }
    }
    return false;
  }
  
  protected ZipFile basicOpen()
    throws IOException
  {
    return BundleFile.secureAction.getZipFile(basefile);
  }
  
  protected synchronized ZipFile getZipFile()
    throws IOException
  {
    if (closed)
    {
      mruListAdd();
      zipFile = basicOpen();
      closed = false;
    }
    else
    {
      mruListUse();
    }
    return zipFile;
  }
  
  protected ZipEntry getZipEntry(String path)
  {
    if ((path.length() > 0) && (path.charAt(0) == '/')) {
      path = path.substring(1);
    }
    ZipEntry entry = zipFile.getEntry(path);
    if ((entry != null) && (entry.getSize() == 0L) && (!entry.isDirectory()))
    {
      ZipEntry dirEntry = zipFile.getEntry(path + '/');
      if (dirEntry != null) {
        entry = dirEntry;
      }
    }
    return entry;
  }
  
  protected synchronized File extractDirectory(String dirName)
  {
    if (!checkedOpen()) {
      return null;
    }
    Enumeration<? extends ZipEntry> entries = zipFile.entries();
    while (entries.hasMoreElements())
    {
      String entryPath = ((ZipEntry)entries.nextElement()).getName();
      if ((entryPath.startsWith(dirName)) && (!entryPath.endsWith("/"))) {
        getFile(entryPath, false);
      }
    }
    return getExtractFile(dirName);
  }
  
  protected File getExtractFile(String entryName)
  {
    if (bundledata == null) {
      return null;
    }
    String path = ".cp";
    String name = entryName.replace('/', File.separatorChar);
    if ((name.length() > 1) && (name.charAt(0) == File.separatorChar)) {
      path = path.concat(name);
    } else {
      path = path + File.separator + name;
    }
    return bundledata.getExtractFile(path);
  }
  
  public synchronized File getFile(String entry, boolean nativeCode)
  {
    if (!checkedOpen()) {
      return null;
    }
    ZipEntry zipEntry = getZipEntry(entry);
    if (zipEntry == null) {
      return null;
    }
    try
    {
      File nested = getExtractFile(zipEntry.getName());
      if (nested != null)
      {
        if (nested.exists())
        {
          if (Debug.DEBUG_GENERAL) {
            Debug.println("File already present: " + nested.getPath());
          }
          if (nested.isDirectory()) {
            extractDirectory(zipEntry.getName());
          }
        }
        else if (zipEntry.getName().endsWith("/"))
        {
          if (!nested.mkdirs())
          {
            if (Debug.DEBUG_GENERAL) {
              Debug.println("Unable to create directory: " + nested.getPath());
            }
            throw new IOException(NLS.bind(AdaptorMsg.ADAPTOR_DIRECTORY_CREATE_EXCEPTION, nested.getAbsolutePath()));
          }
          extractDirectory(zipEntry.getName());
        }
        else
        {
          InputStream in = zipFile.getInputStream(zipEntry);
          if (in == null) {
            return null;
          }
   
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd