Java Code Examples for javax.microedition.io.Connector#READ

The following examples show how to use javax.microedition.io.Connector#READ . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: luaj   File: JmeIoLib.java    License: MIT License 6 votes vote down vote up
protected File openFile( String filename, boolean readMode, boolean appendMode, boolean updateMode, boolean binaryMode ) throws IOException {
	String url = "file:///" + filename;
	int mode  = readMode? Connector.READ: Connector.READ_WRITE;
	StreamConnection conn = (StreamConnection) Connector.open( url, mode );
	File f = readMode? 
			new FileImpl(conn, conn.openInputStream(), null):
			new FileImpl(conn, conn.openInputStream(), conn.openOutputStream());
	/*
	if ( appendMode ) {
		f.seek("end",0);
	} else {
		if ( ! readMode )
			conn.truncate(0);
	}
	*/
	return f;
}
 
Example 2
/**
 * @inheritDoc
 */
public Object connect(String url, boolean read, boolean write) throws IOException {
    int mode;
    if(read && write) {
        mode = Connector.READ_WRITE;
    } else {
        if(write) {
            mode = Connector.WRITE;
        } else {
            mode = Connector.READ;
        }
    }
    return Connector.open(url, mode);
}
 
Example 3
private void checkOpenMode(int mode)  throws IllegalArgumentException {
    if (mode != Connector.READ_WRITE &&
        mode != Connector.READ &&
        mode != Connector.WRITE) {
        throw new IllegalArgumentException("Unsupported mode: " + mode);
    }
}
 
Example 4
public Connection open(String uri, int mode, boolean timeouts)
  throws IOException
{
  if (mode != Connector.READ &&
      mode != Connector.WRITE &&
      mode != Connector.READ_WRITE)
    throw new IllegalArgumentException("Variable mode has an invalid value");

  if (null==uri || uri.length()==0)
    throw new IllegalArgumentException("URI must not be null or empty");

  int schemeSeparator = uri.indexOf(':');

  if (schemeSeparator < 0) {
    throw new IllegalArgumentException("Not a valid URI");
  }

  String scheme = uri.substring(0, schemeSeparator);

  ConnectionFactory factory = getFactory(scheme);
  Connection retval = null;

  if (factory != null) {
    retval = factory.createConnection(uri, mode, timeouts);

  } else {

    // fall back to Connector.
    try {
      retval = Connector.open(uri, mode, timeouts);
    } catch (Exception e) {
      throw new ConnectionNotFoundException();
    }

  }

  if (retval == null)
    throw new ConnectionNotFoundException();
  else
    return retval;
}
 
Example 5
protected void checkReadMode() throws IOException {
    if ((mode & Connector.READ) == 0) {
        throw new IOException("Invalid mode: " + mode);
    }
}