Example usage for java.net URI getAuthority

List of usage examples for java.net URI getAuthority

Introduction

In this page you can find the example usage for java.net URI getAuthority.

Prototype

public String getAuthority() 

Source Link

Document

Returns the decoded authority component of this URI.

Usage

From source file:Main.java

public static void main(String[] args) throws NullPointerException, URISyntaxException {
    URI uri = new URI("http://www.java2s.com");
    System.out.println("URI      : " + uri);
    System.out.println("Authority : " + uri.getAuthority());
}

From source file:Main.java

public static void main(String[] args) throws NullPointerException, URISyntaxException {
    URI uri = new URI("http://www.example.org");
    System.out.println("URI      : " + uri);
    System.out.println("Raw Authority : " + uri.getRawAuthority());
    System.out.println("Raw Fragment : " + uri.getRawFragment());
    System.out.println("Fragment : " + uri.getFragment());
    System.out.println("Authority : " + uri.getAuthority());
    System.out.println("Authority : " + uri.getRawPath());
    System.out.println("RawQuery : " + uri.getRawQuery());
    System.out.println("RawSchemeSpecificPart : " + uri.getRawSchemeSpecificPart());
    System.out.println("RawUserInfo : " + uri.getRawUserInfo());

}

From source file:IRIDemo.java

public static void main(String[] args) throws NullPointerException, URISyntaxException {
    URI uri = new URI("http://r%C3%A9sum%C3%A9.example.org");
    System.out.println("URI      : " + uri);
    System.out.println("Raw Authority : " + uri.getRawAuthority());
    System.out.println("Raw Fragment : " + uri.getRawFragment());
    System.out.println("Fragment : " + uri.getFragment());
    System.out.println("Authority : " + uri.getAuthority());
    System.out.println("Authority : " + uri.getRawPath());
    System.out.println("RawQuery : " + uri.getRawQuery());
    System.out.println("RawSchemeSpecificPart : " + uri.getRawSchemeSpecificPart());
    System.out.println("RawUserInfo : " + uri.getRawUserInfo());

}

From source file:org.apache.helix.tools.ZkCopy.java

public static void main(String[] args) throws Exception {
    CommandLineParser cliParser = new GnuParser();
    Options cliOptions = constructCmdLineOpt();
    CommandLine cmd = null;//from  w w w  .j a  va 2s.co m

    try {
        cmd = cliParser.parse(cliOptions, args);
    } catch (ParseException pe) {
        System.err.println("CommandLineClient: failed to parse command-line options: " + pe.toString());
        printUsage(cliOptions);
        System.exit(1);
    }

    URI srcUri = new URI(cmd.getOptionValue(src));
    URI dstUri = new URI(cmd.getOptionValue(dst));

    ZkCopyScheme srcScheme = ZkCopyScheme.valueOf(srcUri.getScheme());
    ZkCopyScheme dstScheme = ZkCopyScheme.valueOf(dstUri.getScheme());

    if (srcScheme == ZkCopyScheme.zk && dstScheme == ZkCopyScheme.zk) {
        String srcZkAddr = srcUri.getAuthority();
        String dstZkAddr = dstUri.getAuthority();

        ZkClient srcClient = null;
        ZkClient dstClient = null;
        try {
            if (srcZkAddr.equals(dstZkAddr)) {
                srcClient = dstClient = new ZkClient(srcZkAddr, ZkClient.DEFAULT_SESSION_TIMEOUT,
                        ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ByteArraySerializer());
            } else {
                srcClient = new ZkClient(srcZkAddr, ZkClient.DEFAULT_SESSION_TIMEOUT,
                        ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ByteArraySerializer());
                dstClient = new ZkClient(dstZkAddr, ZkClient.DEFAULT_SESSION_TIMEOUT,
                        ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ByteArraySerializer());
            }
            String srcPath = srcUri.getPath();
            String dstPath = dstUri.getPath();
            zkCopy(srcClient, srcPath, dstClient, dstPath);
        } finally {
            if (srcClient != null) {
                srcClient.close();
            }
            if (dstClient != null) {
                dstClient.close();
            }
        }
    } else {
        System.err.println("Unsupported scheme. srcScheme: " + srcScheme + ", dstScheme: " + dstScheme);
        System.exit(1);
    }
}

From source file:org.apache.commons.net.examples.mail.IMAPExportMbox.java

public static void main(String[] args) throws IOException, URISyntaxException {
    int connect_timeout = CONNECT_TIMEOUT;
    int read_timeout = READ_TIMEOUT;

    int argIdx = 0;
    String eol = EOL_DEFAULT;/*from   w  w w.  java2  s . com*/
    boolean printHash = false;
    boolean printMarker = false;
    int retryWaitSecs = 0;

    for (argIdx = 0; argIdx < args.length; argIdx++) {
        if (args[argIdx].equals("-c")) {
            connect_timeout = Integer.parseInt(args[++argIdx]);
        } else if (args[argIdx].equals("-r")) {
            read_timeout = Integer.parseInt(args[++argIdx]);
        } else if (args[argIdx].equals("-R")) {
            retryWaitSecs = Integer.parseInt(args[++argIdx]);
        } else if (args[argIdx].equals("-LF")) {
            eol = LF;
        } else if (args[argIdx].equals("-CRLF")) {
            eol = CRLF;
        } else if (args[argIdx].equals("-.")) {
            printHash = true;
        } else if (args[argIdx].equals("-X")) {
            printMarker = true;
        } else {
            break;
        }
    }

    final int argCount = args.length - argIdx;

    if (argCount < 2) {
        System.err.println("Usage: IMAPExportMbox [-LF|-CRLF] [-c n] [-r n] [-R n] [-.] [-X]"
                + " imap[s]://user:password@host[:port]/folder/path [+|-]<mboxfile> [sequence-set] [itemnames]");
        System.err.println(
                "\t-LF | -CRLF set end-of-line to LF or CRLF (default is the line.separator system property)");
        System.err.println("\t-c connect timeout in seconds (default 10)");
        System.err.println("\t-r read timeout in seconds (default 10)");
        System.err.println("\t-R temporary failure retry wait in seconds (default 0; i.e. disabled)");
        System.err.println("\t-. print a . for each complete message received");
        System.err.println("\t-X print the X-IMAP line for each complete message received");
        System.err.println(
                "\tthe mboxfile is where the messages are stored; use '-' to write to standard output.");
        System.err.println(
                "\tPrefix file name with '+' to append to the file. Prefix with '-' to allow overwrite.");
        System.err.println(
                "\ta sequence-set is a list of numbers/number ranges e.g. 1,2,3-10,20:* - default 1:*");
        System.err
                .println("\titemnames are the message data item name(s) e.g. BODY.PEEK[HEADER.FIELDS (SUBJECT)]"
                        + " or a macro e.g. ALL - default (INTERNALDATE BODY.PEEK[])");
        System.exit(1);
    }

    final String uriString = args[argIdx++];
    URI uri;
    try {
        uri = URI.create(uriString);
    } catch (IllegalArgumentException e) { // cannot parse the path as is; let's pull it apart and try again
        Matcher m = Pattern.compile("(imaps?://[^/]+)(/.*)").matcher(uriString);
        if (m.matches()) {
            uri = URI.create(m.group(1)); // Just the scheme and auth parts
            uri = new URI(uri.getScheme(), uri.getAuthority(), m.group(2), null, null);
        } else {
            throw e;
        }
    }
    final String file = args[argIdx++];
    String sequenceSet = argCount > 2 ? args[argIdx++] : "1:*";
    final String itemNames;
    // Handle 0, 1 or multiple item names
    if (argCount > 3) {
        if (argCount > 4) {
            StringBuilder sb = new StringBuilder();
            sb.append("(");
            for (int i = 4; i <= argCount; i++) {
                if (i > 4) {
                    sb.append(" ");
                }
                sb.append(args[argIdx++]);
            }
            sb.append(")");
            itemNames = sb.toString();
        } else {
            itemNames = args[argIdx++];
        }
    } else {
        itemNames = "(INTERNALDATE BODY.PEEK[])";
    }

    final boolean checkSequence = sequenceSet.matches("\\d+:(\\d+|\\*)"); // are we expecting a sequence?
    final MboxListener chunkListener;
    if (file.equals("-")) {
        chunkListener = null;
    } else if (file.startsWith("+")) {
        final File mbox = new File(file.substring(1));
        System.out.println("Appending to file " + mbox);
        chunkListener = new MboxListener(new BufferedWriter(new FileWriter(mbox, true)), eol, printHash,
                printMarker, checkSequence);
    } else if (file.startsWith("-")) {
        final File mbox = new File(file.substring(1));
        System.out.println("Writing to file " + mbox);
        chunkListener = new MboxListener(new BufferedWriter(new FileWriter(mbox, false)), eol, printHash,
                printMarker, checkSequence);
    } else {
        final File mbox = new File(file);
        if (mbox.exists() && mbox.length() > 0) {
            throw new IOException("mailbox file: " + mbox + " already exists and is non-empty!");
        }
        System.out.println("Creating file " + mbox);
        chunkListener = new MboxListener(new BufferedWriter(new FileWriter(mbox)), eol, printHash, printMarker,
                checkSequence);
    }

    String path = uri.getPath();
    if (path == null || path.length() < 1) {
        throw new IllegalArgumentException("Invalid folderPath: '" + path + "'");
    }
    String folder = path.substring(1); // skip the leading /

    // suppress login details
    final PrintCommandListener listener = new PrintCommandListener(System.out, true) {
        @Override
        public void protocolReplyReceived(ProtocolCommandEvent event) {
            if (event.getReplyCode() != IMAPReply.PARTIAL) { // This is dealt with by the chunk listener
                super.protocolReplyReceived(event);
            }
        }
    };

    // Connect and login
    final IMAPClient imap = IMAPUtils.imapLogin(uri, connect_timeout * 1000, listener);

    String maxIndexInFolder = null;

    try {

        imap.setSoTimeout(read_timeout * 1000);

        if (!imap.select(folder)) {
            throw new IOException("Could not select folder: " + folder);
        }

        for (String line : imap.getReplyStrings()) {
            maxIndexInFolder = matches(line, PATEXISTS, 1);
            if (maxIndexInFolder != null) {
                break;
            }
        }

        if (chunkListener != null) {
            imap.setChunkListener(chunkListener);
        } // else the command listener displays the full output without processing

        while (true) {
            boolean ok = imap.fetch(sequenceSet, itemNames);
            // If the fetch failed, can we retry?
            if (!ok && retryWaitSecs > 0 && chunkListener != null && checkSequence) {
                final String replyString = imap.getReplyString(); //includes EOL
                if (startsWith(replyString, PATTEMPFAIL)) {
                    System.err.println("Temporary error detected, will retry in " + retryWaitSecs + "seconds");
                    sequenceSet = (chunkListener.lastSeq + 1) + ":*";
                    try {
                        Thread.sleep(retryWaitSecs * 1000);
                    } catch (InterruptedException e) {
                        // ignored
                    }
                } else {
                    throw new IOException(
                            "FETCH " + sequenceSet + " " + itemNames + " failed with " + replyString);
                }
            } else {
                break;
            }
        }

    } catch (IOException ioe) {
        String count = chunkListener == null ? "?" : Integer.toString(chunkListener.total);
        System.err.println("FETCH " + sequenceSet + " " + itemNames + " failed after processing " + count
                + " complete messages ");
        if (chunkListener != null) {
            System.err.println("Last complete response seen: " + chunkListener.lastFetched);
        }
        throw ioe;
    } finally {

        if (printHash) {
            System.err.println();
        }

        if (chunkListener != null) {
            chunkListener.close();
            final Iterator<String> missingIds = chunkListener.missingIds.iterator();
            if (missingIds.hasNext()) {
                StringBuilder sb = new StringBuilder();
                for (;;) {
                    sb.append(missingIds.next());
                    if (!missingIds.hasNext()) {
                        break;
                    }
                    sb.append(",");
                }
                System.err.println("*** Missing ids: " + sb.toString());
            }
        }
        imap.logout();
        imap.disconnect();
    }
    if (chunkListener != null) {
        System.out.println("Processed " + chunkListener.total + " messages.");
    }
    if (maxIndexInFolder != null) {
        System.out.println("Folder contained " + maxIndexInFolder + " messages.");
    }
}

From source file:Main.java

private static String getSchemeAuthority(URI uri) {
    return uri.getScheme() + "_" + uri.getAuthority();
}

From source file:com.twitter.distributedlog.client.serverset.DLZkServerSet.java

private static String getZKServersFromDLUri(URI uri) {
    return uri.getAuthority().replace(";", ",");
}

From source file:Main.java

public static String getFSMSessionFromUri(URI fsmURI) {
    String result = null;//w w w . j  a v a 2s .  c  o  m

    if (fsmURI != null) {
        result = fsmURI.getAuthority();
    }
    return result;
}

From source file:org.xdi.oxauth.service.fido.u2f.ClientDataValidationService.java

public static String canonicalizeOrigin(String url) {
    try {//  ww w.jav  a2 s.co  m
        URI uri = new URI(url);
        if (uri.getAuthority() == null) {
            return url;
        }
        return uri.getScheme() + "://" + uri.getAuthority();
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Specified bad origin", e);
    }
}

From source file:Main.java

public static void printURIDetails(URI uri) {
    System.out.println("URI:" + uri);
    System.out.println("Normalized:" + uri.normalize());
    String parts = "[Scheme=" + uri.getScheme() + ", Authority=" + uri.getAuthority() + ", Path="
            + uri.getPath() + ", Query:" + uri.getQuery() + ", Fragment:" + uri.getFragment() + "]";
    System.out.println(parts);//from www.jav a 2s.c  om
    System.out.println();
}