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

The following examples show how to use javax.microedition.io.file.FileConnection#getURL() . 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: GetURL.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests getURL() on a non-existing file url
 */
public void test0001() {
	boolean passed = false;
	try {
		String url = "file://" + getTestPath() + "file";	
		
		String escapedUrl		= URLSupport.getEscapedForm(url);
		String alternativeUrl	= URLSupport.getAlternativeEscapedForm(url);
					
		FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
		ensureNotExists(conn);
		try {
			addOperationDesc("Using file url: " + url);
			
			String connUrl = conn.getURL();
			addOperationDesc("getURL() returned: " + connUrl);
			
			passed = connUrl.equals(escapedUrl) || connUrl.equals(alternativeUrl);
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests getURL() on a non-existing file url", passed);
}
 
Example 2
Source File: GetURL.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests getURL() on a non-existing directory url
 */
public void test0002() {
	boolean passed = false;
	try {
		String url = "file://" + getTestPath() + "dir/";
			
		String escapedUrl 		= URLSupport.getEscapedForm(url);
		String alternativeUrl	= URLSupport.getAlternativeEscapedForm(url);
		
		FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
		ensureNotExists(conn);
		try {
			addOperationDesc("Using directory url: " + url);
			
			String connUrl = conn.getURL();
			addOperationDesc("getURL() returned: " + connUrl);
			
			passed = connUrl.equals(escapedUrl) || connUrl.equals(alternativeUrl);
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests getURL() on a non-existing directory url", passed);
}
 
Example 3
Source File: GetURL.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests getURL() on an existing file url
 */
public void test0003() {
	boolean passed = false;
	try {
		String url = "file://" + getTestPath() + "file";	
		
		String escapedUrl		= URLSupport.getEscapedForm(url);
		String alternativeUrl	= URLSupport.getAlternativeEscapedForm(url);
					
		FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
		ensureFileExists(conn);
		try {
			addOperationDesc("Using file url: " + url);
			
			String connUrl = conn.getURL();
			addOperationDesc("getURL() returned: " + connUrl);
			
			passed = connUrl.equals(escapedUrl) || connUrl.equals(alternativeUrl);
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests getURL() on an existing file url", passed);
}
 
Example 4
Source File: GetURL.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests getURL() on an existing directory url
 */
public void test0004() {
	boolean passed = false;
	try {
		String url = "file://" + getTestPath() + "dir/";
			
		String escapedUrl 		= URLSupport.getEscapedForm(url);
		String alternativeUrl	= URLSupport.getAlternativeEscapedForm(url);
		
		FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
		ensureDirExists(conn);
		try {
			addOperationDesc("Using directory url: " + url);
			
			String connUrl = conn.getURL();
			addOperationDesc("getURL() returned: " + connUrl);
			
			passed = connUrl.equals(escapedUrl) || connUrl.equals(alternativeUrl);
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests getURL() on an existing directory url", passed);
}
 
Example 5
Source File: GetURL.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests getURL() on an existing file, and a connection url ending with '/'
 */
public void test0005() {
	boolean passed = false;
	try {
		String url0="file://"+getTestPath()+"file";
		FileConnection conn0 = (FileConnection)Connector.open(url0, Connector.READ_WRITE);

		addOperationDesc("Creating file: " + url0);
		ensureFileExists(conn0);
		conn0.close();
		
		String escapedUrl		= URLSupport.getEscapedForm(url0);
		String alternativeUrl	= URLSupport.getAlternativeEscapedForm(url0);

		String url = "file://" + getTestPath() + "file/";						
		FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
		
		try {
			addOperationDesc("Using directory url: " + url);
			
			String connUrl = conn.getURL();
			addOperationDesc("getURL() returned: " + connUrl);
			
			passed = connUrl.equals(escapedUrl) || connUrl.equals(alternativeUrl);
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests getURL() on an existing file, and a connection url ending with '/'", passed);
}
 
Example 6
Source File: GetURL.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests getURL() on an existing directory, and a connection url not ending with '/'
 */
public void test0006() {
	boolean passed = false;
	try {
		String url0 = "file://" + getTestPath() + "dir/";
		FileConnection conn0 = (FileConnection)Connector.open(url0, Connector.READ_WRITE);

		addOperationDesc("Creating directory: " + url0);
		ensureDirExists(conn0);
		conn0.close();
			
		String escapedUrl 		= URLSupport.getEscapedForm(url0);
		String alternativeUrl	= URLSupport.getAlternativeEscapedForm(url0);

		String url = "file://" + getTestPath() + "dir";			
		FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
		
		try {
			addOperationDesc("Using file url: " + url);
			
			String connUrl = conn.getURL();
			addOperationDesc("getURL() returned: " + connUrl);
			
			passed = connUrl.equals(escapedUrl) || connUrl.equals(alternativeUrl);
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests getURL() on an existing directory, and a connection url not ending with '/'", passed);
}
 
Example 7
Source File: GetURL.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests getURL() on an encoded file URL
 */
public void test0007() {
	boolean passed = false;
	try {

		String url="file://"+ getTestPath() +"foo%5e%25bar/file";

		String escapedUrl		= URLSupport.getEscapedForm(url);
		String alternativeUrl	= URLSupport.getAlternativeEscapedForm(url);
					
		FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
		try {
			addOperationDesc("Using file: " + url);
			
			String connUrl = conn.getURL();
			addOperationDesc("getURL() returned: " + connUrl);
			
			passed = connUrl.equals(escapedUrl) || connUrl.equals(alternativeUrl);
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests getURL() on an encoded file URL", passed);
}
 
Example 8
Source File: GetURL.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests if getURL() returns in escaped URL format
 */
public void test0008() {
	boolean passed = false;
	try {
		String unEscapedUrl		= "file://"+ getTestPath() +"a directory/a file";

		String escapedUrl 		= URLSupport.getEscapedForm(unEscapedUrl);
		String alternativeUrl	= URLSupport.getAlternativeEscapedForm(unEscapedUrl);
			
		FileConnection conn = (FileConnection)Connector.open(unEscapedUrl, Connector.READ_WRITE);
		try {
			addOperationDesc("Using file: " + unEscapedUrl);
			
			String connUrl = conn.getURL();
			addOperationDesc("getURL() returned: " + connUrl);
			
			passed = connUrl.equals(escapedUrl) || connUrl.equals(alternativeUrl);
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests if getURL() returns in escaped URL format", passed);
}
 
Example 9
Source File: GetURL.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests getURL() on a file url with host
 */
public void test0009() {
	boolean passed = false;
	try {
			String url = "file://" + URLSupport.getPathWithHost(getTestPath())+ "file";
			
		FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);

		try {
			String escapedUrl 		= URLSupport.getEscapedForm(url);
			String alternativeUrl	= URLSupport.getAlternativeEscapedForm(url);
		
			addOperationDesc("Using file url with host: " + url);
		
			String connUrl= conn.getURL();
			addOperationDesc("getURL() returned: " + connUrl);

			passed = connUrl.equals(escapedUrl) || connUrl.equals(alternativeUrl);			
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests getURL() on a file url with host", passed);
}
 
Example 10
Source File: TestCaseWithLog.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
protected void ensureFileExists(FileConnection conn) throws IOException {
	if (conn.exists()) {
		// if the file already exists, delete it to ensure zero length when created again
		recursiveDelete(conn);
	}
	
	try {
		conn.create();
	} catch (Exception e) {
		throw new IOException("could not create file <" + conn.getURL() + "> (" + e.getMessage() + ")");
	}
}
 
Example 11
Source File: TestCaseWithLog.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
protected void ensureDirExists(FileConnection conn) throws IOException {
	if (conn.exists()) {
		// if the dir already exists, delete it to ensure zero length when created again
		recursiveDelete(conn);
	}
	
	try {
		conn.mkdir();
	} catch (Exception e) {
		throw new IOException("could not create directory <" + conn.getURL() + "> (" + e.getMessage() + ")");
	}
}