Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Copyright (c) 2010-2011 Oracle and/or its affiliates. All rights reserved.
   * The contents of this file are subject to the terms of either the GNU
   * General Public License Version 2 only ("GPL") or the Common Development
   * and Distribution License("CDDL") (collectively, the "License").  You
   * may not use this file except in compliance with the License.  You can
  * obtain a copy of the License at
  * or packager/legal/LICENSE.txt.  See the License for the specific
  * language governing permissions and limitations under the License.
  * When distributing the software, include this License Header Notice in each
  * file and include the License file at packager/legal/LICENSE.txt.
  * GPL Classpath Exception:
  * Oracle designates this particular file as subject to the "Classpath"
  * exception as provided by Oracle in the GPL Version 2 section of the License
  * file that accompanied this code.
  * Modifications:
  * If applicable, add the following below the License Header, with the fields
  * enclosed by brackets [] replaced by your own identifying information:
  * "Portions Copyright [year] [name of copyright owner]"
  * Contributor(s):
  * If you wish your version of this file to be governed by only the CDDL or
  * only the GPL Version 2, indicate your decision by adding "[Contributor]
  * elects to include this software in this distribution under the [CDDL or GPL
  * Version 2] license."  If you don't indicate a single choice of license, a
  * recipient has the option to distribute your version of this file under
  * either the CDDL, the GPL Version 2 or to extend the choice of license to
  * its licensees as provided above.  However, if you add GPL Version 2 code
  * and therefore, elected the GPL Version 2 license, then the option applies
  * only if the new code is made subject to such option by the copyright
  * holder.
 package com.sun.jersey.core.spi.scanning.uri;
 import java.util.Set;

A "jar" and "zip" scheme URI scanner that recursively jar files. Jar entries are reported to a com.sun.jersey.core.spi.scanning.ScannerListener.

 public class JarZipSchemeScanner implements UriSchemeScanner {
     public Set<StringgetSchemes() {
         return new HashSet<String>(Arrays.asList("jar""zip"));
     public void scan(final URI ufinal ScannerListener cfl) {
         final String ssp = u.getRawSchemeSpecificPart();
         final String jarUrlString = ssp.substring(0, ssp.lastIndexOf('!'));
         final String parent = ssp.substring(ssp.lastIndexOf('!') + 2);
         try {
             closing(jarUrlString).f(new Closing.Closure() {
                 public void f(final InputStream inthrows IOException {
         } catch (IOException ex) {
             throw new ScannerException("IO error when scanning jar " + uex);

Obtain a com.sun.jersey.core.util.Closing of the jar file.

For most platforms the format for the zip or jar follows the form of the

  • jar:file:///tmp/!/example.txt
  • zip:!/example.txt

On versions of the WebLogic application server a proprietary format is supported of the following form, which assumes a zip file located on the local file system:

  • zip:/tmp/!/example.txt
  • zip:d:/!/example.txt

This method will first attempt to create a com.sun.jersey.core.util.Closing as follows:

   new Closing(new URL(jarUrlString).openStream());
if that fails with a then the method will attempt to create a com.sun.jersey.core.util.Closing instance as follows:
  return new Closing(new FileInputStream(
      UriComponent.decode(jarUrlString, UriComponent.Type.PATH)));

jarUrlString the raw scheme specific part of a URI minus the jar entry
a com.sun.jersey.core.util.Closing.
Throws: if there is an error opening the stream.
    protected Closing closing(String jarUrlStringthrows IOException {
        try {
            return new Closing(new URL(jarUrlString).openStream());
        } catch (MalformedURLException ex) {
            return new Closing(new FileInputStream(
New to GrepCode? Check out our FAQ X