001 package org.crsh.vfs.spi.ram;
002
003 import org.crsh.vfs.Path;
004
005 import java.io.IOException;
006 import java.net.URL;
007 import java.net.URLConnection;
008 import java.net.URLStreamHandler;
009
010 /** @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a> */
011 public class RAMURLStreamHandler extends URLStreamHandler {
012
013 /** . */
014 private final RAMDriver driver;
015
016 public RAMURLStreamHandler(RAMDriver driver) {
017 this.driver = driver;
018 }
019
020 @Override
021 protected URLConnection openConnection(URL u) throws IOException {
022 Path path = Path.get(u.getFile());
023 if (path.isDir()) {
024 throw new IOException("Cannot open dir");
025 }
026 String file = driver.entries.get(path);
027 if (file == null) {
028 throw new IOException("Cannot open non existing dir " + path);
029 }
030 return new RAMURLConnection(u, file);
031 }
032 }