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

The following examples show how to use javax.microedition.io.Connector#READ . 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 File: JmeIoLib.java    From luaj with 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
Source File: GameCanvasImplementation.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @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
Source File: BluetoothProtocol.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: ConnectorServiceImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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
Source File: BluetoothConnection.java    From pluotsorbet with GNU General Public License v2.0 4 votes vote down vote up
protected void checkReadMode() throws IOException {
    if ((mode & Connector.READ) == 0) {
        throw new IOException("Invalid mode: " + mode);
    }
}