public static int loadURIResource(URI uri, CPU cpu, int addr) { int i; System.out.println("loadURL: " + uri.toString()); try { DataInputStream s = new DataInputStream(new BufferedInputStream(uri.toURL().openStream())); i = 0; try { while (true) { cpu.write8_a32(addr + i, s.readByte()); i++; } } catch (EOFException e) { // end } } catch (IOException e) { e.printStackTrace(System.err); throw new IllegalArgumentException(e); } System.out.printf("loadURL: '%s' done, %dbytes.\n", uri.toString(), i); return i; }
/** * Creates a new FTPFile instance by converting the given file: URI into an abstract pathname. * * <p>FTP URI protocol:<br> * ftp:// [ userName [ : password ] @ ] host [ : port ][ / path ] * * <p>example:<br> * ftp://[email protected]:21/pub/testfile.txt * * @param uri An absolute, hierarchical URI using a supported scheme. * @throws NullPointerException if <code>uri</code> is <code>null</code>. * @throws IllegalArgumentException If the preconditions on the parameter do not hold. */ public FTPFile(URI uri) throws IOException, URISyntaxException { super(uri); if (uri.getScheme().equals("ftp")) { String userinfo = uri.getUserInfo(); if (userinfo != null) { int index = userinfo.indexOf(":"); if (index >= 0) { setFileSystem( new FTPFileSystem( new FTPAccount( uri.getHost(), uri.getPort(), userinfo.substring(0, index - 1), userinfo.substring(index + 1), uri.getPath()))); } else { setFileSystem( new FTPFileSystem( new FTPAccount(uri.getHost(), uri.getPort(), userinfo, "", uri.getPath()))); } } else { fileSystem = new FTPFileSystem( new FTPAccount(uri.getHost(), uri.getPort(), null, "", uri.getPath())); } setFileName(uri.getPath()); ftpClient = ((FTPFileSystem) fileSystem).getFTPClient(); } else { throw new URISyntaxException(uri.toString(), "Wrong URI scheme"); } }
public void setLibrary(URI url) throws Exception { if (url == null) url = new URI("http://repo.jpm4j.org/"); this.host = new URLClient(url.toString()); host.setReporter(reporter); library = JSONRPCProxy.createRPC(JpmRepo.class, host, "jpm"); }
private void setResponseLocationHeader(HttpServletRequest req, HttpServletResponse resp) throws ServletException { URI requestURI = ServletResourceHandler.getURI(req); String responsePath = "/" + new Path(requestURI.getPath()).segment(0) + "/import/" + id; //$NON-NLS-1$ //$NON-NLS-2$ URI responseURI; try { responseURI = new URI(requestURI.getScheme(), requestURI.getAuthority(), responsePath, null, null); } catch (URISyntaxException e) { // should not be possible throw new ServletException(e); } resp.setHeader(ProtocolConstants.HEADER_LOCATION, responseURI.toString()); }
/** * Evaluates a URI and adds it to the namespace map as a namespace. * * @param uri URI */ protected void addNamespaceURI(URI uri) { if (uri == null) { throw new IllegalArgumentException("URI argument is null."); } // extract URI without fragment String uriString = uri.toString(); String newURI = null; if (uriString != null) { // determine what comes last a '#' or '/' int hashindex = uriString.lastIndexOf('#'); int slashindex = uriString.lastIndexOf('/'); // validate (URI must contain a forward slash) if (slashindex == -1) { // namespace may have been evaluated already return; } // is there a '/' after the '#'? if (slashindex > hashindex) { // remove everything after the last '/' int index = uriString.lastIndexOf('/'); newURI = uriString.substring(0, index) + "/"; } else { // '#' comes after last '/' (remove entire fragment) newURI = uriString.replaceAll(uri.getFragment(), ""); } // only add namespace if it is new if ((newURI != null) && (!namespaces.containsValue(newURI))) { // add to namespaces namespaces.put("ns" + namespaces.size(), newURI); } } }
public static String convertUrlToBaseStringURI(URL url) { URI uri = null; try { uri = url.toURI(); } catch (URISyntaxException e1) { e1.printStackTrace(); } String scheme = uri.getScheme().toLowerCase(); String host = uri.getHost().toLowerCase(); int port = uri.getPort(); if ((scheme.equals(HTTP_PROTOCOL) && port == HTTP_DEFAULT_PORT) || (scheme.equals(HTTPS_PROTOCOL) && port == HTTPS_DEFAULT_PORT)) { port = -1; } URI baseUri = null; try { baseUri = new URI(scheme, null, host, port, uri.getPath(), null, null); } catch (URISyntaxException e) { e.printStackTrace(); } return baseUri.toString(); }