/* TestPathFileLocator.java (c) 2015 Edward Swartz All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html */ package v9t9.machine.common.tests; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.net.URL; import java.net.URLConnection; import org.junit.Test; import ejs.base.utils.FileUtils; /** * @author ejs * */ public class TestPathFileLocator { // FIXME: taken from a main() in PathFileLocator... not sure how to validate @Test public void test() throws Exception { URL url = new URL("file:///home/ejs/path/to/files/"); URI root = url.toURI(); System.out.println(root); URI same = root.resolve("."); System.out.println(same); URI parent = root.resolve(".."); System.out.println(parent); URI parentParent = root.resolve("../../"); if (parentParent.getScheme().equals("file")) System.out.println(new File(parentParent)); System.out.println(url); System.out.println(new URL(url, "..")); System.out.println(new URL(url, ".")); URI another = new URI("jar:///tmp/foo.jar!/in/and/out/"); System.out.println(another); URI anotherParent = another.resolve(".."); System.out.println(anotherParent); anotherParent = anotherParent.resolve(".."); if (anotherParent.getScheme().equals("file")) System.out.println(new File(anotherParent)); System.out.println(anotherParent); anotherParent = anotherParent.resolve(".."); System.out.println(anotherParent); URI query = new URI("http://foo.bar.com/path/to/something/?query=bar"); System.out.println(query); URI queryPlus = query.resolve("foo/la/dee"); System.out.println(queryPlus); URI queryPlus2 = query.resolve("foo/la/dee" + "?"+ query.getQuery()); System.out.println(queryPlus2); query = new URI("https://foo.bar.com/path/to/something/?query=bar"); System.out.println(query); queryPlus = query.resolve("foo/la/dee"); System.out.println(queryPlus); queryPlus2 = query.resolve("foo/la/dee" + "?"+ query.getQuery()); System.out.println(queryPlus2); try { URL dir = new URL("file:/tmp"); URLConnection connection = dir.openConnection(); connection.connect(); System.out.println(connection.getContentType()); System.out.println(connection.getContentLength()); InputStream is = connection.getInputStream(); System.out.println(FileUtils.readInputStreamTextAndClose(is)); is.close(); } catch (IOException e) { e.printStackTrace(); } } }