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


Java FileConnection.openOutputStream方法代码示例

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


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

示例1: openOutputStream

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
 * @inheritDoc
 */
public OutputStream openOutputStream(Object connection) throws IOException {
    if(connection instanceof String) {
        FileConnection fc = (FileConnection)Connector.open((String)connection, Connector.READ_WRITE);
        if(!fc.exists()) {
            fc.create();
        }
        BufferedOutputStream o = new BufferedOutputStream(fc.openOutputStream(), (String)connection);
        o.setConnection(fc);
        return o;
    }
    return new BufferedOutputStream(((HttpConnection)connection).openOutputStream(), ((HttpConnection)connection).getURL());
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:16,代码来源:GameCanvasImplementation.java

示例2: openOutputStream

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
 * @inheritDoc
 */
public OutputStream openOutputStream(Object connection) throws IOException {
    if (connection instanceof String) {
        FileConnection fc = (FileConnection) Connector.open((String) connection, Connector.READ_WRITE);
        if (!fc.exists()) {
            fc.create();
        }
        BufferedOutputStream o = new BufferedOutputStream(fc.openOutputStream(), (String) connection);
        o.setConnection(fc);
        return o;
    }
    OutputStream os = new BlackBerryOutputStream(((HttpConnection) connection).openOutputStream());
    return new BufferedOutputStream(os, ((HttpConnection) connection).getURL());
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:17,代码来源:BlackBerryImplementation.java

示例3: getOutputStream

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
public OutputStream getOutputStream() throws IOException {
    FileConnection connector = connector();
    if(!connector.exists()) {
        this.createConnectorAndPath(connector);
    } else {
        //TODO: Delete exist file, maybe? Probably....
    }
    OutputStream os = connector.openOutputStream();
    clearReferenceConnection(getLocalURI());
    return os;
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:12,代码来源:J2meFileReference.java

示例4: runBenchmark

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
void runBenchmark() {
    try {
        long start;

        String dirPath = System.getProperty("fileconn.dir.private");
        FileConnection file = (FileConnection)Connector.open(dirPath + "test");
        if (file.exists()) {
            file.delete();
        }
        file.create();

        OutputStream fileOut = file.openOutputStream();
        start = JVM.monotonicTimeMillis();
        writeUTF(fileOut);
        System.out.println("DataOutputStream::writeUTF in file: " + (JVM.monotonicTimeMillis() - start));

        InputStream fileIn = file.openInputStream();
        start = JVM.monotonicTimeMillis();
        readUTF(fileIn);
        System.out.println("DataInputStream::readUTF from file: " + (JVM.monotonicTimeMillis() - start));

        file.close();
    } catch (IOException e) {
        System.out.println("Unexpected exception: " + e);
        e.printStackTrace();
    }
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:28,代码来源:DataInputOutputStreamFileBench.java

示例5: test0001

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
public void test0001() {
	boolean passed = false;
	try {	
		FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
		OutputStream os = null;
		try {
			addOperationDesc("Creating file: " + conn.getURL());
			ensureFileExists(conn);
			
			long availableSize = conn.availableSize();
			addOperationDesc("first availableSize() call returned " + availableSize);

			int incrementSize = 4096;
			byte buf[] = new byte[incrementSize];
			os = conn.openOutputStream();
			for (int i=0; i<4; i++) {
				addOperationDesc("writing " + incrementSize + " bytes to disk");
				os.write(buf);
			}
			os.close();
			os = null;

			long availableSize2 = conn.availableSize();
			addOperationDesc("second availableSize() call returned " + availableSize2 + " (should be less than first call)");
			
			passed = availableSize2<availableSize;									
		} finally {
			if (os != null) os.close();
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}
	assertTrueWithLog("Tests availableSize()", passed);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:37,代码来源:AvailableSize.java

示例6: test0001

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
 * Tests openInputStream()
 */
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);
			
			InputStream is = null;
			OutputStream os = null;
			try {
				addOperationDesc("Writing byte to output stream: 69");
				os = conn.openOutputStream();
				os.write(69);
				os.flush();
				
				is = conn.openInputStream();
				int result = is.read();
				addOperationDesc("Reading byte from input stream: " + result);
				
				passed = result==69;
			} finally {
				if (is != null) is.close();
				if (os != null) os.close();
			}
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests openInputStream()", passed);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:39,代码来源:OpenInputStream.java

示例7: test0002

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
 * Tests fileSize() on a file with an open OutputStream
 */
public void test0002() {
	boolean passed = false;
	try {
		FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE); 
		OutputStream os =null;
		try {				
			addOperationDesc("Creating file with a size of 0 bytes: " + conn.getURL());
			ensureFileExists(conn);
			
			addOperationDesc("Opening output stream on file");
			os = conn.openOutputStream();
			addOperationDesc("Writing and flushing 64 bytes to file");
			os.write(new byte[64]);
			os.flush();
			
			long fileSize = conn.fileSize();
			addOperationDesc("fileSize() returned " + fileSize);
		
			passed = fileSize==64;
		} finally {
			if (os!=null) os.close();
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

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

示例8: ensureFileSize

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
protected void ensureFileSize(FileConnection conn, int fileSize) throws IOException {
	OutputStream os = conn.openOutputStream();
	try {
		os.write(new byte[fileSize]);
		os.flush();
	} finally {
		os.close();
	}
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:10,代码来源:FileSize.java

示例9: openOutputStream

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
 * @inheritDoc
 */
public OutputStream openOutputStream(Object connection, int offset) throws IOException {
    FileConnection fc = (FileConnection) Connector.open((String) connection, Connector.READ_WRITE);
    if (!fc.exists()) {
        fc.create();
    }
    BufferedOutputStream o = new BufferedOutputStream(fc.openOutputStream(offset), (String) connection);
    o.setConnection(fc);
    return o;
}
 
开发者ID:shannah,项目名称:cn1,代码行数:13,代码来源:BlackBerryImplementation.java

示例10: test0001

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
 * Tests usedSize()
 */
public void test0001() {
	boolean passed = false;
	try {	
		FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
		OutputStream os = null;
		try {
			addOperationDesc("Creating file: " + conn.getURL());
			ensureFileExists(conn);
			
			long usedSize = conn.usedSize();
			addOperationDesc("first usedSize() call returned " + usedSize);

			int incrementSize = 4096;
			addOperationDesc("writing " + incrementSize + " bytes to disk");
			os = conn.openOutputStream();
			os.write(new byte[incrementSize]);
			os.close();
			os = null;

			long usedSize2 = conn.usedSize();
			addOperationDesc("second usedSize() call returned " + usedSize2 + " (should be more than first call)");
			
			passed = usedSize2>usedSize;									
		} finally {
			if (os != null) os.close();
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}
	assertTrueWithLog("Tests usedSize()", passed);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:37,代码来源:UsedSize.java

示例11: test0007

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
 * Streams can be opened and closed more than once on a connection calling openOutputStream()
 */
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();
			addOperationDesc("Closing stream");
			stream.close();
			stream = null;

			addOperationDesc("Opening stream");
			stream = conn.openOutputStream();
			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()", passed);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:37,代码来源:OpenOutputStream.java

示例12: test0011

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
 * Tests if the OutputStream returned from openOutputStream() updates the file immediately when flush() is called.
 */
public void test0011() {
	boolean passed = false;
	try {
		FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
		try {
			addOperationDesc("Creating file: " + conn.getURL());
			ensureFileExists(conn);

			OutputStream os = null;
			try {
				
				long fileSize1 = conn.fileSize();
				addOperationDesc("fileSize() is " + fileSize1);

				os = conn.openOutputStream();
									
				addOperationDesc("Writing 1024 bytes to output stream");
				os.write(new byte[1024]);
				os.flush();
				
				long fileSize2 = conn.fileSize();
				addOperationDesc("fileSize() is " + fileSize2);
				
				passed = fileSize2==1024;
			} finally {
				if (os != null) os.close();
			}
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

	assertTrueWithLog("Tests if the OutputStream returned from openOutputStream() updates the file immediately when flush() is called", passed);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:41,代码来源:OpenOutputStream.java

示例13: test0001

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
 * Tests truncate()
 */
public void test0001() {
	boolean passed = false;
	try {
		FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
		OutputStream os = null;
		try {
			addOperationDesc("Creating file: " + conn.getURL());
			ensureFileExists(conn);
			
			addOperationDesc("Writing 8 bytes");
			os = conn.openOutputStream();
			os.write(new byte[8]);
			os.close();
			os = null;
			
			addOperationDesc("Truncating at byte 1");
			conn.truncate(1);
			
			long fileSize = conn.fileSize();
			addOperationDesc("fileSize() returned " + fileSize);
			
			passed = fileSize==1;
		} finally {
			if (os != null) os.close();
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}
	
	assertTrueWithLog("Tests truncate()", passed);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:37,代码来源:Truncate.java

示例14: test0002

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
 * Tests truncate() where byteOffset is greater than the current end of file
 */
public void test0002() {
	boolean passed = false;
	try {
		FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
		OutputStream os = null;
		try {
			addOperationDesc("Creating file: " + conn.getURL());
			ensureFileExists(conn);
			
			addOperationDesc("Writing 8 bytes");
			os = conn.openOutputStream();
			os.write(new byte[8]);
			os.close();
			os = null;
			
			addOperationDesc("Truncating at byte 10");
			conn.truncate(10);
			
			long fileSize = conn.fileSize();
			addOperationDesc("fileSize() returned " + fileSize);
			
			passed = fileSize==8;
		} finally {
			if (os != null) os.close();
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}
	
	assertTrueWithLog("Tests truncate() where byteOffset is greater than the current end of file", passed);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:37,代码来源:Truncate.java

示例15: test0011

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
 * Tests if a file is truncated properly even if an open outputstream is not explicitly flushed by the user 
 */
public void test0011() {
	boolean passed = false;
	try {
		FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
		OutputStream os = null;
		try {
			addOperationDesc("Creating file: " + conn.getURL());
			ensureFileExists(conn);
			
			addOperationDesc("Writing 8 bytes");
			os = conn.openOutputStream();
			os.write(new byte[8]);				
								
			addOperationDesc("Truncating at byte 7");
			conn.truncate(7);
			
			long fileSize = conn.fileSize();
			addOperationDesc("fileSize() returned " + fileSize);
			
			passed = fileSize==7;
		} finally {
			if (os != null) os.close();
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}
	
	assertTrueWithLog("Tests if a file is truncated properly even if an open outputstream is not explicitly flushed by the user", passed);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:35,代码来源:Truncate.java


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