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

The following examples show how to use javax.microedition.io.file.FileConnection#canWrite() . 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);
}
 
Example 7
Source File: CanWrite.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests canWrite() in Connector.READ mode
 */
public void test0009() {
	boolean passed = false;
	try {	
		addOperationDesc("Opening connection in READ mode");
		FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ);
		try {
			boolean canWrite = conn.canWrite();
			addOperationDesc("canWrite() call returned " + canWrite);
			
			passed = true;								
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}
	
	assertTrueWithLog("Tests canWrite() in Connector.READ mode", passed);
}
 
Example 8
Source File: CanWrite.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests canWrite() on a non-existent file
 */
public void test0010() {
	boolean passed = false;
	try {
		FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
		try {
			addOperationDesc("Deleting file: " + conn.getURL());
			ensureNotExists(conn);
			
			boolean canWrite = conn.canWrite();
			addOperationDesc("canWrite() returned " + canWrite);
			
			passed = canWrite==false;
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

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

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

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

	assertTrueWithLog("canWrite() returns false for a non-existent directory (writable attribute is NOT supported by filesystem)", passed);
}