Package java.net

Examples of java.net.URI


    private final JUnit4Mockery context = new JUnit4Mockery();
    private final MultiChannelConnector connector = context.mock(MultiChannelConnector.class);

    @Test
    public void createsConnectionOnConstructionAndStopsOnStop() throws Exception {
        final URI serverAddress = new URI("test:somestuff");
        final MultiChannelConnection<Message> connection = context.mock(MultiChannelConnection.class);

        context.checking(new Expectations() {{
            one(connector).connect(with(equalTo(serverAddress)));
            will(returnValue(connection));
View Full Code Here


        });
    }

    private void finishConnect(ConnectEvent<Connection<Object>> event,
                               Action<ConnectEvent<MultiChannelConnection<Object>>> action) {
        URI localAddress = event.getLocalAddress();
        URI remoteAddress = event.getRemoteAddress();
        DefaultMultiChannelConnection channelConnection = new DefaultMultiChannelConnection(executorFactory,
                String.format("Incoming Connection %s", localAddress), event.getConnection(), localAddress, remoteAddress);
        action.execute(new ConnectEvent<MultiChannelConnection<Object>>(channelConnection, localAddress, remoteAddress));
    }
View Full Code Here

     *
     * @return The connection, or null if not running.
     */
    Connection<Object> maybeConnect() {
        try {
            URI uri;
            try {
                FileInputStream inputStream = new FileInputStream(getRegistryFile());
                try {
                    // Acquire shared lock on file while reading it
                    inputStream.getChannel().lock(0, Long.MAX_VALUE, true);
                    DataInputStream dataInputStream = new DataInputStream(inputStream);
                    uri = new URI(dataInputStream.readUTF());
                } finally {
                    // Also releases the lock
                    inputStream.close();
                }
            } catch (FileNotFoundException e) {
View Full Code Here

        TcpIncomingConnector incomingConnector = new TcpIncomingConnector(executorFactory, getClass().getClassLoader());
        final CompletionHandler finished = new CompletionHandler();

        LOGGER.lifecycle("Awaiting requests.");
       
        URI uri = incomingConnector.accept(new Action<ConnectEvent<Connection<Object>>>() {
            public void execute(ConnectEvent<Connection<Object>> connectionConnectEvent) {
                try {
                    finished.onStartActivity();
                    handler.handle(connectionConnectEvent.getConnection(), finished);
                } finally {
                    finished.onActivityComplete();
                    connectionConnectEvent.getConnection().stop();
                }
            }
        });

        try {
            File registryFile = getRegistryFile();
            registryFile.getParentFile().mkdirs();
//            registryFile.createNewFile();
            FileOutputStream outputStream = new FileOutputStream(registryFile);
            try {
                // Lock file while writing to it
                outputStream.getChannel().lock();
                DataOutputStream dataOutputStream = new DataOutputStream(outputStream);
                dataOutputStream.writeUTF(uri.toString());
                dataOutputStream.flush();
            } finally {
                // Also releases the lock
                outputStream.close();
            }
View Full Code Here

                throw new UncheckedIOException(e);
            }
        }

        if (path instanceof URI) {
            URI uri = (URI) path;
            if (uri.getScheme().equals("file")) {
                return new File(uri.getPath());
            }
            return uri;
        }

        String str = path.toString();
        if (str.startsWith("file:")) {
            return new File(uriDecode(str.substring(5)));
        }

        for (File file : File.listRoots()) {
            String rootPath = file.getAbsolutePath();
            String normalisedStr = str;
            if (!OperatingSystem.current().isCaseSensitiveFileSystem()) {
                rootPath = rootPath.toLowerCase();
                normalisedStr = normalisedStr.toLowerCase();
            }
            if (normalisedStr.startsWith(rootPath) || normalisedStr.startsWith(rootPath.replace(File.separatorChar,
                    '/'))) {
                return new File(str);
            }
        }

        // Check if string starts with a URI scheme
        if (URI_SCHEME.matcher(str).matches()) {
            try {
                return new URI(str);
            } catch (URISyntaxException e) {
                throw new UncheckedIOException(e);
            }
        }
View Full Code Here

            return baseURI;
        } else {
            if(baseURIString == null) {
                return null;
            }
            final URI uri;
            try {
                uri = new URI(baseURIString);
            } catch (URISyntaxException e) {
                throw new SyntaxError("err:XQST0046", e);
            }
            this.baseURI = uri;
            return uri;
View Full Code Here

    }

    private void doMain(String[] args) throws IOException, XQueryException, XMLStreamException {
        URL queryFileUrl = Example1.class.getResource("bib_relative.xq");
        InputStream input1 = queryFileUrl.openStream();
        URI baseUri = NetUtils.toURI(queryFileUrl); // This baseUri effects to fn:doc(...)
        invokeQueryPullMode(input1, baseUri);
        input1.close();

        System.out.println("--------------------------------");
View Full Code Here

    }

    public Sequence eval(Sequence<? extends Item> contextSeq, ValueSequence argv, DynamicContext dynEnv)
            throws XQueryException {
        StaticContext sc = dynEnv.getStaticContext();
        URI uri = sc.getBaseURI();
        if(uri == null) {
            return ValueSequence.EMPTY_SEQUENCE;
        }
        return new AnyURIValue(uri);
    }
View Full Code Here

                Node testCase = rs.item(i);
                final String testName = xpath.evaluate("./@name", testCase);
                final String testFilePath = xpath.evaluate("./@FilePath", testCase);
                final String queryFileName = xpath.evaluate("./*[local-name()='query']/@name", testCase);
                File queryFile = new File(xqtsQueryPath, testFilePath + queryFileName + ".xq");
                final URI baseUri = new File(xqtsQueryPath, testFilePath).toURI();

                XQueryModule xqmod = new XQueryModule();

                {// ((//*:test-group)//*:test-case)/*:module
                    NodeList moduleNodes = (NodeList) xpath.evaluate("./*[local-name()='module']", testCase, XPathConstants.NODESET);
View Full Code Here

        XQExpression body = mod.getExpression();
        return body;
    }

    private static Reader readQuery(String viewloc, StaticContext staticEnv) throws XQueryException {
        URI resolved = ResolveUri.resolveURI(viewloc, staticEnv);
        final URL queryUrl;
        try {
            queryUrl = resolved.toURL();
        } catch (MalformedURLException e) {
            throw new DynamicError("Invalid URL form: " + viewloc);
        }
        final InputStream is;
        try {
View Full Code Here

TOP

Related Classes of java.net.URI

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.