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


Java FileConnection.openDataOutputStream方法代码示例

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


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

示例1: 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

示例2: test0001

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
 * Tests openDataOutputStream()
 */
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);

			DataOutputStream os = null;
			try {
				os = conn.openDataOutputStream();
				
				long fileSize1 = conn.fileSize();
				addOperationDesc("fileSize() is " + fileSize1);
				
				addOperationDesc("Writing int to output stream");
				os.writeInt(2);
				addOperationDesc("Closing output stream");
				os.close();
				os = null;
				
				long fileSize2 = conn.fileSize();
				addOperationDesc("fileSize() is " + fileSize2);
				
				passed = fileSize2>fileSize1;
			} finally {
				if (os != null) os.close();
			}
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

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

示例3: test0007

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

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

示例4: test0011

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
 * Tests if the DataOutputStream returned from openDataOutputStream() 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);

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

				os = conn.openDataOutputStream();
									
				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 DataOutputStream returned from openDataOutputStream() updates the file immediately when flush() is called", passed);
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:41,代码来源:OpenDataOutputStream.java

示例5: test0001

import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
 * Tests openDataInputStream()
 */
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);
			
			DataInputStream is = null;
			DataOutputStream os = null;
			try {
				addOperationDesc("Writing UTF string to output stream: foobar");
				os = conn.openDataOutputStream();
				os.writeUTF("foobar");
				os.close();
				os = null;
				
				is = conn.openDataInputStream();
				String result = is.readUTF();
				addOperationDesc("Reading UTF string from input stream: " + result);
				
				passed = result.equals("foobar");
			} finally {
				if (is != null) is.close();
				if (os != null) os.close();
			}
		} finally {
			conn.close();
		}
	} catch (Exception e) {
		logUnexpectedExceptionDesc(e);
		passed = false;
	}

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

示例6: runBenchmark

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

      client = (LocalMessageProtocolConnection)Connector.open("localmsg://nokia.image-processing");

      DataEncoder dataEncoder = new DataEncoder("Conv-BEB");
      dataEncoder.putStart(14, "event");
      dataEncoder.put(13, "name", "Common");
      dataEncoder.putStart(14, "message");
      dataEncoder.put(13, "name", "ProtocolVersion");
      dataEncoder.put(10, "version", "1.[0-10]");
      dataEncoder.putEnd(14, "message");
      dataEncoder.putEnd(14, "event");
      byte[] sendData = dataEncoder.getData();
      client.send(sendData, 0, sendData.length);

      LocalMessageProtocolMessage msg = client.newMessage(null);
      client.receive(msg);

      FileConnection originalImage = (FileConnection)Connector.open("file:////test.jpg", Connector.READ_WRITE);
      if (!originalImage.exists()) {
          originalImage.create();
      }
      OutputStream os = originalImage.openDataOutputStream();
      InputStream is = getClass().getResourceAsStream("/org/mozilla/io/test.jpg");
      os.write(TestUtils.read(is));
      os.close();

      MemorySampler.sampleMemory("Memory before nokia.image-processing benchmark");
      for (int i = 0; i < 1000; i++) {
        start = JVM.monotonicTimeMillis();
        String path = scaleImage();
        time += JVM.monotonicTimeMillis() - start;

        FileConnection file = (FileConnection)Connector.open(path);
        file.delete();
        file.close();
      }
      System.out.println("scaleImage: " + time);
      MemorySampler.sampleMemory("Memory after nokia.image-processing benchmark");

      originalImage.delete();
      originalImage.close();

      client.close();
  } catch (IOException e) {
    e.printStackTrace();
  }
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:51,代码来源:ImageProcessingBench.java


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