// Path: lib/src/WinRun4J/src/org/boris/winrun4j/classloader/ByteBufferInputStream.java
// public class ByteBufferInputStream extends InputStream
// {
//     private ByteBuffer bb;
// 
//     public ByteBufferInputStream(ByteBuffer bb) {
//         this.bb = bb;
//     }
// 
//     public int read() throws IOException {
//         try {
//             return bb.get() & Integer.MAX_VALUE;
//         } catch (BufferUnderflowException e) {
//             return -1;
//         }
//     }
// 
//     public int read(byte[] b) throws IOException {
//         int len = b.length;
//         if (len > bb.remaining()) {
//             len = bb.remaining();
//         }
// 
//         bb.get(b, 0, len);
//         return len;
//     }
// 
//     public int read(byte[] b, int off, int len) throws IOException {
//         if (len > bb.remaining()) {
//             len = bb.remaining();
//         }
// 
//         bb.get(b, off, len);
//         return len;
//     }
// 
//     public long skip(long n) throws IOException {
//         if (n > bb.remaining()) {
//             n = bb.remaining();
//         }
//         bb.position((int) (bb.position() + n));
//         return n;
//     }
// 
//     public int available() throws IOException {
//         return bb.remaining();
//     }
// 
//     public boolean markSupported() {
//         return false;
//     }
// }
// 
// Path: lib/src/WinRun4J/src/org/boris/winrun4j/classloader/EmbeddedClassLoader.java
// public class EmbeddedClassLoader extends URLClassLoader
// {
//     private String[] jars;
//     private ByteBuffer[] buffers;
// 
//     public EmbeddedClassLoader() {
//         super(makeUrls(), ClassLoader.getSystemClassLoader());
//         jars = listJars(null);
//         buffers = new ByteBuffer[jars.length];
//         for (int i = 0; i < buffers.length; i++) {
//             buffers[i] = getJar(null, jars[i]);
//         }
//     }
// 
//     private static URL[] makeUrls() {
//         String p = System.getProperty("java.class.path");
//         if (p == null)
//             return new URL[0];
//         StringTokenizer st = new StringTokenizer(p, ";");
//         ArrayList urls = new ArrayList();
//         while (st.hasMoreTokens()) {
//             try {
//                 urls.add(new URL(st.nextToken()));
//             } catch (MalformedURLException e) {
//             }
//         }
//         return (URL[]) urls.toArray(new URL[0]);
//     }
// 
//     public URL findResource(String name) {
//         try {
//             return new URL("res:///" + name);
//         } catch (MalformedURLException e) {
//             return null;
//         }
//     }
// 
//     public InputStream getResourceAsStream(String name) {
//         for (int i = 0; i < buffers.length; i++) {
//             ByteBuffer bb = buffers[i];
//             bb.position(0);
//             ZipInputStream zis = new ZipInputStream(new ByteBufferInputStream(bb));
//             ZipEntry ze = null;
//             try {
//                 while ((ze = zis.getNextEntry()) != null) {
//                     if (name.equals(ze.getName())) {
//                         return zis;
//                     }
//                 }
//             } catch (IOException e) {
//                 return null;
//             }
//         }
//         return null;
//     }
// 
//     protected Class findClass(String name) throws ClassNotFoundException {
//         String cname = name.replace('.', '/').concat(".class");
//         for (int i = 0; i < buffers.length; i++) {
//             ByteBuffer bb = buffers[i];
//             bb.position(0);
//             ZipInputStream zis = new ZipInputStream(new ByteBufferInputStream(bb));
//             ZipEntry ze = null;
//             try {
//                 while ((ze = zis.getNextEntry()) != null) {
//                     String s = ze.getName();
//                     if (cname.equals(s)) {
//                         ByteArrayOutputStream bos = new ByteArrayOutputStream();
//                         byte[] buf = new byte[4096];
//                         int len = 0;
//                         while ((len = zis.read(buf)) > 0) {
//                             bos.write(buf, 0, len);
//                         }
//                         byte[] cb = bos.toByteArray();
//                         return defineClass(name, cb, 0, cb.length);
//                     }
//                 }
//             } catch (IOException e) {
//                 throw new ClassNotFoundException(name, e);
//             }
//         }
// 
//         throw new ClassNotFoundException(name);
//     }
// 
//     public static native ByteBuffer getJar(String library, String jarName);
// 
//     public static native String[] listJars(String library);
// }


import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.nio.ByteBuffer;
import org.boris.winrun4j.classloader.ByteBufferInputStream;
import org.boris.winrun4j.classloader.EmbeddedClassLoader;
/*******************************************************************************
 * This program and the accompanying materials
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at 
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     Peter Smith
 *******************************************************************************/
package org.boris.winrun4j.res;



public class EmbeddedJarURLConnection extends URLConnection
{
    protected EmbeddedJarURLConnection(URL url) {
        super(url);
    }

    public void connect() throws IOException {
    }

    public InputStream getInputStream() throws IOException {
        ByteBuffer bb = EmbeddedClassLoader.getJar(null, url.getFile());
        if (bb == null)
            return null;
        else
// Path: lib/src/WinRun4J/src/org/boris/winrun4j/classloader/ByteBufferInputStream.java
// public class ByteBufferInputStream extends InputStream
// {
//     private ByteBuffer bb;
// 
//     public ByteBufferInputStream(ByteBuffer bb) {
//         this.bb = bb;
//     }
// 
//     public int read() throws IOException {
//         try {
//             return bb.get() & Integer.MAX_VALUE;
//         } catch (BufferUnderflowException e) {
//             return -1;
//         }
//     }
// 
//     public int read(byte[] b) throws IOException {
//         int len = b.length;
//         if (len > bb.remaining()) {
//             len = bb.remaining();
//         }
// 
//         bb.get(b, 0, len);
//         return len;
//     }
// 
//     public int read(byte[] b, int off, int len) throws IOException {
//         if (len > bb.remaining()) {
//             len = bb.remaining();
//         }
// 
//         bb.get(b, off, len);
//         return len;
//     }
// 
//     public long skip(long n) throws IOException {
//         if (n > bb.remaining()) {
//             n = bb.remaining();
//         }
//         bb.position((int) (bb.position() + n));
//         return n;
//     }
// 
//     public int available() throws IOException {
//         return bb.remaining();
//     }
// 
//     public boolean markSupported() {
//         return false;
//     }
// }
// 
// Path: lib/src/WinRun4J/src/org/boris/winrun4j/classloader/EmbeddedClassLoader.java
// public class EmbeddedClassLoader extends URLClassLoader
// {
//     private String[] jars;
//     private ByteBuffer[] buffers;
// 
//     public EmbeddedClassLoader() {
//         super(makeUrls(), ClassLoader.getSystemClassLoader());
//         jars = listJars(null);
//         buffers = new ByteBuffer[jars.length];
//         for (int i = 0; i < buffers.length; i++) {
//             buffers[i] = getJar(null, jars[i]);
//         }
//     }
// 
//     private static URL[] makeUrls() {
//         String p = System.getProperty("java.class.path");
//         if (p == null)
//             return new URL[0];
//         StringTokenizer st = new StringTokenizer(p, ";");
//         ArrayList urls = new ArrayList();
//         while (st.hasMoreTokens()) {
//             try {
//                 urls.add(new URL(st.nextToken()));
//             } catch (MalformedURLException e) {
//             }
//         }
//         return (URL[]) urls.toArray(new URL[0]);
//     }
// 
//     public URL findResource(String name) {
//         try {
//             return new URL("res:///" + name);
//         } catch (MalformedURLException e) {
//             return null;
//         }
//     }
// 
//     public InputStream getResourceAsStream(String name) {
//         for (int i = 0; i < buffers.length; i++) {
//             ByteBuffer bb = buffers[i];
//             bb.position(0);
//             ZipInputStream zis = new ZipInputStream(new ByteBufferInputStream(bb));
//             ZipEntry ze = null;
//             try {
//                 while ((ze = zis.getNextEntry()) != null) {
//                     if (name.equals(ze.getName())) {
//                         return zis;
//                     }
//                 }
//             } catch (IOException e) {
//                 return null;
//             }
//         }
//         return null;
//     }
// 
//     protected Class findClass(String name) throws ClassNotFoundException {
//         String cname = name.replace('.', '/').concat(".class");
//         for (int i = 0; i < buffers.length; i++) {
//             ByteBuffer bb = buffers[i];
//             bb.position(0);
//             ZipInputStream zis = new ZipInputStream(new ByteBufferInputStream(bb));
//             ZipEntry ze = null;
//             try {
//                 while ((ze = zis.getNextEntry()) != null) {
//                     String s = ze.getName();
//                     if (cname.equals(s)) {
//                         ByteArrayOutputStream bos = new ByteArrayOutputStream();
//                         byte[] buf = new byte[4096];
//                         int len = 0;
//                         while ((len = zis.read(buf)) > 0) {
//                             bos.write(buf, 0, len);
//                         }
//                         byte[] cb = bos.toByteArray();
//                         return defineClass(name, cb, 0, cb.length);
//                     }
//                 }
//             } catch (IOException e) {
//                 throw new ClassNotFoundException(name, e);
//             }
//         }
// 
//         throw new ClassNotFoundException(name);
//     }
// 
//     public static native ByteBuffer getJar(String library, String jarName);
// 
//     public static native String[] listJars(String library);
// }


// Path: lib/src/WinRun4J/src/org/boris/winrun4j/res/EmbeddedJarURLConnection.java
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.nio.ByteBuffer;
import org.boris.winrun4j.classloader.ByteBufferInputStream;
import org.boris.winrun4j.classloader.EmbeddedClassLoader;

/*******************************************************************************
 * This program and the accompanying materials
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at 
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     Peter Smith
 *******************************************************************************/
package org.boris.winrun4j.res;



public class EmbeddedJarURLConnection extends URLConnection
{
    protected EmbeddedJarURLConnection(URL url) {
        super(url);
    }

    public void connect() throws IOException {
    }

    public InputStream getInputStream() throws IOException {
        ByteBuffer bb = EmbeddedClassLoader.getJar(null, url.getFile());
        if (bb == null)
            return null;
        else
            return new ByteBufferInputStream(bb);