当前位置: 首页>>代码示例>>Java>>正文


Java FileConnection.close方法代码示例

本文整理汇总了Java中javax.microedition.io.file.FileConnection.close方法的典型用法代码示例。如果您正苦于以下问题:Java FileConnection.close方法的具体用法?Java FileConnection.close怎么用?Java FileConnection.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.microedition.io.file.FileConnection的用法示例。


在下文中一共展示了FileConnection.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test0001

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
 * Tests fileSize() on a file
 */
public void test0001() {
	boolean passed = false;
	try {
		FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE); 
		try {				
			addOperationDesc("Creating file with a size of 64 bytes: " + conn.getURL());
			ensureFileExists(conn);
			ensureFileSize(conn, 64);
			
			long fileSize = conn.fileSize();
			addOperationDesc("fileSize() returned " + fileSize);
			
			passed = fileSize==64;
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests fileSize() on a file", passed);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:27,代码来源:FileSize.java

示例2: test0009

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
 * Tests getName() 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 {
			addOperationDesc("Using file url with host: " + url);
			
			String name = conn.getName();
			addOperationDesc("getName() returned " + name);

			passed = name.equals("file");				
		} finally {
			conn.close();
		}

	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests getName() on a file url with host", passed);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:29,代码来源:GetName.java

示例3: remove

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
public void remove() throws IOException {
    FileConnection con = connector();

    //TODO: this really needs to be written better, but
    //for now avoiding deadlock is better than ensuring
    //thread safety

    //Take a lock on the connection so that nothing tries
    //to access it while this happens
    synchronized(con) {
        con.delete();
        con.close();
    }

    //Take a lock on the connections so that
    //nothing can retrieve the connection
    synchronized(connections) {
        //Remove the local connection now that it's
        //closed.
        clearReferenceConnection(getLocalURI());
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:23,代码来源:J2meFileReference.java

示例4: dumpRMS

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
public static void dumpRMS (String pathPrefix) {
    if (pathPrefix == null)
        pathPrefix = DUMP_PATH_PREFIX_DEFAULT;
    String filepath = dumpFilePath(pathPrefix);

    try {
        FileConnection fc = (FileConnection)Connector.open("file:///" + filepath);
        if (fc.exists()) {
            System.err.println("Error: File " + filepath + " already exists");
            fail("Dump file " + filepath + " already exists");
        }

        fc.create();
        DataOutputStream out = fc.openDataOutputStream();

        dumpRMS(out);

        fc.close();
    } catch (IOException ioe) {
        fail(ioe, "ioexception");
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:23,代码来源:DumpRMS.java

示例5: test0001

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
 * create() creates a new file
 */
public void test0001() {
	boolean passed = false;
	try {
		FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
		try {
			addOperationDesc("Deleting file: " + conn.getURL());
			ensureNotExists(conn);
			
			addOperationDesc("Creating file");
			conn.create();

			boolean exists = conn.exists();
			addOperationDesc("exists() returned " + exists);
			
			passed = exists==true;
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("create() creates a new file", passed);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:29,代码来源:Create.java

示例6: startApp

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
public void startApp() {
    System.out.println("START - Background alarm started: " + startedBackgroundAlarm());

    receiveSMS();

    try {
        FileConnection file = (FileConnection)Connector.open("file:////startBackgroundService");
        if (!file.exists()) {
            file.create();
        }
        file.close();
    } catch (IOException e) {
        System.out.println("Unexpected exception: " + e);
        return;
    }

    System.out.println("DONE - Background alarm started: " + startedBackgroundAlarm());
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:19,代码来源:ForegroundEnableBackgroundServiceMIDlet.java

示例7: test0003

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
 * Tests isHidden() on a hidden 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 hidden");
			conn.setHidden(true);
			
			boolean isHidden = conn.isHidden();
			addOperationDesc("isHidden() returned " + isHidden);
			
			passed = isHidden==true;
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests isHidden() on a hidden directory", passed);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:29,代码来源:IsHidden.java

示例8: test0001

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
 * Tests directorySize() on empty directory
 */
public void test0001() {
	boolean passed = false;
	try {
		FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"testdir/", Connector.READ_WRITE);
		try {
			addOperationDesc("Creating directory: " + conn.getURL());
			ensureDirExists(conn);
			
			long directorySize = conn.directorySize(true);
			addOperationDesc("directorySize(true) returned " + directorySize);
			
			passed = directorySize==0;
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests directorySize() on empty directory", passed);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:26,代码来源:DirectorySize.java

示例9: test0004

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
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);
			
			long modifyTime = conn.lastModified();
			addOperationDesc("lastModified() returned " + modifyTime);
			
			passed = modifyTime == 0;
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests lastModified() on a directory (modification date is NOT supported by filesystem)", passed);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:24,代码来源:LastModified.java

示例10: test0005

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:29,代码来源:CanWrite.java

示例11: test0001

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
 * Tests exists() on a 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);
			
			boolean exists = conn.exists();
			addOperationDesc("exists() returned " + exists);
			
			passed = exists==true;
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests exists() on a file", passed);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:26,代码来源:Exists.java

示例12: test0007

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
 * Tests getName() on an encoded file URL
 */
public void test0007() {
	boolean passed = false;
	try {
		String url="file://"+getTestPath()+"foo%5e%25bar";
		
		FileConnection conn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
		try {
			addOperationDesc("Using file url: " + url);
			
			String name = conn.getName();
			addOperationDesc("getName() returned " + name);
			
			passed = "foo^%bar".equals(name);
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests getName() on an encoded file URL", passed);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:27,代码来源:GetName.java

示例13: 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);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:37,代码来源:GetURL.java

示例14: test0007

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
 * Streams can be opened and closed more than once on a connection calling openOutputStream(long)
 */
public void test0007() {
	boolean passed = false;
	try {
		FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
		OutputStream stream = null;
		try {
			addOperationDesc("Creating file: " + conn.getURL());
			ensureFileExists(conn);
			
			addOperationDesc("Opening stream");
			stream = conn.openOutputStream(0);
			addOperationDesc("Closing stream");
			stream.close();
			stream = null;

			addOperationDesc("Opening stream");
			stream = conn.openOutputStream(0);
			addOperationDesc("Closing stream");
			stream.close();
			stream = null;
			
			passed = true;
		} finally {
			if (stream!=null) stream.close();				
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Streams can be opened and closed more than once on a connection calling openOutputStream(long)", passed);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:37,代码来源:OpenOutputStream_Long.java

示例15: test0002

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
 * Tests Connector.open() with a valid file url in Connector.READ mode
 */
public void test0002() {
	boolean passed = false;
	try {	
		FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ);
		passed = true;									
		conn.close();
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}
	assertTrueWithLog("Tests Connector.open() with a valid file url in Connector.READ mode", passed);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:16,代码来源:Open.java


注:本文中的javax.microedition.io.file.FileConnection.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。