Package java.net

Examples of java.net.MalformedURLException


   * @throws FTPException
   */
  protected static void prepareURLTransfer(URL url, FileTransferClientInterface client)
    throws IOException, FTPException {
    if (!url.getProtocol().equals("ftp"))
      throw new MalformedURLException("Unsupported protocol: "
          + url.getProtocol());
      client.setRemoteHost(url.getHost());
      if (url.getPort()>0)
        client.setRemotePort(url.getPort());
      String userInfo = url.getUserInfo();
      String userName = "anonymous", password = "";
      if (userInfo!=null) {
        int colonPos = userInfo.indexOf(':');
        if (colonPos>=0) {
          userName = userInfo.substring(0, colonPos);
          if (colonPos+1<userInfo.length()-1)
            password = userInfo.substring(colonPos+1);
        } else
          userName = userInfo;
      }
      client.setUserName(userName);
      client.setPassword(password);
      client.setDetectContentType(true);
      if (url.getQuery()!=null) {
        String query = url.getQuery();
        String TYPE = "type=";
        int typePos = query.indexOf(TYPE);
        if (typePos>=0 && query.length()>typePos+TYPE.length()) {
          char typeChar = query.toUpperCase().charAt(typePos+TYPE.length());
          if (typeChar==FTPTransferType.BINARY_CHAR.charAt(0)) {
            client.setContentType(FTPTransferType.BINARY);
              client.setDetectContentType(true);
          } else if (typeChar==FTPTransferType.ASCII_CHAR.charAt(0)) {
            client.setContentType(FTPTransferType.ASCII);
              client.setDetectContentType(true);
          } else
              throw new MalformedURLException("Unknown type: " + query.substring(typePos));
        }
      }
  }
View Full Code Here


     */
    public static FileTransferInputStream downloadURLStream(String ftpURL)
      throws MalformedURLException, IOException, FTPException {
      URL url = new URL(ftpURL);
      if (!url.getProtocol().equals("ftp"))
        throw new MalformedURLException("Unsupported protocol: " + url.getProtocol());
      FileTransferClient client = new FileTransferClient();
    prepareURLTransfer(url, client);
      client.connect();
    return new AutoCloseFileTransferInputStream(client.downloadStream(url.getPath()), client);
    }
View Full Code Here

    public static void downloadURLFile(String localFileName, String ftpURL)
      throws MalformedURLException, IOException, FTPException {
    URL url = new URL(ftpURL);
    FileTransferClient client = new FileTransferClient();
    if (!url.getProtocol().equals("ftp"))
      throw new MalformedURLException("Unsupported protocol: "
          + url.getProtocol());
    prepareURLTransfer(url, client);
    client.connect();
    try {
      client.downloadFile(localFileName, url.getPath());
View Full Code Here

  public static FileTransferOutputStream uploadURLStream(String ftpURL)
      throws MalformedURLException, IOException, FTPException {
    URL url = new URL(ftpURL);
    FileTransferClient client = new FileTransferClient();
    if (!url.getProtocol().equals("ftp"))
      throw new MalformedURLException("Unsupported protocol: "
          + url.getProtocol());
    prepareURLTransfer(url, client);
    client.connect();
    return new AutoCloseFileTransferOutputStream(client.uploadStream(url
        .getPath()), client);
View Full Code Here

   *
   *
   */
  public URL getResource(String path) throws MalformedURLException {
    if (path == null || path.length() == 0 || path.charAt(0) != '/')
      throw new MalformedURLException("Path " + path
          + " is not in acceptable form.");
    File resFile = new File(getRealPath(path));
    if (resFile.exists()) // TODO get canonical path is more robust
      return new URL("file", "localhost", resFile.getPath());
    return null;
View Full Code Here

                host = hostport.substring(0, ppos);
                String port = hostport.substring(ppos + 1);
                try {
                    this.port = Integer.parseInt(port);
                } catch (NumberFormatException e) {
                    throw new MalformedURLException("Invalid port "+port);
                }
            } else {
                host = hostport;
            }
        } else {
            throw new MalformedURLException("Empty URL");
        }
    }
View Full Code Here

     * @throws MalformedURLException
     * @since 4.2
     */
    public TeiidURL(String serverURL) throws MalformedURLException {
        if (serverURL == null) {
            throw new MalformedURLException(INVALID_FORMAT_SERVER);
        }
        if (StringUtil.startsWithIgnoreCase(serverURL, SECURE_PROTOCOL)) {
          usingSSL = true;
        } else if (!StringUtil.startsWithIgnoreCase(serverURL, DEFAULT_PROTOCOL)) {
          throw new MalformedURLException(INVALID_FORMAT_SERVER);
        }

        appServerURL = serverURL;
    parseServerURL(serverURL.substring(usingSSL?SECURE_PROTOCOL.length():DEFAULT_PROTOCOL.length()), INVALID_FORMAT_SERVER);
    }
View Full Code Here

     * @since 4.2
     */
    private void parseServerURL(String serverURL, String exceptionMessage) throws MalformedURLException {
        StringTokenizer st = new StringTokenizer(serverURL, COMMA_DELIMITER);
        if (!st.hasMoreTokens()) {
            throw new MalformedURLException(exceptionMessage);
        }
        while (st.hasMoreTokens()) {
          String nextToken = st.nextToken();
          nextToken = nextToken.trim();
          String host = ""; //$NON-NLS-1$
          String port = ""; //$NON-NLS-1$
          if (nextToken.startsWith("[")) { //$NON-NLS-1$
            int hostEnd = nextToken.indexOf("]:"); //$NON-NLS-1$
            if (hostEnd == -1) {
              throw new MalformedURLException(JDBCPlugin.Util.getString("TeiidURL.invalid_ipv6_hostport", nextToken, exceptionMessage)); //$NON-NLS-1$
            }
            host = nextToken.substring(1, hostEnd);
            port = nextToken.substring(hostEnd+2);
          }
          else {
            int hostEnd = nextToken.indexOf(":"); //$NON-NLS-1$
            if (hostEnd == -1) {
              throw new MalformedURLException(JDBCPlugin.Util.getString("TeiidURL.invalid_hostport", nextToken, exceptionMessage)); //$NON-NLS-1$
            }
            host = nextToken.substring(0, hostEnd);
            port = nextToken.substring(hostEnd+1);
          }
          host = host.trim();
          port = port.trim();
            if (host.equals("") || port.equals("")) { //$NON-NLS-1$ //$NON-NLS-2$
                throw new MalformedURLException(JDBCPlugin.Util.getString("TeiidURL.invalid_hostport", nextToken, exceptionMessage)); //$NON-NLS-1$
            }
            int portNumber = validatePort(port);
            HostInfo hostInfo = new HostInfo(host, portNumber);
            hosts.add(hostInfo);
        }
View Full Code Here

  public static int validatePort(String port) throws MalformedURLException {
    int portNumber;
    try {
        portNumber = Integer.parseInt(port);
    } catch (NumberFormatException nfe) {
        throw new MalformedURLException(JDBCPlugin.Util.getString("TeiidURL.non_numeric_port", port)); //$NON-NLS-1$
    }
    String msg = validatePort(portNumber);
    if (msg != null) {
      throw new MalformedURLException(msg);
    }
    return portNumber;
  }
View Full Code Here

        SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(new IOException(
        "A test Generic java.io.IOException"), //$NON-NLS-1$
        SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
    testCreateThrowable(
        new MalformedURLException(
            "A test java.net.MalformedURLException"), //$NON-NLS-1$
        SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(new TeiidException(
        "A test Generic MM Core Exception"), SQLStates.DEFAULT); //$NON-NLS-1$
    testCreateThrowable(new TeiidException("A test MM Exception"), //$NON-NLS-1$
View Full Code Here

TOP

Related Classes of java.net.MalformedURLException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.