Package javax.microedition.io

Examples of javax.microedition.io.Connection


    /**
     * @see org.osgi.service.io.ConnectorService#openDataInputStream(java.lang.String)
     */
    public DataInputStream openDataInputStream(String name) throws IOException
    {
        Connection connection = open(name, READ, false);
        if (!(connection instanceof InputConnection))
        {
            try
            {
                connection.close();
            } catch (IOException ioex)
            {

            }

            throw new IOException("Connection doesn't implement InputConnection" + connection.getClass());
        }

        return ((InputConnection) connection).openDataInputStream();
    }
View Full Code Here


    /**
     * @see org.osgi.service.io.ConnectorService#openDataOutputStream(java.lang.String)
     */
    public DataOutputStream openDataOutputStream(String name) throws IOException
    {
        Connection connection = open(name, WRITE, false);
        if (!(connection instanceof OutputConnection))
        {
            try
            {
                connection.close();
            } catch (IOException ioex)
            {

            }

            throw new IOException("Connection doesn't implement OutputConnection" + connection.getClass());
        }

        return ((OutputConnection) connection).openDataOutputStream();
    }
View Full Code Here

    /**
     * @see org.osgi.service.io.ConnectorService#openInputStream(java.lang.String)
     */
    public InputStream openInputStream(String name) throws IOException
    {
        Connection connection = open(name, READ, false);
        if (!(connection instanceof InputConnection))
        {
            try
            {
                connection.close();
            } catch (IOException ioex)
            {

            }

            throw new IOException("Connection doesn't implement InputConnection" + connection.getClass());
        }

        return ((InputConnection) connection).openInputStream();
    }
View Full Code Here

    /**
     * @see org.osgi.service.io.ConnectorService#openOutputStream(java.lang.String)
     */
    public OutputStream openOutputStream(String name) throws IOException
    {
        Connection connection = open(name, WRITE, false);
        if (!(connection instanceof OutputConnection))
        {
            try
            {
                connection.close();
            } catch (IOException ioex)
            {

            }

            throw new IOException("Connection doesn't implement OutputConnection" + connection.getClass());
        }

        return ((OutputConnection) connection).openOutputStream();
    }
View Full Code Here

        }

        String scheme = name.substring(0, index);

        ConnectionFactory connFactory = resolveConnectionFactory(scheme);
        Connection connection = null;
        if (connFactory != null)
        {
            connection = connFactory.createConnection(name, mode, timeouts);
        }
        // if connection is not provided go to javax.microedition.io.Connector
View Full Code Here

     *   protocol handler is prohibited
     */
    public Connection open(boolean timeouts)
        throws IOException
    {
        Connection conn = Connector.open(getURL(), Connector.READ, timeouts);
        return conn;
    }
View Full Code Here

                                "URL is null",
                                ContentHandlerException.TYPE_UNKNOWN);
        }

        // Open a connection to the content.
        Connection conn = null;
        int rc = 0;
        try {
            while (true) {
                // Loop to enable redirects.
                conn = Connector.open(url);
                if (conn instanceof HttpConnection) {
                    HttpConnection httpc = (HttpConnection)conn;
                    httpc.setRequestMethod(httpc.HEAD);

                    // Get the response code
                    rc = httpc.getResponseCode();
                    if (rc == HttpConnection.HTTP_OK) {
                        type = httpc.getType();
                        if (type != null) {
                            // Check for and remove any parameters (rfc2616)
                            int ndx = type.indexOf(';');
                            if (ndx >= 0) {
                                type = type.substring(0, ndx);
                            }
                            type = type.trim();
                        }
                        if (type == null || type.length() == 0) {
                            type = null;
                            throw new ContentHandlerException(
                                "unable to determine type",
                                ContentHandlerException.TYPE_UNKNOWN);
                        }
                        break;
                    } else if (rc == HttpConnection.HTTP_TEMP_REDIRECT ||
                               rc == HttpConnection.HTTP_MOVED_TEMP ||
                               rc == HttpConnection.HTTP_MOVED_PERM) {
                        // Get the new location and close the connection
                        url = httpc.getHeaderField("location");

                        conn.close();
                        conn = null;
                        continue; // restart with the new url
                    } else {
                        throw new IOException("http status: " + rc);
                    }
                } else {
                    // Not HTTP, this isn't going to work
                    // TBD: Check suffixes
                    throw new ContentHandlerException(
                                "URL scheme not supported",
                                ContentHandlerException.TYPE_UNKNOWN);
                }
            }

        } finally {
            if (conn != null) {
                try {
                    conn.close();
                } catch (Exception ex) {
                }
            }
        }
        return type;
View Full Code Here

     *             throws an IOException for invalid path values
     *
     */
    public FileConnectionWrapper( String path ) throws IOException {

        Connection con = Connector.open( path );

        if( con instanceof FileConnection ) {
            _fileConnection = (FileConnection) con;
        } else {
            // not a file connection - throw exception
            if( con != null ) {
                try {
                    con.close();
                } catch( Exception e ) {
                }
            }
            throw new FileIOException( FileIOException.INVALID_PARAMETER );
        }
View Full Code Here

        return properties;
    }

    private static FileConnection open( String fullPath ) {
        Connection con;
        try {
            con = Connector.open( fullPath );
        } catch( IOException e ) {
            return null;
        }
View Full Code Here

     * @throws Exception
     */
    public void setHomeScreenBackground( String filePath ) throws Exception {
        FileConnection fileConnection = null;
        try {
            Connection con = Connector.open( filePath );
            if( con != null && con instanceof FileConnection ) {
                fileConnection = (FileConnection) con;
                if( !fileConnection.exists() || fileConnection.isDirectory() ) {
                    throw new Exception( "Invalid file URI" );
                }
View Full Code Here

TOP

Related Classes of javax.microedition.io.Connection

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.