jetty-util-8.1.0.v20120127

16:37:35.237 INFO  jd.cli.Main - Decompiling jetty-util-8.1.0.v20120127.jar
package org.eclipse.jetty.util;

import java.io.IOException;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;

public class QuotedStringTokenizer
  extends StringTokenizer
{
  private static final String __delim = "\t\n\r";
  private String _string;
  private String _delim = "\t\n\r";
  private boolean _returnQuotes = false;
  private boolean _returnDelimiters = false;
  private StringBuffer _token;
  private boolean _hasToken = false;
  private int _i = 0;
  private int _lastStart = 0;
  private boolean _double = true;
  private boolean _single = true;
  
  public QuotedStringTokenizer(String str, String delim, boolean returnDelimiters, boolean returnQuotes)
  {
    super("");
    _string = str;
    if (delim != null) {
      _delim = delim;
    }
    _returnDelimiters = returnDelimiters;
    _returnQuotes = returnQuotes;
    if ((_delim.indexOf('\'') >= 0) || (_delim.indexOf('"') >= 0)) {
      throw new Error("Can't use quotes as delimiters: " + _delim);
    }
    _token = new StringBuffer(_string.length() > 1024 ? 512 : _string.length() / 2);
  }
  
  public QuotedStringTokenizer(String str, String delim, boolean returnDelimiters)
  {
    this(str, delim, returnDelimiters, false);
  }
  
  public QuotedStringTokenizer(String str, String delim)
  {
    this(str, delim, false, false);
  }
  
  public QuotedStringTokenizer(String str)
  {
    this(str, null, false, false);
  }
  
  public boolean hasMoreTokens()
  {
    if (_hasToken) {
      return true;
    }
    _lastStart = _i;
    
    int state = 0;
    boolean escape = false;
    while (_i < _string.length())
    {
      char c = _string.charAt(_i++);
      switch (state)
      {
      case 0: 
        if (_delim.indexOf(c) >= 0)
        {
          if (_returnDelimiters)
          {
            _token.append(c);
            return _hasToken = 1;
          }
        }
        else if ((c == '\'') && (_single))
        {
          if (_returnQuotes) {
            _token.append(c);
          }
          state = 2;
        }
        else if ((c == '"') && (_double))
        {
          if (_returnQuotes) {
            _token.append(c);
          }
          state = 3;
        }
        else
        {
          _token.append(c);
          _hasToken = true;
          state = 1;
        }
        break;
      case 1: 
        _hasToken = true;
        if (_delim.indexOf(c) >= 0)
        {
          if (_returnDelimiters) {
            _i -= 1;
          }
          return _hasToken;
        }
        if ((c == '\'') && (_single))
        {
          if (_returnQuotes) {
            _token.append(c);
          }
          state = 2;
        }
        else if ((c == '"') && (_double))
        {
          if (_returnQuotes) {
            _token.append(c);
          }
          state = 3;
        }
        else
        {
          _token.append(c);
        }
        break;
      case 2: 
        _hasToken = true;
        if (escape)
        {
          escape = false;
          _token.append(c);
        }
        else if (c == '\'')
        {
          if (_returnQuotes) {
            _token.append(c);
          }
          state = 1;
        }
        else if (c == '\\')
        {
          if (_returnQuotes) {
            _token.append(c);
          }
          escape = true;
        }
        else
        {
          _token.append(c);
        }
        break;
      case 3: 
        _hasToken = true;
        if (escape)
        {
          escape = false;
          _token.append(c);
        }
        else if (c == '"')
        {
          if (_returnQuotes) {
            _token.append(c);
          }
          state = 1;
        }
        else if (c == '\\')
        {
          if (_returnQuotes) {
            _token.append(c);
          }
          escape = true;
        }
        else
        {
          _token.append(c);
        }
        break;
      }
    }
    return _hasToken;
  }
  
  public String nextToken()
    throws NoSuchElementException
  {
    if ((!hasMoreTokens()) || (_token == null)) {
      throw new NoSuchElementException();
    }
    String t = _token.toString();
    _token.setLength(0);
    _hasToken = false;
    return t;
  }
  
  public String nextToken(String delim)
    throws NoSuchElementException
  {
    _delim = delim;
    _i = _lastStart;
    _token.setLength(0);
    _hasToken = false;
    return nextToken();
  }
  
  public boolean hasMoreElements()
  {
    return hasMoreTokens();
  }
  
  public Object nextElement()
    throws NoSuchElementException
  {
    return nextToken();
  }
  
  public int countTokens()
  {
    return -1;
  }
  
  public static String quoteIfNeeded(String s, String delim)
  {
    if (s == null) {
      return null;
    }
    if (s.length() == 0) {
      return "\"\"";
    }
    for (int i = 0; i < s.length(); i++)
    {
      char c = s.charAt(i);
      if ((c == '\\') || (c == '"') || (c == '\'') || (Character.isWhitespace(c)) || (delim.indexOf(c) >= 0))
      {
        StringBuffer b = new StringBuffer(s.length() + 8);
        quote(b, s);
        return b.toString();
      }
    }
    return s;
  }
  
  public static String quote(String s)
  {
    if (s == null) {
      return null;
    }
    if (s.length() == 0) {
      return "\"\"";
    }
    StringBuffer b = new StringBuffer(s.length() + 8);
    quote(b, s);
    return b.toString();
  }
  
  private static final char[] escapes = new char[32];
  
  static
  {
    Arrays.fill(escapes, 65535);
    escapes[8] = 'b';
    escapes[9] = 't';
    escapes[10] = 'n';
    escapes[12] = 'f';
    escapes[13] = 'r';
  }
  
  public static void quote(Appendable buffer, String input)
  {
    try
    {
      buffer.append('"');
      for (int i = 0; i < input.length(); i++)
      {
        char c = input.charAt(i);
        if (c >= ' ')
        {
          if ((c == '"') || (c == '\\')) {
            buffer.append('\\');
          }
          buffer.append(c);
        }
        else
        {
          char escape = escapes[c];
          if (escape == 65535)
          {
            buffer.append('\\').append('u').append('0').append('0');
            if (c < '\020') {
              buffer.append('0');
            }
            buffer.append(Integer.toString(c, 16));
          }
          else
          {
            buffer.append('\\').append(escape);
          }
        }
      }
      buffer.append('"');
    }
    catch (IOException x)
    {
      throw new RuntimeException(x);
    }
  }
  
  public static boolean quoteIfNeeded(Appendable buf, String s, String delim)
  {
    for (int i = 0; i < s.length(); i++)
    {
      char c = s.charAt(i);
      if (delim.indexOf(c) >= 0)
      {
        quote(buf, s);
        return true;
      }
    }
    try
    {
      buf.append(s);
      return false;
    }
    catch (IOException e)
    {
      throw new RuntimeException(e);
    }
  }
  
  public static String unquote(String s)
  {
    if (s == null) {
      return null;
    }
    if (s.length() < 2) {
      return s;
    }
    char first = s.charAt(0);
    char last = s.charAt(s.length() - 1);
    if ((first != last) || ((first != '"') && (first != '\''))) {
      return s;
    }
    StringBuilder b = new StringBuilder(s.length() - 2);
    boolean escape = false;
    for (int i = 1; i < s.length() - 1; i++)
    {
      char c = s.charAt(i);
      if (escape)
      {
        escape = false;
        switch (c)
        {
        case 'n': 
          b.append('\n');
          break;
        case 'r': 
          b.append('\r');
          break;
        case 't': 
          b.append('\t');
          break;
        case 'f': 
          b.append('\f');
          break;
        case 'b': 
          b.append('\b');
          break;
        case '\\': 
          b.append('\\');
          break;
        case '/': 
          b.append('/');
          break;
        case '"': 
          b.append('"');
          break;
        case 'u': 
          b.append((char)((TypeUtil.convertHexDigit((byte)s.charAt(i++)) << 24) + (TypeUtil.convertHexDigit((byte)s.charAt(i++)) << 16) + (TypeUtil.convertHexDigit((byte)s.charAt(i++)) << 8) + TypeUtil.convertHexDigit((byte)s.charAt(i++))));
          
          break;
        default: 
          b.append(c);break;
        }
      }
      else if (c == '\\')
      {
        escape = true;
      }
      else
      {
        b.append(c);
      }
    }
    return b.toString();
  }
  
  public boolean getDouble()
  {
    return _double;
  }
  
  public void setDouble(boolean d)
  {
    _double = d;
  }
  
  public boolean getSingle()
  {
    return _single;
  }
  
  public void setSingle(boolean single)
  {
    _single = single;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.util.QuotedStringTokenizer
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.util;

class IO$1 {}

/* Location:
 * Qualified Name:     org.eclipse.jetty.util.IO.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.util.resource;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.StringTokenizer;

public class ResourceCollection
  extends Resource
{
  private Resource[] _resources;
  
  public ResourceCollection()
  {
    _resources = new Resource[0];
  }
  
  public ResourceCollection(Resource... resources)
  {
    List<Resource> list = new ArrayList();
    for (Resource r : resources) {
      if (r != null) {
        if ((r instanceof ResourceCollection)) {
          for (Resource r2 : ((ResourceCollection)r).getResources()) {
            list.add(r2);
          }
        } else {
          list.add(r);
        }
      }
    }
    _resources = ((Resource[])list.toArray(new Resource[list.size()]));
    for (Resource r : _resources) {
      if ((!r.exists()) || (!r.isDirectory())) {
        throw new IllegalArgumentException(r + " is not an existing directory.");
      }
    }
  }
  
  public ResourceCollection(String[] resources)
  {
    _resources = new Resource[resources.length];
    try
    {
      for (int i = 0; i < resources.length; i++)
      {
        _resources[i] = Resource.newResource(resources[i]);
        if ((!_resources[i].exists()) || (!_resources[i].isDirectory())) {
          throw new IllegalArgumentException(_resources[i] + " is not an existing directory.");
        }
      }
    }
    catch (IllegalArgumentException e)
    {
      throw e;
    }
    catch (Exception e)
    {
      throw new RuntimeException(e);
    }
  }
  
  public ResourceCollection(String csvResources)
  {
    setResourcesAsCSV(csvResources);
  }
  
  public Resource[] getResources()
  {
    return _resources;
  }
  
  public void setResources(Resource[] resources)
  {
    _resources = (resources != null ? resources : new Resource[0]);
  }
  
  public void setResourcesAsCSV(String csvResources)
  {
    StringTokenizer tokenizer = new StringTokenizer(csvResources, ",;");
    int len = tokenizer.countTokens();
    if (len == 0) {
      throw new IllegalArgumentException("ResourceCollection@setResourcesAsCSV(String)  argument must be a string containing one or more comma-separated resource strings.");
    }
    _resources = new Resource[len];
    try
    {
      for (int i = 0; tokenizer.hasMoreTokens(); i++)
      {
        _resources[i] = Resource.newResource(tokenizer.nextToken().trim());
        if ((!_resources[i].exists()) || (!_resources[i].isDirectory())) {
          throw new IllegalArgumentException(_resources[i] + " is not an existing directory.");
        }
      }
    }
    catch (Exception e)
    {
      throw new RuntimeException(e);
    }
  }
  
  public Resource addPath(String path)
    throws IOException, MalformedURLException
  {
    if (_resources == null) {
      throw new IllegalStateException("*resources* not set.");
    }
    if (path == null) {
      throw new MalformedURLException();
    }
    if ((path.length() == 0) || ("/".equals(path))) {
      return this;
    }
    Resource resource = null;
    ArrayList<Resource> resources = null;
    for (int i = 0; i < _resources.length; i++)
    {
      resource = _resources[i].addPath(path);
      if (resource.exists())
      {
        if (resource.isDirectory()) {
          break;
        }
        return resource;
      }
    }
    for (i++; i < _resources.length; i++)
    {
      Resource r = _resources[i].addPath(path);
      if ((r.exists()) && (r.isDirectory()))
      {
        if (resource != null)
        {
          resources = new ArrayList();
          resources.add(resource);
          resource = null;
        }
        resources.add(r);
      }
    }
    if (resource != null) {
      return resource;
    }
    if (resources != null) {
      return new ResourceCollection((Resource[])resources.toArray(new Resource[resources.size()]));
    }
    return null;
  }
  
  protected Object findResource(String path)
    throws IOException, MalformedURLException
  {
    Resource resource = null;
    ArrayList<Resource> resources = null;
    for (int i = 0; i < _resources.length; i++)
    {
      resource = _resources[i].addPath(path);
      if (resource.exists())
      {
        if (resource.isDirectory()) {
          break;
        }
        return resource;
      }
    }
    for (i++; i < _resources.length; i++)
    {
      Resource r = _resources[i].addPath(path);
      if ((r.exists()) && (r.isDirectory()))
      {
        if (resource != null)
        {
          resources = new ArrayList();
          resources.add(resource);
        }
        resources.add(r);
      }
    }
    if (resource != null) {
      return resource;
    }
    if (resources != null) {
      return resources;
    }
    return null;
  }
  
  public boolean delete()
    throws SecurityException
  {
    throw new UnsupportedOperationException();
  }
  
  public boolean exists()
  {
    if (_resources == null) {
      throw new IllegalStateException("*resources* not set.");
    }
    return true;
  }
  
  public File getFile()
    throws IOException
  {
    if (_resources == null) {
      throw new IllegalStateException("*resources* not set.");
    }
    for (Resource r : _resources)
    {
      File f = r.getFile();
      if (f != null) {
        return f;
      }
    }
    return null;
  }
  
  public InputStream getInputStream()
    throws IOException
  {
    if (_resources == null) {
      throw new IllegalStateException("*resources* not set.");
    }
    for (Resource r : _resources)
    {
      InputStream is = r.getInputStream();
      if (is != null) {
        return is;
      }
    }
    return null;
  }
  
  public String getName()
  {
    if (_resources == null) {
      throw new IllegalStateException("*resources* not set.");
    }
    for (Resource r : _resources)
    {
      String name = r.getName();
      if (name != null) {
        return name;
      }
    }
    return null;
  }
  
  public OutputStream getOutputStream()
    throws IOException, SecurityException
  {
    if (_resources == null) {
      throw new IllegalStateException("*resources* not set.");
    }
    for (Resource r : _resources)
    {
      OutputStream os = r.getOutputStream();
      if (os != null) {
        return os;
      }
    }
    return null;
  }
  
  public URL getURL()
  {
    if (_resources == null) {
      throw new IllegalStateException("*resources* not set.");
    }
    for (Resource r : _resources)
    {
      URL url = r.getURL();
      if (url != null) {
        return url;
      }
    }
    return null;
  }
  
  public boolean isDirectory()
  {
    if (_resources == null) {
      throw new IllegalStateException("*resources* not set.");
    }
    return true;
  }
  
  public long lastModified()
  {
    if (_resources == null) {
      throw new IllegalStateException("*resources* not set.");
    }
    for (Resource r : _resources)
    {
      long lm = r.lastModified();
      if (lm != -1L) {
        return lm;
      }
    }
    return -1L;
  }
  
  public long length()
  {
    return -1L;
  }
  
  public String[] list()
  {
    if (_resources == null) {
      throw new IllegalStateException("*resources* not set.");
    }
    HashSet<String> set = new HashSet();
    for (Resource r : _resources) {
      for (String s : r.list()) {
        set.add(s);
      }
    }
    String[] result = (String[])set.toArray(new String[set.size()]);
    Arrays.sort(result);
    return result;
  }
  
  public void release()
  {
    if (_resources == null) {
      throw new IllegalStateException("*resources* not set.");
    }
    for (Resource r : _resources) {
      r.release();
    }
  }
  
  public boolean renameTo(Resource dest)
    throws SecurityException
  {
    throw new UnsupportedOperationException();
  }
  
  public void copyTo(File destination)
    throws IOException
  {
    for (int r = _resources.length; r-- > 0;) {
      _resources[r].copyTo(destination);
    }
  }
  
  public String toString()
  {
    if (_resources == null) {
      return "[]";
    }
    return String.valueOf(Arrays.asList(_resources));
  }
  
  public boolean isContainedIn(Resource r)
    throws MalformedURLException
  {
    return false;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.util.resource.ResourceCollection
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.util.resource;

public abstract interface ResourceFactory
{
  public abstract Resource getResource(String paramString);
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.util.resource.ResourceFactory
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.util.resource;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.security.Permission;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;

public class FileResource
  extends URLResource
{
  private static final Logger LOG = Log.getLogger(FileResource.class);
  private static boolean __checkAliases = true;
  private File _file;
  private transient URL _alias = null;
  private transient boolean _aliasChecked = false;
  
  public static void setCheckAliases(boolean checkAliases)
  {
    __checkAliases = checkAliases;
  }
  
  public static boolean getCheckAliases()
  {
    return __checkAliases;
  }
  
  public FileResource(URL url)
    throws IOException, URISyntaxException
  {
    super(url, null);
    try
    {
      _file = new File(new URI(url.toString()));
    }
    catch (Exception e)
    {
      LOG.ignore(e);
      try
      {
        String file_url = "file:" + URIUtil.encodePath(url.toString().substring(5));
        URI uri = new URI(file_url);
        if (uri.getAuthority() == null) {
          _file = new File(uri);
        } else {
          _file = new File("//" + uri.getAuthority() + URIUtil.decodePath(url.getFile()));
        }
      }
      catch (Exception e2)
      {
        LOG.ignore(e2);
        
        checkConnection();
        Permission perm = _connection.getPermission();
        _file = new File(perm == null ? url.getFile() : perm.getName());
      }
    }
    if (_file.isDirectory())
    {
      if (!_urlString.endsWith("/")) {
        _urlString += "/";
      }
    }
    else if (_urlString.endsWith("/")) {
      _urlString = _urlString.substring(0, _urlString.length() - 1);
    }
  }
  
  FileResource(URL url, URLConnection connection, File file)
  {
    super(url, connection);
    _file = file;
    if ((_file.isDirectory()) && (!_urlString.endsWith("/"))) {
      _urlString += "/";
    }
  }
  
  public Resource addPath(String path)
    throws IOException, MalformedURLException
  {
    URLResource r = null;
    String url = null;
    
    path = URIUtil.canonicalPath(path);
    if ("/".equals(path)) {
      return this;
    }
    if (!isDirectory())
    {
      r = (FileResource)super.addPath(path);
      url = _urlString;
    }
    else
    {
      if (path == null) {
        throw new MalformedURLException();
      }
      String rel = path;
      if (path.startsWith("/")) {
        rel = path.substring(1);
      }
      url = URIUtil.addPaths(_urlString, URIUtil.encodePath(rel));
      r = (URLResource)Resource.newResource(url);
    }
    String encoded = URIUtil.encodePath(path);
    int expected = r.toString().length() - encoded.length();
    int index = _urlString.lastIndexOf(encoded, expected);
    if ((expected != index) && ((expected - 1 != index) || (path.endsWith("/")) || (!r.isDirectory()))) {
      if (!(r instanceof BadResource))
      {
        _alias = new URL(url);
        _aliasChecked = true;
      }
    }
    return r;
  }
  
  public URL getAlias()
  {
    if ((__checkAliases) && (!_aliasChecked)) {
      try
      {
        String abs = _file.getAbsolutePath();
        String can = _file.getCanonicalPath();
        if ((abs.length() != can.length()) || (!abs.equals(can))) {
          _alias = Resource.toURL(new File(can));
        }
        _aliasChecked = true;
        if ((_alias != null) && (LOG.isDebugEnabled()))
        {
          LOG.debug("ALIAS abs=" + abs, new Object[0]);
          LOG.debug("ALIAS can=" + can, new Object[0]);
        }
      }
      catch (Exception e)
      {
        LOG.warn("EXCEPTION ", e);
        return getURL();
      }
    }
    return _alias;
  }
  
  public boolean exists()
  {
    return _file.exists();
  }
  
  public long lastModified()
  {
    return _file.lastModified();
  }
  
  public boolean isDirectory()
  {
    return _file.isDirectory();
  }
  
  public long length()
  {
    return _file.length();
  }
  
  public String getName()
  {
    return _file.getAbsolutePath();
  }
  
  public File getFile()
  {
    return _file;
  }
  
  public InputStream getInputStream()
    throws IOException
  {
    return new FileInputStream(_file);
  }
  
  public OutputStream getOutputStream()
    throws IOException, SecurityException
  {
    return new FileOutputStream(_file);
  }
  
  public boolean delete()
    throws SecurityException
  {
    return _file.delete();
  }
  
  public boolean renameTo(Resource dest)
    throws SecurityException
  {
    if ((dest instanceof FileResource)) {
      return _file.renameTo(_file);
    }
    return false;
  }
  
  public String[] list()
  {
    String[] list = _file.list();
    if (list == null) {
      return null;
    }
    for (int i = list.length; i-- > 0; tmp64_62[tmp64_63] = (tmp64_62[tmp64_63] + "/")) {
      label17:
      if ((!new File(_file, list[i]).isDirectory()) || (list[i].endsWith("/"))) {
        break label17;
      }
    }
    return list;
  }
  
  public String encode(String uri)
  {
    return uri;
  }
  
  public boolean equals(Object o)
  {
    if (this == o) {
      return true;
    }
    if ((null == o) || (!(o instanceof FileResource))) {
      return false;
    }
    FileResource f = (FileResource)o;
    return (_file == _file) || ((null != _file) && (_file.equals(_file)));
  }
  
  public int hashCode()
  {
    return null == _file ? super.hashCode() : _file.hashCode();
  }
  
  public void copyTo(File destination)
    throws IOException
  {
    if (isDirectory())
    {
      IO.copyDir(getFile(), destination);
    }
    else
    {
      if (destination.exists()) {
        throw new IllegalArgumentException(destination + " exists");
      }
      IO.copy(getFile(), destination);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.util.resource.FileResource
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.util.resource;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.JarURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
import java.util.jar.Manifest;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;

public class JarResource
  extends URLResource
{
  private static final Logger LOG = Log.getLogger(JarResource.class);
  protected JarURLConnection _jarConnection;
  
  JarResource(URL url)
  {
    super(url, null);
  }
  
  JarResource(URL url, boolean useCaches)
  {
    super(url, null, useCaches);
  }
  
  public synchronized void release()
  {
    _jarConnection = null;
    super.release();
  }
  
  protected synchronized boolean checkConnection()
  {
    super.checkConnection();
    try
    {
      if (_jarConnection != _connection) {
        newConnection();
      }
    }
    catch (IOException e)
    {
      LOG.ignore(e);
      _jarConnection = null;
    }
    return _jarConnection != null;
  }
  
  protected void newConnection()
    throws IOException
  {
    _jarConnection = ((JarURLConnection)_connection);
  }
  
  public boolean exists()
  {
    if (_urlString.endsWith("!/")) {
      return checkConnection();
    }
    return super.exists();
  }
  
  public File getFile()
    throws IOException
  {
    return null;
  }
  
  public InputStream getInputStream()
    throws IOException
  {
    checkConnection();
    if (!_urlString.endsWith("!/")) {
      new FilterInputStream(super.getInputStream())
      {
        public void close()
          throws IOException
        {
          in = IO.getClosedStream();
        }
      };
    }
    URL url = new URL(_urlString.substring(4, _urlString.length() - 2));
    InputStream is = url.openStream();
    return is;
  }
  
  public void copyTo(File directory)
    throws IOException
  {
    if (!exists()) {
      return;
    }
    if (LOG.isDebugEnabled()) {
      LOG.debug("Extract " + this + " to " + directory, new Object[0]);
    }
    String urlString = getURL().toExternalForm().trim();
    int endOfJarUrl = urlString.indexOf("!/");
    int startOfJarUrl = endOfJarUrl >= 0 ? 4 : 0;
    if (endOfJarUrl < 0) {
      throw new IOException("Not a valid jar url: " + urlString);
    }
    URL jarFileURL = new URL(urlString.substring(startOfJarUrl, endOfJarUrl));
    String subEntryName = endOfJarUrl + 2 < urlString.length() ? urlString.substring(endOfJarUrl + 2) : null;
    boolean subEntryIsDir = (subEntryName != null) && (subEntryName.endsWith("/"));
    if (LOG.isDebugEnabled()) {
      LOG.debug("Extracting entry = " + subEntryName + " from jar " + jarFileURL, new Object[0]);
    }
    InputStream is = jarFileURL.openConnection().getInputStream();
    JarInputStream jin = new JarInputStream(is);
    JarEntry entry;
    while ((entry = jin.getNextJarEntry()) != null)
    {
      String entryName = entry.getName();
      boolean shouldExtract;
      boolean shouldExtract;
      if ((subEntryName != null) && (entryName.startsWith(subEntryName)))
      {
        if ((!subEntryIsDir) && (subEntryName.length() + 1 == entryName.length()) && (entryName.endsWith("/"))) {
          subEntryIsDir = true;
        }
        boolean shouldExtract;
        if (subEntryIsDir)
        {
          entryName = entryName.substring(subEntryName.length());
          boolean shouldExtract;
          if (!entryName.equals("")) {
            shouldExtract = true;
          } else {
            shouldExtract = false;
          }
        }
        else
        {
          shouldExtract = true;
        }
      }
      else
      {
        boolean shouldExtract;
        if ((subEntryName != null) && (!entryName.startsWith(subEntryName))) {
          shouldExtract = false;
        } else {
          shouldExtract = true;
        }
      }
      if (!shouldExtract)
      {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Skipping entry: " + entryName, new Object[0]);
        }
      }
      else
      {
        String dotCheck = entryName.replace('\\', '/');
        dotCheck = URIUtil.canonicalPath(dotCheck);
        if (dotCheck == null)
        {
          if (LOG.isDebugEnabled()) {
            LOG.debug("Invalid entry: " + entryName, new Object[0]);
          }
        }
        else
        {
          File file = new File(directory, entryName);
          if (entry.isDirectory())
          {
            if (!file.exists()) {
              file.mkdirs();
            }
          }
          else
          {
            File dir = new File(file.getParent());
            if (!dir.exists()) {
              dir.mkdirs();
            }
            FileOutputStream fout = null;
            try
            {
              fout = new FileOutputStream(file);
              IO.copy(jin, fout);
            }
            finally
            {
              IO.close(fout);
            }
            if (entry.getTime() >= 0L) {
              file.setLastModified(entry.getTime());
            }
          }
        }
      }
    }
    if ((subEntryName == null) || ((subEntryName != null) && (subEntryName.equalsIgnoreCase("META-INF/MANIFEST.MF"))))
    {
      Manifest manifest = jin.getManifest();
      if (manifest != null)
      {
        File metaInf = new File(directory, "META-INF");
        metaInf.mkdir();
        File f = new File(metaInf, "MANIFEST.MF");
        FileOutputStream fout = new FileOutputStream(f);
        manifest.write(fout);
        fout.close();
      }
    }
    IO.close(jin);
  }
  
  public static Resource newJarResource(Resource resource)
    throws IOException
  {
    if ((resource instanceof JarResource)) {
      return resource;
    }
    return Resource.newResource("jar:" + resource + "!/");
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.util.resource.JarResource
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.util.resource;

import java.io.File;
import java.io.IOException;
import java.net.JarURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;

class JarFileResource
  extends JarResource
{
  private static final Logger LOG = Log.getLogger(JarFileResource.class);
  private JarFile _jarFile;
  private File _file;
  private String[] _list;
  private JarEntry _entry;
  private boolean _directory;
  private String _jarUrl;
  private String _path;
  private boolean _exists;
  
  JarFileResource(URL url)
  {
    super(url);
  }
  
  JarFileResource(URL url, boolean useCaches)
  {
    super(url, useCaches);
  }
  
  public synchronized void release()
  {
    _list = null;
    _entry = null;
    _file = null;
    _jarFile = null;
    super.release();
  }
  
  protected boolean checkConnection()
  {
    try
    {
      super.checkConnection();
    }
    finally
    {
      if (_jarConnection == null)
      {
        _entry = null;
        _file = null;
        _jarFile = null;
        _list = null;
      }
    }
    return _jarFile != null;
  }
  
  protected synchronized void newConnection()
    throws IOException
  {
    super.newConnection();
    
    _entry = null;
    _file = null;
    _jarFile = null;
    _list = null;
    
    int sep = _urlString.indexOf("!/");
    _jarUrl = _urlString.substring(0, sep + 2);
    _path = _urlString.substring(sep + 2);
    if (_path.length() == 0) {
      _path = null;
    }
    _jarFile = _jarConnection.getJarFile();
    _file = new File(_jarFile.getName());
  }
  
  public boolean exists()
  {
    if (_exists) {
      return true;
    }
    if (_urlString.endsWith("!/"))
    {
      String file_url = _urlString.substring(4, _urlString.length() - 2);
      try
      {
        return newResource(file_url).exists();
      }
      catch (Exception e)
      {
        LOG.ignore(e);return false;
      }
    }
    boolean check = checkConnection();
    if ((_jarUrl != null) && (_path == null))
    {
      _directory = check;
      return true;
    }
    JarFile jarFile = null;
    if (check) {
      jarFile = _jarFile;
    } else {
      try
      {
        JarURLConnection c = (JarURLConnection)new URL(_jarUrl).openConnection();
        c.setUseCaches(getUseCaches());
        jarFile = c.getJarFile();
      }
      catch (Exception e)
      {
        LOG.ignore(e);
      }
    }
    if ((jarFile != null) && (_entry == null) && (!_directory))
    {
      Enumeration e = jarFile.entries();
      while (e.hasMoreElements())
      {
        JarEntry entry = (JarEntry)e.nextElement();
        String name = entry.getName().replace('\\', '/');
        if (name.equals(_path))
        {
          _entry = entry;
          
          _directory = _path.endsWith("/");
          break;
        }
        if (_path.endsWith("/"))
        {
          if (name.startsWith(_path))
          {
            _directory = true;
            break;
          }
        }
        else if ((name.startsWith(_path)) && (name.length() > _path.length()) && (name.charAt(_path.length()) == '/'))
        {
          _directory = true;
          break;
        }
      }
      if ((_directory) && (!_urlString.endsWith("/")))
      {
        _urlString += "/";
        try
        {
          _url = new URL(_urlString);
        }
        catch (MalformedURLException ex)
        {
          LOG.warn(ex);
        }
      }
    }
    _exists = ((_directory) || (_entry != null));
    return _exists;
  }
  
  public boolean isDirectory()
  {
    return (_urlString.endsWith("/")) || ((exists()) && (_directory));
  }
  
  public long lastModified()
  {
    if ((checkConnection()) && (_file != null)) {
      return _file.lastModified();
    }
    return -1L;
  }
  
  public synchronized String[] list()
  {
    if ((isDirectory()) && (_list == null))
    {
      ArrayList list = new ArrayList(32);
      
      checkConnection();
      
      JarFile jarFile = _jarFile;
      if (jarFile == null) {
        try
        {
          JarURLConnection jc = (JarURLConnection)new URL(_jarUrl).openConnection();
          jc.setUseCaches(getUseCaches());
          jarFile = jc.getJarFile();
        }
        catch (Exception e)
        {
          LOG.ignore(e);
        }
      }
      Enumeration e = jarFile.entries();
      String dir = _urlString.substring(_urlString.indexOf("!/") + 2);
      while (e.hasMoreElements())
      {
        JarEntry entry = (JarEntry)e.nextElement();
        String name = entry.getName().replace('\\', '/');
        if ((name.startsWith(dir)) && (name.length() != dir.length()))
        {
          String listName = name.substring(dir.length());
          int dash = listName.indexOf('/');
          if (dash >= 0)
          {
            if ((dash != 0) || (listName.length() != 1))
            {
              if (dash == 0) {
                listName = listName.substring(dash + 1, listName.length());
              } else {
                listName = listName.substring(0, dash + 1);
              }
              if (list.contains(listName)) {}
            }
          }
          else {
            list.add(listName);
          }
        }
      }
      _list = new String[list.size()];
      list.toArray(_list);
    }
    return _list;
  }
  
  public long length()
  {
    if (isDirectory()) {
      return -1L;
    }
    if (_entry != null) {
      return _entry.getSize();
    }
    return -1L;
  }
  
  public String encode(String uri)
  {
    return uri;
  }
  
  public static Resource getNonCachingResource(Resource resource)
  {
    if (!(resource instanceof JarFileResource)) {
      return resource;
    }
    JarFileResource oldResource = (JarFileResource)resource;
    
    JarFileResource newResource = new JarFileResource(oldResource.getURL(), false);
    return newResource;
  }
  
  public boolean isContainedIn(Resource resource)
    throws MalformedURLException
  {
    String string = _urlString;
    int index = string.indexOf("!/");
    if (index > 0) {
      string = string.substring(0, index);
    }
    if (string.startsWith("jar:")) {
      string = string.substring(4);
    }
    URL url = new URL(string);
    return url.sameFile(resource.getURL());
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.util.resource.JarFileResource
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.util.resource;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;

class BadResource
  extends URLResource
{
  private String _message = null;
  
  BadResource(URL url, String message)
  {
    super(url, null);
    _message = message;
  }
  
  public boolean exists()
  {
    return false;
  }
  
  public long lastModified()
  {
    return -1L;
  }
  
  public boolean isDirectory()
  {
    return false;
  }
  
  public long length()
  {
    return -1L;
  }
  
  public File getFile()
  {
    return null;
  }
  
  public InputStream getInputStream()
    throws IOException
  {
    throw new FileNotFoundException(_message);
  }
  
  public OutputStream getOutputStream()
    throws IOException, SecurityException
  {
    throw new FileNotFoundException(_message);
  }
  
  public boolean delete()
    throws SecurityException
  {
    throw new SecurityException(_message);
  }
  
  public boolean renameTo(Resource dest)
    throws SecurityException
  {
    throw new SecurityException(_message);
  }
  
  public String[] list()
  {
    return null;
  }
  
  public void copyTo(File destination)
    throws IOException
  {
    throw new SecurityException(_message);
  }
  
  public String toString()
  {
    return super.toString() + "; BadResource=" + _message;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.util.resource.BadResource
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.util.resource;

import java.io.File;
import java.io.FilePermission;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.security.Permission;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;

public class URLResource
  extends Resource
{
  private static final Logger LOG = Log.getLogger(URLResource.class);
  protected URL _url;
  protected String _urlString;
  protected URLConnection _connection;
  protected InputStream _in = null;
  transient boolean _useCaches = Resource.__defaultUseCaches;
  
  protected URLResource(URL url, URLConnection connection)
  {
    _url = url;
    _urlString = _url.toString();
    _connection = connection;
  }
  
  protected URLResource(URL url, URLConnection connection, boolean useCaches)
  {
    this(url, connection);
    _useCaches = useCaches;
  }
  
  protected synchronized boolean checkConnection()
  {
    if (_connection == null) {
      try
      {
        _connection = _url.openConnection();
        _connection.setUseCaches(_useCaches);
      }
      catch (IOException e)
      {
        LOG.ignore(e);
      }
    }
    return _connection != null;
  }
  
  public synchronized void release()
  {
    if (_in != null)
    {
      try
      {
        _in.close();
      }
      catch (IOException e)
      {
        LOG.ignore(e);
      }
      _in = null;
    }
    if (_connection != null) {
      _connection = null;
    }
  }
  
  public boole
1 2 3 4 5 6 7 8 9 10 11 12 13 14

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-2017. Infinite Loop Ltd