Java Code Examples for sun.net.www.ParseUtil#encodePath()

The following examples show how to use sun.net.www.ParseUtil#encodePath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppletClassLoader.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public Enumeration findResources(String name) throws IOException {

        final Enumeration e = super.findResources(name);

        // 6215746:  Disable META-INF/* lookup from codebase in
        // applet/plugin classloader. [stanley.ho]
        if (name.startsWith("META-INF/"))
            return e;

        // 4668479: Option to turn off codebase lookup in AppletClassLoader
        // during resource requests. [stanley.ho]
        if (codebaseLookup == false)
            return e;

        URL u = new URL(base, ParseUtil.encodePath(name, false));
        if (!resourceExists(u)) {
            u = null;
        }

        final URL url = u;
        return new Enumeration() {
            private boolean done;
            public Object nextElement() {
                if (!done) {
                    if (e.hasMoreElements()) {
                        return e.nextElement();
                    }
                    done = true;
                    if (url != null) {
                        return url;
                    }
                }
                throw new NoSuchElementException();
            }
            public boolean hasMoreElements() {
                return !done && (e.hasMoreElements() || url != null);
            }
        };
    }
 
Example 2
Source File: AppletClassLoader.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public Enumeration findResources(String name) throws IOException {

        final Enumeration e = super.findResources(name);

        // 6215746:  Disable META-INF/* lookup from codebase in
        // applet/plugin classloader. [stanley.ho]
        if (name.startsWith("META-INF/"))
            return e;

        // 4668479: Option to turn off codebase lookup in AppletClassLoader
        // during resource requests. [stanley.ho]
        if (codebaseLookup == false)
            return e;

        URL u = new URL(base, ParseUtil.encodePath(name, false));
        if (!resourceExists(u)) {
            u = null;
        }

        final URL url = u;
        return new Enumeration() {
            private boolean done;
            public Object nextElement() {
                if (!done) {
                    if (e.hasMoreElements()) {
                        return e.nextElement();
                    }
                    done = true;
                    if (url != null) {
                        return url;
                    }
                }
                throw new NoSuchElementException();
            }
            public boolean hasMoreElements() {
                return !done && (e.hasMoreElements() || url != null);
            }
        };
    }
 
Example 3
Source File: AppletClassLoader.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public Enumeration findResources(String name) throws IOException {

        final Enumeration e = super.findResources(name);

        // 6215746:  Disable META-INF/* lookup from codebase in
        // applet/plugin classloader. [stanley.ho]
        if (name.startsWith("META-INF/"))
            return e;

        // 4668479: Option to turn off codebase lookup in AppletClassLoader
        // during resource requests. [stanley.ho]
        if (codebaseLookup == false)
            return e;

        URL u = new URL(base, ParseUtil.encodePath(name, false));
        if (!resourceExists(u)) {
            u = null;
        }

        final URL url = u;
        return new Enumeration() {
            private boolean done;
            public Object nextElement() {
                if (!done) {
                    if (e.hasMoreElements()) {
                        return e.nextElement();
                    }
                    done = true;
                    if (url != null) {
                        return url;
                    }
                }
                throw new NoSuchElementException();
            }
            public boolean hasMoreElements() {
                return !done && (e.hasMoreElements() || url != null);
            }
        };
    }
 
Example 4
Source File: ModulePatcher.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Resource find(String name) throws IOException {
    JarEntry entry = jf.getJarEntry(name);
    if (entry == null)
        return null;

    return new Resource() {
        @Override
        public String getName() {
            return name;
        }
        @Override
        public URL getURL() {
            String encodedPath = ParseUtil.encodePath(name, false);
            try {
                return new URL("jar:" + csURL + "!/" + encodedPath);
            } catch (MalformedURLException e) {
                return null;
            }
        }
        @Override
        public URL getCodeSourceURL() {
            return csURL;
        }
        @Override
        public ByteBuffer getByteBuffer() throws IOException {
            byte[] bytes = getInputStream().readAllBytes();
            return ByteBuffer.wrap(bytes);
        }
        @Override
        public InputStream getInputStream() throws IOException {
            return jf.getInputStream(entry);
        }
        @Override
        public int getContentLength() throws IOException {
            long size = entry.getSize();
            return (size > Integer.MAX_VALUE) ? -1 : (int) size;
        }
    };
}
 
Example 5
Source File: ModuleReferences.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
Optional<URI> implFind(String name) {
    JmodFile.Entry je = getEntry(name);
    if (je != null) {
        if (je.isDirectory() && !name.endsWith("/"))
            name += "/";
        String encodedPath = ParseUtil.encodePath(name, false);
        String uris = "jmod:" + uri + "!/" + encodedPath;
        return Optional.of(URI.create(uris));
    } else {
        return Optional.empty();
    }
}
 
Example 6
Source File: ModuleReferences.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
Optional<URI> implFind(String name) throws IOException {
    JarEntry je = getEntry(name);
    if (je != null) {
        if (jf.isMultiRelease())
            name = SharedSecrets.javaUtilJarAccess().getRealName(jf, je);
        if (je.isDirectory() && !name.endsWith("/"))
            name += "/";
        String encodedPath = ParseUtil.encodePath(name, false);
        String uris = "jar:" + uri + "!/" + encodedPath;
        return Optional.of(URI.create(uris));
    } else {
        return Optional.empty();
    }
}
 
Example 7
Source File: ModulePatcher.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public Resource find(String name) throws IOException {
    JarEntry entry = jf.getJarEntry(name);
    if (entry == null)
        return null;

    return new Resource() {
        @Override
        public String getName() {
            return name;
        }
        @Override
        public URL getURL() {
            String encodedPath = ParseUtil.encodePath(name, false);
            try {
                return new URL("jar:" + csURL + "!/" + encodedPath);
            } catch (MalformedURLException e) {
                return null;
            }
        }
        @Override
        public URL getCodeSourceURL() {
            return csURL;
        }
        @Override
        public ByteBuffer getByteBuffer() throws IOException {
            byte[] bytes = getInputStream().readAllBytes();
            return ByteBuffer.wrap(bytes);
        }
        @Override
        public InputStream getInputStream() throws IOException {
            return jf.getInputStream(entry);
        }
        @Override
        public int getContentLength() throws IOException {
            long size = entry.getSize();
            return (size > Integer.MAX_VALUE) ? -1 : (int) size;
        }
    };
}
 
Example 8
Source File: AppletClassLoader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public Enumeration findResources(String name) throws IOException {

        final Enumeration e = super.findResources(name);

        // 6215746:  Disable META-INF/* lookup from codebase in
        // applet/plugin classloader. [stanley.ho]
        if (name.startsWith("META-INF/"))
            return e;

        // 4668479: Option to turn off codebase lookup in AppletClassLoader
        // during resource requests. [stanley.ho]
        if (codebaseLookup == false)
            return e;

        URL u = new URL(base, ParseUtil.encodePath(name, false));
        if (!resourceExists(u)) {
            u = null;
        }

        final URL url = u;
        return new Enumeration() {
            private boolean done;
            public Object nextElement() {
                if (!done) {
                    if (e.hasMoreElements()) {
                        return e.nextElement();
                    }
                    done = true;
                    if (url != null) {
                        return url;
                    }
                }
                throw new NoSuchElementException();
            }
            public boolean hasMoreElements() {
                return !done && (e.hasMoreElements() || url != null);
            }
        };
    }
 
Example 9
Source File: AppletClassLoader.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public Enumeration findResources(String name) throws IOException {

        final Enumeration e = super.findResources(name);

        // 6215746:  Disable META-INF/* lookup from codebase in
        // applet/plugin classloader. [stanley.ho]
        if (name.startsWith("META-INF/"))
            return e;

        // 4668479: Option to turn off codebase lookup in AppletClassLoader
        // during resource requests. [stanley.ho]
        if (codebaseLookup == false)
            return e;

        URL u = new URL(base, ParseUtil.encodePath(name, false));
        if (!resourceExists(u)) {
            u = null;
        }

        final URL url = u;
        return new Enumeration() {
            private boolean done;
            public Object nextElement() {
                if (!done) {
                    if (e.hasMoreElements()) {
                        return e.nextElement();
                    }
                    done = true;
                    if (url != null) {
                        return url;
                    }
                }
                throw new NoSuchElementException();
            }
            public boolean hasMoreElements() {
                return !done && (e.hasMoreElements() || url != null);
            }
        };
    }
 
Example 10
Source File: AppletClassLoader.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public Enumeration findResources(String name) throws IOException {

        final Enumeration e = super.findResources(name);

        // 6215746:  Disable META-INF/* lookup from codebase in
        // applet/plugin classloader. [stanley.ho]
        if (name.startsWith("META-INF/"))
            return e;

        // 4668479: Option to turn off codebase lookup in AppletClassLoader
        // during resource requests. [stanley.ho]
        if (codebaseLookup == false)
            return e;

        URL u = new URL(base, ParseUtil.encodePath(name, false));
        if (!resourceExists(u)) {
            u = null;
        }

        final URL url = u;
        return new Enumeration() {
            private boolean done;
            public Object nextElement() {
                if (!done) {
                    if (e.hasMoreElements()) {
                        return e.nextElement();
                    }
                    done = true;
                    if (url != null) {
                        return url;
                    }
                }
                throw new NoSuchElementException();
            }
            public boolean hasMoreElements() {
                return !done && (e.hasMoreElements() || url != null);
            }
        };
    }
 
Example 11
Source File: AppletClassLoader.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public Enumeration findResources(String name) throws IOException {

        final Enumeration e = super.findResources(name);

        // 6215746:  Disable META-INF/* lookup from codebase in
        // applet/plugin classloader. [stanley.ho]
        if (name.startsWith("META-INF/"))
            return e;

        // 4668479: Option to turn off codebase lookup in AppletClassLoader
        // during resource requests. [stanley.ho]
        if (codebaseLookup == false)
            return e;

        URL u = new URL(base, ParseUtil.encodePath(name, false));
        if (!resourceExists(u)) {
            u = null;
        }

        final URL url = u;
        return new Enumeration() {
            private boolean done;
            public Object nextElement() {
                if (!done) {
                    if (e.hasMoreElements()) {
                        return e.nextElement();
                    }
                    done = true;
                    if (url != null) {
                        return url;
                    }
                }
                throw new NoSuchElementException();
            }
            public boolean hasMoreElements() {
                return !done && (e.hasMoreElements() || url != null);
            }
        };
    }
 
Example 12
Source File: AppletClassLoader.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Enumeration findResources(String name) throws IOException {

        final Enumeration e = super.findResources(name);

        // 6215746:  Disable META-INF/* lookup from codebase in
        // applet/plugin classloader. [stanley.ho]
        if (name.startsWith("META-INF/"))
            return e;

        // 4668479: Option to turn off codebase lookup in AppletClassLoader
        // during resource requests. [stanley.ho]
        if (codebaseLookup == false)
            return e;

        URL u = new URL(base, ParseUtil.encodePath(name, false));
        if (!resourceExists(u)) {
            u = null;
        }

        final URL url = u;
        return new Enumeration() {
            private boolean done;
            public Object nextElement() {
                if (!done) {
                    if (e.hasMoreElements()) {
                        return e.nextElement();
                    }
                    done = true;
                    if (url != null) {
                        return url;
                    }
                }
                throw new NoSuchElementException();
            }
            public boolean hasMoreElements() {
                return !done && (e.hasMoreElements() || url != null);
            }
        };
    }
 
Example 13
Source File: AppletClassLoader.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns an input stream for reading the specified resource.
 *
 * The search order is described in the documentation for {@link
 * #getResource(String)}.<p>
 *
 * @param  name the resource name
 * @return an input stream for reading the resource, or <code>null</code>
 *         if the resource could not be found
 * @since  JDK1.1
 */
public InputStream getResourceAsStream(String name)
{

    if (name == null) {
        throw new NullPointerException("name");
    }

    try
    {
        InputStream is = null;

        // Fixed #4507227: Slow performance to load
        // class and resources. [stanleyh]
        //
        // The following is used to avoid calling
        // AppletClassLoader.findResource() in
        // super.getResourceAsStream(). Otherwise,
        // unnecessary connection will be made.
        //
        synchronized(syncResourceAsStream)
        {
            resourceAsStreamInCall = true;

            // Call super class
            is = super.getResourceAsStream(name);

            resourceAsStreamInCall = false;
        }

        // 4668479: Option to turn off codebase lookup in AppletClassLoader
        // during resource requests. [stanley.ho]
        if (codebaseLookup == true && is == null)
        {
            // If resource cannot be obtained,
            // try to download it from codebase
            URL url = new URL(base, ParseUtil.encodePath(name, false));
            is = url.openStream();
        }

        return is;
    }
    catch (Exception e)
    {
        return null;
    }
}
 
Example 14
Source File: AppletClassLoader.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns an input stream for reading the specified resource.
 *
 * The search order is described in the documentation for {@link
 * #getResource(String)}.<p>
 *
 * @param  name the resource name
 * @return an input stream for reading the resource, or <code>null</code>
 *         if the resource could not be found
 * @since  JDK1.1
 */
public InputStream getResourceAsStream(String name)
{

    if (name == null) {
        throw new NullPointerException("name");
    }

    try
    {
        InputStream is = null;

        // Fixed #4507227: Slow performance to load
        // class and resources. [stanleyh]
        //
        // The following is used to avoid calling
        // AppletClassLoader.findResource() in
        // super.getResourceAsStream(). Otherwise,
        // unnecessary connection will be made.
        //
        synchronized(syncResourceAsStream)
        {
            resourceAsStreamInCall = true;

            // Call super class
            is = super.getResourceAsStream(name);

            resourceAsStreamInCall = false;
        }

        // 4668479: Option to turn off codebase lookup in AppletClassLoader
        // during resource requests. [stanley.ho]
        if (codebaseLookup == true && is == null)
        {
            // If resource cannot be obtained,
            // try to download it from codebase
            URL url = new URL(base, ParseUtil.encodePath(name, false));
            is = url.openStream();
        }

        return is;
    }
    catch (Exception e)
    {
        return null;
    }
}
 
Example 15
Source File: AppletClassLoader.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns an input stream for reading the specified resource.
 *
 * The search order is described in the documentation for {@link
 * #getResource(String)}.<p>
 *
 * @param  name the resource name
 * @return an input stream for reading the resource, or <code>null</code>
 *         if the resource could not be found
 * @since  JDK1.1
 */
public InputStream getResourceAsStream(String name)
{

    if (name == null) {
        throw new NullPointerException("name");
    }

    try
    {
        InputStream is = null;

        // Fixed #4507227: Slow performance to load
        // class and resources. [stanleyh]
        //
        // The following is used to avoid calling
        // AppletClassLoader.findResource() in
        // super.getResourceAsStream(). Otherwise,
        // unnecessary connection will be made.
        //
        synchronized(syncResourceAsStream)
        {
            resourceAsStreamInCall = true;

            // Call super class
            is = super.getResourceAsStream(name);

            resourceAsStreamInCall = false;
        }

        // 4668479: Option to turn off codebase lookup in AppletClassLoader
        // during resource requests. [stanley.ho]
        if (codebaseLookup == true && is == null)
        {
            // If resource cannot be obtained,
            // try to download it from codebase
            URL url = new URL(base, ParseUtil.encodePath(name, false));
            is = url.openStream();
        }

        return is;
    }
    catch (Exception e)
    {
        return null;
    }
}
 
Example 16
Source File: AppletClassLoader.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns an input stream for reading the specified resource.
 *
 * The search order is described in the documentation for {@link
 * #getResource(String)}.<p>
 *
 * @param  name the resource name
 * @return an input stream for reading the resource, or <code>null</code>
 *         if the resource could not be found
 * @since  JDK1.1
 */
public InputStream getResourceAsStream(String name)
{

    if (name == null) {
        throw new NullPointerException("name");
    }

    try
    {
        InputStream is = null;

        // Fixed #4507227: Slow performance to load
        // class and resources. [stanleyh]
        //
        // The following is used to avoid calling
        // AppletClassLoader.findResource() in
        // super.getResourceAsStream(). Otherwise,
        // unnecessary connection will be made.
        //
        synchronized(syncResourceAsStream)
        {
            resourceAsStreamInCall = true;

            // Call super class
            is = super.getResourceAsStream(name);

            resourceAsStreamInCall = false;
        }

        // 4668479: Option to turn off codebase lookup in AppletClassLoader
        // during resource requests. [stanley.ho]
        if (codebaseLookup == true && is == null)
        {
            // If resource cannot be obtained,
            // try to download it from codebase
            URL url = new URL(base, ParseUtil.encodePath(name, false));
            is = url.openStream();
        }

        return is;
    }
    catch (Exception e)
    {
        return null;
    }
}
 
Example 17
Source File: AppletClassLoader.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns an input stream for reading the specified resource.
 *
 * The search order is described in the documentation for {@link
 * #getResource(String)}.<p>
 *
 * @param  name the resource name
 * @return an input stream for reading the resource, or <code>null</code>
 *         if the resource could not be found
 * @since  JDK1.1
 */
public InputStream getResourceAsStream(String name)
{

    if (name == null) {
        throw new NullPointerException("name");
    }

    try
    {
        InputStream is = null;

        // Fixed #4507227: Slow performance to load
        // class and resources. [stanleyh]
        //
        // The following is used to avoid calling
        // AppletClassLoader.findResource() in
        // super.getResourceAsStream(). Otherwise,
        // unnecessary connection will be made.
        //
        synchronized(syncResourceAsStream)
        {
            resourceAsStreamInCall = true;

            // Call super class
            is = super.getResourceAsStream(name);

            resourceAsStreamInCall = false;
        }

        // 4668479: Option to turn off codebase lookup in AppletClassLoader
        // during resource requests. [stanley.ho]
        if (codebaseLookup == true && is == null)
        {
            // If resource cannot be obtained,
            // try to download it from codebase
            URL url = new URL(base, ParseUtil.encodePath(name, false));
            is = url.openStream();
        }

        return is;
    }
    catch (Exception e)
    {
        return null;
    }
}
 
Example 18
Source File: AppletClassLoader.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns an input stream for reading the specified resource.
 *
 * The search order is described in the documentation for {@link
 * #getResource(String)}.<p>
 *
 * @param  name the resource name
 * @return an input stream for reading the resource, or <code>null</code>
 *         if the resource could not be found
 * @since  JDK1.1
 */
public InputStream getResourceAsStream(String name)
{

    if (name == null) {
        throw new NullPointerException("name");
    }

    try
    {
        InputStream is = null;

        // Fixed #4507227: Slow performance to load
        // class and resources. [stanleyh]
        //
        // The following is used to avoid calling
        // AppletClassLoader.findResource() in
        // super.getResourceAsStream(). Otherwise,
        // unnecessary connection will be made.
        //
        synchronized(syncResourceAsStream)
        {
            resourceAsStreamInCall = true;

            // Call super class
            is = super.getResourceAsStream(name);

            resourceAsStreamInCall = false;
        }

        // 4668479: Option to turn off codebase lookup in AppletClassLoader
        // during resource requests. [stanley.ho]
        if (codebaseLookup == true && is == null)
        {
            // If resource cannot be obtained,
            // try to download it from codebase
            URL url = new URL(base, ParseUtil.encodePath(name, false));
            is = url.openStream();
        }

        return is;
    }
    catch (Exception e)
    {
        return null;
    }
}
 
Example 19
Source File: AppletClassLoader.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns an input stream for reading the specified resource.
 *
 * The search order is described in the documentation for {@link
 * #getResource(String)}.<p>
 *
 * @param  name the resource name
 * @return an input stream for reading the resource, or <code>null</code>
 *         if the resource could not be found
 * @since  JDK1.1
 */
public InputStream getResourceAsStream(String name)
{

    if (name == null) {
        throw new NullPointerException("name");
    }

    try
    {
        InputStream is = null;

        // Fixed #4507227: Slow performance to load
        // class and resources. [stanleyh]
        //
        // The following is used to avoid calling
        // AppletClassLoader.findResource() in
        // super.getResourceAsStream(). Otherwise,
        // unnecessary connection will be made.
        //
        synchronized(syncResourceAsStream)
        {
            resourceAsStreamInCall = true;

            // Call super class
            is = super.getResourceAsStream(name);

            resourceAsStreamInCall = false;
        }

        // 4668479: Option to turn off codebase lookup in AppletClassLoader
        // during resource requests. [stanley.ho]
        if (codebaseLookup == true && is == null)
        {
            // If resource cannot be obtained,
            // try to download it from codebase
            URL url = new URL(base, ParseUtil.encodePath(name, false));
            is = url.openStream();
        }

        return is;
    }
    catch (Exception e)
    {
        return null;
    }
}
 
Example 20
Source File: AppletClassLoader.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns an input stream for reading the specified resource.
 *
 * The search order is described in the documentation for {@link
 * #getResource(String)}.<p>
 *
 * @param  name the resource name
 * @return an input stream for reading the resource, or <code>null</code>
 *         if the resource could not be found
 * @since  JDK1.1
 */
public InputStream getResourceAsStream(String name)
{

    if (name == null) {
        throw new NullPointerException("name");
    }

    try
    {
        InputStream is = null;

        // Fixed #4507227: Slow performance to load
        // class and resources. [stanleyh]
        //
        // The following is used to avoid calling
        // AppletClassLoader.findResource() in
        // super.getResourceAsStream(). Otherwise,
        // unnecessary connection will be made.
        //
        synchronized(syncResourceAsStream)
        {
            resourceAsStreamInCall = true;

            // Call super class
            is = super.getResourceAsStream(name);

            resourceAsStreamInCall = false;
        }

        // 4668479: Option to turn off codebase lookup in AppletClassLoader
        // during resource requests. [stanley.ho]
        if (codebaseLookup == true && is == null)
        {
            // If resource cannot be obtained,
            // try to download it from codebase
            URL url = new URL(base, ParseUtil.encodePath(name, false));
            is = url.openStream();
        }

        return is;
    }
    catch (Exception e)
    {
        return null;
    }
}