Java Code Examples for javax.microedition.io.file.FileConnection#setWritable()

The following examples show how to use javax.microedition.io.file.FileConnection#setWritable() . 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: CanWrite.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests canWrite() on a writable file
 */
public void test0001() {
	boolean passed = false;
	try {
		FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
		try {
			addOperationDesc("Creating file: " + conn.getURL());
			ensureFileExists(conn);
			
			addOperationDesc("Setting file as writable");
			conn.setWritable(true);
			
			boolean canWrite = conn.canWrite();
			addOperationDesc("canWrite() returned " + canWrite);
			
			passed = canWrite==true;
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests canWrite() on a writable file", passed);
}
 
Example 2
Source File: CanWrite.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests canWrite() on a non-writable file
 */
public void test0002() {
	boolean passed = false;
	try {
		FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
		try {
			addOperationDesc("Creating file: " + conn.getURL());
			ensureFileExists(conn);
			
			addOperationDesc("Setting file as non-writable");
			conn.setWritable(false);
			
			boolean canWrite = conn.canWrite();
			addOperationDesc("canWrite() returned " + canWrite);
			
			passed = canWrite==false;
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests canWrite() on a non-writable file", passed);
}
 
Example 3
Source File: CanWrite.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests canWrite() on a writable directory
 */
public void test0003() {
	boolean passed = false;
	try {
		FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
		try {
			addOperationDesc("Creating directory: " + conn.getURL());
			ensureDirExists(conn);
			
			addOperationDesc("Setting directory as writable");
			conn.setWritable(true);
			
			boolean canWrite = conn.canWrite();
			addOperationDesc("canWrite() returned " + canWrite);
			
			passed = canWrite==true;
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests canWrite() on a writable directory", passed);
}
 
Example 4
Source File: CanWrite.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests canWrite() on a non-writable directory
 */
public void test0004() {
	boolean passed = false;
	try {
		FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
		try {
			addOperationDesc("Creating directory: " + conn.getURL());
			ensureDirExists(conn);
			
			addOperationDesc("Setting directory as non-writable");
			conn.setWritable(false);
			
			boolean canWrite = conn.canWrite();
			addOperationDesc("canWrite() returned " + canWrite);
			
			passed = canWrite==false;
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests canWrite() on a on-writable directory", passed);
}
 
Example 5
Source File: CanWrite.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests canWrite() on a file (writable attribute is NOT supported by filesystem)
 */
public void test0005() {
	boolean passed = false;
	try {
		FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
		try {
			addOperationDesc("Creating file: " + conn.getURL());
			ensureFileExists(conn);
			
			addOperationDesc("Setting file as non-writable");
			conn.setWritable(false);
			
			boolean canWrite = conn.canWrite();
			addOperationDesc("canWrite() returned " + canWrite);
			
			passed = canWrite==true;
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests canWrite() on a file (writable attribute is NOT supported by filesystem)", passed);
}
 
Example 6
Source File: CanWrite.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests canWrite() on a directory (writable attribute is NOT supported by filesystem)
 */
public void test0006() {
	boolean passed = false;
	try {
		FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
		try {
			addOperationDesc("Creating directory: " + conn.getURL());
			ensureDirExists(conn);
			
			addOperationDesc("Setting directory as non-writable");
			conn.setWritable(false);
			
			boolean canWrite = conn.canWrite();
			addOperationDesc("canWrite() returned " + canWrite);
			
			passed = canWrite==true;
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests canWrite() on a directory (writable attribute is NOT supported by filesystem)", passed);
}