本文整理汇总了Java中javax.microedition.io.file.FileConnection.fileSize方法的典型用法代码示例。如果您正苦于以下问题:Java FileConnection.fileSize方法的具体用法?Java FileConnection.fileSize怎么用?Java FileConnection.fileSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.microedition.io.file.FileConnection
的用法示例。
在下文中一共展示了FileConnection.fileSize方法的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);
}
示例2: test0007
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
* Tests fileSize() on a non-existent file
*/
public void test0007() {
boolean passed = false;
try {
FileConnection conn = (FileConnection)Connector.open("file://"+getTestPath()+"test", Connector.READ_WRITE);
try {
addOperationDesc("Deleting file: " + conn.getURL());
ensureNotExists(conn);
long fileSize = conn.fileSize();
addOperationDesc("fileSize() returned " + fileSize);
passed = fileSize==-1;
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests fileSize() on a non-existent file", passed);
}
示例3: 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);
}
示例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);
}
示例5: 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);
}
示例6: test0001
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
* Tests openOutputStream()
*/
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);
OutputStream os = null;
try {
os = conn.openOutputStream();
long fileSize1 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize1);
addOperationDesc("Writing byte to output stream");
os.write(3);
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 openOutputStream()", passed);
}
示例7: 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);
}
示例8: 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);
}
示例9: 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);
}
示例10: 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);
}
示例11: test0013
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
* Tests if the OutputStream returned from openOutputStream(long) updates the file immediately when flush() is called.
*/
public void test0013() {
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 fileSize0 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize0);
os = conn.openOutputStream(0);
addOperationDesc("Writing 64 bytes to output stream");
os.write(new byte[64]);
os.flush();
long fileSize2 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize2);
passed = fileSize2==64;
} finally {
if (os != null) os.close();
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests if the OutputStream returned from openOutputStream(long) updates the file immediately when flush() is called", passed);
}
示例12: read
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
public static byte[] read(String path) {
try {
FileConnection fc = (FileConnection) Connector.open(path, Connector.READ);
InputStream in = fc.openInputStream();
byte[] imageBytes = new byte[(int) fc.fileSize()];
in.read(imageBytes);
in.close();
fc.close();
return imageBytes;
} catch (Exception e) {
return null;
}
}
示例13: test0001
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
* Tests openOutputStream(long)
*/
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);
OutputStream os = null;
try {
long fileSize1 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize1);
addOperationDesc("Opening output stream at offset " + fileSize1);
os = conn.openOutputStream(fileSize1);
addOperationDesc("Writing two bytes to output stream");
os.write(3);
os.write(3);
addOperationDesc("Closing output stream");
os.close();
long fileSize2 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize2);
addOperationDesc("Opening output stream at offset " + (fileSize2-1));
os = conn.openOutputStream(fileSize2-1);
addOperationDesc("Writing two bytes to output stream");
os.write(3);
os.write(3);
addOperationDesc("Closing output stream");
os.close();
long fileSize3 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize3);
passed = fileSize2==fileSize1+2 && fileSize3==fileSize2+1;
} finally {
if (os != null) os.close();
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests openOutputStream(long)", passed);
}
示例14: test0011
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
* Tests openOutputStream(long) with an offset equal to the fileSize
*/
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);
addOperationDesc("Opening output stream at offset " + fileSize1);
os = conn.openOutputStream(fileSize1);
addOperationDesc("Writing two bytes to output stream");
os.write(3);
os.write(3);
addOperationDesc("Closing output stream");
os.close();
long fileSize2 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize2);
addOperationDesc("Opening output stream at offset " + fileSize2);
os = conn.openOutputStream(fileSize2);
addOperationDesc("Writing two bytes to output stream");
os.write(3);
os.write(3);
addOperationDesc("Closing output stream");
os.close();
long fileSize3 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize3);
passed = fileSize2==fileSize1+2 && fileSize3==fileSize2+2;
} finally {
if (os != null) os.close();
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests openOutputStream(long) with an offset larger than fileSize", passed);
}
示例15: test0012
import javax.microedition.io.file.FileConnection; //导入方法依赖的package包/类
/**
* Tests openOutputStream(long) with an offset larger than fileSize
*/
public void test0012() {
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);
addOperationDesc("Opening output stream at offset " + (fileSize1+3));
os = conn.openOutputStream(fileSize1+3);
addOperationDesc("Writing two bytes to output stream");
os.write(3);
os.write(3);
addOperationDesc("Closing output stream");
os.close();
long fileSize2 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize2);
addOperationDesc("Opening output stream at offset " + (fileSize2+7));
os = conn.openOutputStream(fileSize2+7);
addOperationDesc("Writing two bytes to output stream");
os.write(3);
os.write(3);
addOperationDesc("Closing output stream");
os.close();
long fileSize3 = conn.fileSize();
addOperationDesc("fileSize() is " + fileSize3);
passed = fileSize2==fileSize1+2 && fileSize3==fileSize2+2;
} finally {
if (os != null) os.close();
}
} finally {
conn.close();
}
} catch (Exception e) {
logUnexpectedExceptionDesc(e);
passed = false;
}
assertTrueWithLog("Tests openOutputStream(long) with an offset larger than fileSize", passed);
}