本文整理汇总了Java中javax.microedition.io.file.FileConnection.create方法的典型用法代码示例。如果您正苦于以下问题:Java FileConnection.create方法的具体用法?Java FileConnection.create怎么用?Java FileConnection.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.microedition.io.file.FileConnection
的用法示例。
在下文中一共展示了FileConnection.create方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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");
}
}
示例2: generateData
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
void generateData() throws IOException {
String str = "";
String part = "abcdefghilmnopqrstuvzABCDEFGHILMNOPQRSTUVZabcdefghilmnopqrstuvzABCDEFGHILMNOPQRSTUVZ";
for (int i = 0; i < 2000; i++) {
str += part;
}
cbuf = new char[str.length()];
cbufReader = new char[cbuf.length];
str.getChars(0, str.length(), cbuf, 0);
String dirPath = System.getProperty("fileconn.dir.private");
file = (FileConnection)Connector.open(dirPath + "test");
if (file.exists()) {
file.delete();
}
file.create();
}
示例3: 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());
}
示例4: 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);
}
示例5: 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());
}
示例6: 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());
}
示例7: 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();
}
}
示例8: 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() + ")");
}
}
示例9: save
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
public static boolean save(byte[] bytes, String filename) {
String path = "file://";
if (DeviceMemory.useSDCard() && !DeviceMemory.forceInternalMemory) {
path += "/SDCard/vika/";
} else {
path += "/store/home/user/vika/";
}
boolean result = DeviceMemory.makeDirectory(path);
/*
* if (!result && useSDCard() && !forceInternalMemory) { forceInternalMemory = true; return
* save(bytes, filename); }
*/
if (!result) {
return false;
}
path += filename;
try {
FileConnection fc = (FileConnection) Connector.open(path, Connector.READ_WRITE);
if (!fc.exists()) {
fc.create();
}
OutputStream out = fc.openOutputStream();
out.write(bytes);
out.close();
fc.close();
return true;
} catch (IOException e) {
return false;
}
}
示例10: 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();
}
}
示例11: openFileConnection
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
* Opens the {@link FileConnection} and a {@link PrintStream}.
*
* @param filenamePrefix prefix of the filename part of the file path.
* @param append if <code>true</code> then don't use timestamp in the filename but append to existing log file.
* @throws IOException if a file could not be created.
* @throws SecurityException if no permission was given to create a file.
* @throws NullPointerException if <code>filenamePrefix</code> is <code>null</code>.
*/
private static void openFileConnection(String filenamePrefix, boolean append)
throws IOException, SecurityException
{
if (!System.getProperty("microedition.io.file.FileConnection.version").equals("1.0")) {
// FileConnection API version 1.0 isn't supported.
// Probably a bit unnecessary check as if it isn't supported
// a ClassNotFoundException would have been thrown earlier.
throw new IOException("FileConnection not available");
}
final String filename = createLogFilename(filenamePrefix, !append);
final String[] pathProperties = {"fileconn.dir.memorycard", "fileconn.dir.recordings"};
String path = null;
// Attempt to create a file to the directories specified by the
// system properties in array pathProperties.
for (int i = 0; i < pathProperties.length; i++) {
path = System.getProperty(pathProperties[i]);
// Only throw declared exceptions if this is the last path
// to try.
try {
if (path == null) {
if (i < (pathProperties.length - 1)) {
continue;
} else {
throw new IOException("Path not available: " + pathProperties[i]);
}
}
FileConnection fConn = (FileConnection)
Connector.open(path + filename, Connector.READ_WRITE);
OutputStream os = null;
if (append) {
if (!fConn.exists()) {
fConn.create();
}
os = fConn.openOutputStream(fConn.fileSize());
} else {
// Assume that createLogFilename creates such a filename
// that is enough to separate filenames even if they
// are created in a short interval (seconds).
fConn.create();
os = fConn.openOutputStream();
}
streams[FILE_INDX] = new PrintStream(os);
// Opening the connection and stream was successful so don't
// try other paths.
fileConn = fConn;
break;
} catch (SecurityException se) {
if (i == (pathProperties.length - 1)) {
throw se;
}
} catch (IOException ioe) {
if (i == (pathProperties.length - 1)) {
throw ioe;
}
}
}
}
示例12: test
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
public void test(TestHarness th) {
try {
FileConnection file = (FileConnection)Connector.open("file:////prova");
if (file.exists()) {
file.delete();
}
file.create();
RandomAccessStream ras = new RandomAccessStream();
ras.connect("prova", Connector.READ_WRITE);
OutputStream out = ras.openOutputStream();
testWrite(th, out);
out.close();
ras.setPosition(0);
InputStream in = ras.openInputStream();
testRead(th, in);
in.close();
ras.disconnect();
file.delete();
th.check(!file.exists());
file.create();
out = file.openOutputStream();
testWrite(th, out);
out.close();
in = file.openInputStream();
testRead(th, in);
in.close();
file.delete();
file.close();
} catch (Exception e) {
th.fail("Unexpected exception: " + e);
e.printStackTrace();
}
}