/*
* JBoss, Home of Professional Open Source
* Copyright 2006, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.vfs.protocol;

import java.io.IOException;
import java.io.InputStream;
import java.io.File;
import java.io.FilePermission;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLDecoder;
import java.security.Permission;

import org.jboss.vfs.VFS;
import org.jboss.vfs.VirtualFile;
import sun.net.www.ParseUtil;

/**
 * Implements basic URLConnection for a VirtualFile
 *
 * @author <a href="bill@jboss.com">Bill Burke</a>
 * @author <a href="ales.justin@jboss.com">Ales Justin</a>
 * @version $Revision: 1.1 $
 */
class VirtualFileURLConnection extends URLConnection {

    protected VirtualFile file;

    public VirtualFileURLConnection(URL url) throws IOException {
        super(url);
        file = VFS.getInstance().getChild(URLDecoder.decode(url.getPath(), "UTF-8"));
    }

    public void connect() throws IOException {
    }

    public VirtualFile getContent() throws IOException {
        return file;
    }

    public int getContentLength() {
        try {
            final long size = file.getSize();
            return size > (long) Integer.MAX_VALUE ? -1 : (int) size;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public long getLastModified() {
        try {
            return file.getLastModified();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public InputStream getInputStream() throws IOException {
        return file.openStream();
    }

    public Permission getPermission() throws IOException {
        String decodedPath = ParseUtil.decode(url.getPath());
        if (File.separatorChar == '/') {
            return new FilePermission(decodedPath, "read");
        } else {
            return new FilePermission(
                    decodedPath.replace('/', File.separatorChar), "read");
        }
    }
}

@@ -1058,27 +1058,20 @@
 java.io.
-IOException
+File
 ;%0D%0Aimpor
@@ -1080,27 +1080,30 @@
 java.io.
-InputStream
+FilePermission
 ;%0D%0Aimpor
@@ -1104,36 +1104,43 @@
 %0Aimport java.io.
-File
+IOException
 ;%0D%0Aimport java.i
@@ -1137,38 +1137,35 @@
 ort java.io.
-FilePermission
+InputStream
 ;%0D%0Aimport ja
@@ -1339,39 +1339,8 @@
 le;%0D
-%0Aimport sun.net.www.ParseUtil;%0D
 %0A%0D%0A/
@@ -2633,17 +2633,18 @@
 h = 
-ParseUtil
+URLDecoder
 .dec
@@ -2660,16 +2660,25 @@
 etPath()
+, %22UTF-8%22
 );%0D%0A    

Remove dep on non-standard class