本文整理汇总了Java中javax.microedition.io.file.FileConnection.getURL方法的典型用法代码示例。如果您正苦于以下问题:Java FileConnection.getURL方法的具体用法?Java FileConnection.getURL怎么用?Java FileConnection.getURL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.microedition.io.file.FileConnection
的用法示例。
在下文中一共展示了FileConnection.getURL方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test0001
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
* 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);
}
示例2: test0002
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
* 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);
}
示例3: test0003
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
* 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);
}
示例4: test0004
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
* 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);
}
示例5: test0005
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
* 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);
}
示例6: test0006
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
* 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);
}
示例7: test0007
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
* 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);
}
示例8: test0008
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
* 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);
}
示例9: test0009
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
* 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);
}
示例10: ensureFileExists
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
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() + ")");
}
}
示例11: ensureDirExists
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
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() + ")");
}
}