Methods Summary |
---|
public native long | availableSize()Determines the free memory that is available on the file system the file
or directory resides on. This may only be an estimate and may vary based
on platform-specific file system blocking and metadata information.
|
public native boolean | canRead()Check is file corresponding to this filehandler exists and has a
read permission.
|
public native boolean | canWrite()Check is file corresponding to this filehandler exists and has a
write permission.
|
public native void | close()Close file associated with this handler. Open file and all system
resources should be released by this call. Handler object can be
reused by subsequent call to connect().
|
private native void | closeDir(long dirHandle)Closes the directory.
|
public native void | closeForRead()Closes the file for reading.
|
public native void | closeForReadWrite()Closes the file for both reading and writing.
|
public native void | closeForWrite()Closes the file for writing.
|
public void | connect(java.lang.String rootName, java.lang.String fileName)Connect file handler to the abstract file target. This operation should
not trigger any access to the native filesystem.
initialize();
illegalChars = illegalFileNameChars0();
if (illegalChars == null) {
illegalChars = "";
}
if (rootName == null || rootName.length() == 0) {
return;
}
String rootPath = getNativePathForRoot(rootName);
if (rootPath != null) {
StringBuffer name = new StringBuffer(rootPath);
int curr = name.length();
this.rootDir = getNativeName(rootPath, this.rootDir);
// we add '1' because 'fileName' unlike 'rootName'
// has leading '/'
int fileNameLen = fileName.length();
if (fileName != null && fileNameLen != 0) {
name.append(fileName.substring(rootName.length() + 1));
}
String privateDirURL = System.getProperty("fileconn.dir.private");
if (privateDirURL != null) {
int privateDirURLLen = privateDirURL.length();
if (fileName.regionMatches(true, 0, privateDirURL, 7,
privateDirURLLen - 7)) {
name.insert(curr + privateDirURLLen - rootName.length() - 8,
getSuiteID() + getFileSeparator());
}
}
pathToNativeSeparator(name, curr, name.length() - curr);
this.fileName = getNativeName(name.toString(), this.fileName);
}
|
public native void | create()Create file corresponding to this file handler. The
file is created immediately on the actual file system upon invocation of
this method. Files are created with zero length and data can be put
into the file through write method after opening the file. This method
does not create any directories specified in the file's path.
|
public void | createPrivateDir(java.lang.String rootName)Creates dedicated private working directory for the MIDlet suite.
Does nothing if specified root is not private root or the directory
already exists.
// create private directory if necessary
String privateDir = System.getProperty("fileconn.dir.private");
if (privateDir != null) {
privateDir = privateDir.substring(7);
if (!privateDirExists && rootName.regionMatches(true, 0, privateDir,
1, rootName.length())) {
BaseFileHandler fh = new DefaultFileHandler();
fh.connect(rootName, privateDir);
if (!fh.exists()) {
fh.mkdir();
}
privateDirExists = true;
}
}
|
public native void | delete()Deletes the file or directory associated with this handler.
The file or directory is deleted immediately on
the actual file system upon invocation of this method. Previously open
native file should be closed.The
handler instance object remains connected and available for use.
|
private native java.lang.String | dirGetNextFile(long dirHandle, boolean includeHidden)Gets the next file in directory.
|
public native long | directorySize(boolean includeSubDirs)Determines the size in bytes on a file system of all of the files
that are contained in a directory.
|
public native boolean | exists()Check is file or directory corresponding to this filehandler exists.
|
public native long | fileSize()Determines the size of a file on the file system. The size of a file
always represents the number of bytes contained in the file; there is
no pre-allocated but empty space in a file. Users should perform an
explicit flush() on any open output streams to the file
prior to invoking this method to ensure accurate results.
|
private boolean | filterAccept(java.lang.String filter, java.lang.String str)Check that given string matches the given filter. Filter is defined by
the FileConnection spec as follows:
String against which all files and directories are
matched for retrieval. An asterisk ("*") can be used as a
wildcard to represent 0 or more occurrences of any character.
Filter value of null matches any string.
if (filter == null) {
return true;
}
if (filter.length() == 0) {
return false;
}
int currPos = 0;
int currComp = 0, firstSigComp = 0;
int idx;
// Splitted string does not contain separators themselves
String components[] = split(filter, '*", 0);
// if filter does not begin with '*' check that string begins with
// filter's first component
if (filter.charAt(0) != '*") {
if (!str.startsWith(components[0])) {
return false;
} else {
currPos += components[0].length();
currComp++;
firstSigComp = currComp;
}
}
// Run on the string and check that it contains all filter
// components sequentially
for (; currComp < components.length; currComp++) {
if ((idx = str.indexOf(components[currComp], currPos)) != -1) {
currPos = idx + components[currComp].length();
} else {
// run out of the string while filter components remain
return false;
}
}
// At this point we run out of filter. First option is that
// filter ends with '*', or string is finished,
// we are fine then, and accept the string.
//
// In the other case we check that string ends with the last component
// of the filter (given that there was an asterisk before the last
// component
if (!(filter.charAt(filter.length() - 1) == '*"
|| currPos == str.length())) {
if (components.length > firstSigComp) {
// does string end with the last filter component?
if (!str.endsWith(components[components.length - 1])) {
return false;
}
} else {
// there was no asteric before last filter component
return false;
}
}
// If we got here string is accepted
return true;
|
private native void | finalize()Cleanup after garbage collected instance
|
public native void | flush()Flushes any output to the file.
|
public static native char | getFileSeparator()Gets the system-dependent file separator character.
|
private native java.lang.String | getMountedRoots()Gets the mounted root file systems.
|
private static native long | getNativeName(java.lang.String name, long oldName)Return pointer to the system-dependent file name stored in the native
code.
|
private native java.lang.String | getNativePathForRoot(java.lang.String root)Gets OS path for the specified file system root.
|
private java.lang.String | getSuiteID()Returns ID of the current MIDlet suite in 8-digit reverse hexadecimal
form (the same form is used in native code).
MIDletSuite midletSuite =
MIDletStateHandler.getMidletStateHandler().getMIDletSuite();
StringBuffer id = new StringBuffer(Integer.toHexString(midletSuite.getID()));
int len = id.length();
while (len++ < 8) {
id.insert(0, '0");
}
return id.reverse().toString();
|
public java.lang.String | illegalFileNameChars()Returns a string that contains all characters forbidden for the use on
the given platform except "/" (forward slash) which is always considered
illegal. If there are no such characters an empty string is returned.
return illegalChars;
|
private static native java.lang.String | illegalFileNameChars0()Gets the list of illegal characters in file names.
|
private static native void | initialize()Initializes native part of file handler.
|
public native boolean | isDirectory()Check is file corresponding to this filehandler exists and is a
directory.
|
public boolean | isHidden()Check is file corresponding to this filehandler exists and is
hidden.
// Note: ANSI C does not define hidden files.
// Sure, on UNIX systems a file is considered to be hidden
// if its name begins with a period character ('.'), but we can not
// rename files during setHidden() method, so we consider
// what hidden files are not supported on UNIX systems, and this method
// always returns false on UNIX as it's required by JSR 75 spec.
return isHidden0();
|
private native boolean | isHidden0()Helper method that checks if the file is visible.
|
public native long | lastModified()Returns the time that the file denoted by this file handler
was last modified.
|
public java.util.Vector | list(java.lang.String filter, boolean includeHidden)Gets a filtered list of files and directories contained in a directory.
The directory is the handler's target as specified in
create() .
Vector list = new Vector();
long dirHandle = openDir();
String fname = dirGetNextFile(dirHandle, includeHidden);
while (fname != null) {
// cleanname is passed to the filter and does not contain trailing
// slash denoting directory
String cleanname;
if (fname.charAt(fname.length() - 1) == '/") {
cleanname = fname.substring(0, fname.length() - 1);
} else {
cleanname = fname;
}
if (filterAccept(filter, cleanname)) {
list.addElement(fname);
}
fname = dirGetNextFile(dirHandle, includeHidden);
}
closeDir(dirHandle);
return list;
|
public java.util.Vector | listRoots()List filesystem roots available on the device. For the description of
the correct root format see FileConnection documentation.
Vector roots = new Vector();
String s = getMountedRoots();
if (s != null) {
String[] rs = com.sun.kvem.midp.pim.formats.FormatSupport
.split(s, '\n", 0);
for (int i = 0; i < rs.length; i++) {
roots.addElement(rs[i]);
}
}
return roots;
|
public native void | mkdir()Creates a directory corresponding to the directory
string provided in the connect() method.
The directory is created immediately on the actual
file system upon invocation of this method. Directories in the
specified path are not recursively created and must be explicitly
created before subdirectories can be created.
|
private native long | openDir()Opens the directory.
|
public native void | openForRead()Opens the file for reading.
|
public native void | openForWrite()Opens the file for writing.
|
private java.lang.StringBuffer | pathToNativeSeparator(java.lang.StringBuffer name, int off, int len)Replace all entries of the "//" with "/" (multiple separators
with single separator) and all "/" with the native separator.
int length = off + len;
int curr = off;
char sep = getFileSeparator();
while ((curr + 1) < length) {
if (name.charAt(curr) == '/" && name.charAt(curr+1) == '/") {
name.deleteCharAt(curr);
length--;
continue;
} else if (name.charAt(curr) == '/") {
name.setCharAt(curr, sep);
}
curr++;
}
// trim trailing slash if it exists
if (name.charAt(length - 1) == '/") {
name.deleteCharAt(length - 1);
}
return name;
|
public native void | positionForWrite(long offset)Sets the next write location.
|
public native int | read(byte[] b, int off, int len)Reads data from the file to an array.
|
public void | rename(java.lang.String newName)Renames the selected file or directory to a new name in the same
directory. The file or directory is renamed immediately on the actual
file system upon invocation of this method. No file or directory by the
original name exists after this method call. Previously open native file
should be closed. The handler
instance object remains connected and available for use,
referring now to the file or directory by its new name.
// we start search of '/' from '1' to skip leading '/'
// that means local machine in URL specification
int rootEnd = newName.indexOf('/", 1);
String rootName = newName.substring(1, rootEnd + 1);
if (rootName.length() == 0) {
return;
}
String rootPath = getNativePathForRoot(rootName);
if (rootPath != null)
{
StringBuffer name = new StringBuffer(rootPath);
int curr = name.length();
String newNameWORoot = newName.substring(rootEnd + 1);
name.append(newNameWORoot);
String privateDirURL = System.getProperty("fileconn.dir.private");
if (privateDirURL != null) {
int privateDirURLLen = privateDirURL.length();
if (newName.regionMatches(true, 0, privateDirURL, 7,
privateDirURLLen - 7)) {
name.insert(curr + privateDirURLLen - rootName.length() - 8,
getSuiteID() + getFileSeparator());
}
}
pathToNativeSeparator(name, curr, name.length() - curr);
rename0(name.toString());
}
|
private native void | rename0(java.lang.String newName)Helper method that renames the file.
|
public void | setHidden(boolean hidden)Sets the hidden attribute of the file associated with this file handler
to the value provided. The attribute is applied to the file on the
actual file system immediately upon invocation of this method if the
file system
and platform support it. If the file system doesn't support a hidden
attribute, this method is ignored and isHidden() always
returns false. Since the exact definition of hidden is
system-dependent,
this method only works on file systems that support a settable file
attribute. For example, on Win32 and FAT file systems, a file may be
considered hidden if it has been marked as such in the file's
attributes; therefore this method is applicable. However on UNIX
systems a file may be considered to be hidden if its name begins with a
period character ('.'). In the UNIX case, this method may be ignored and
the method to make a file hidden may be the rename()
method.
setHidden0(hidden);
|
private native void | setHidden0(boolean hidden)Helper method that marks the file hidden flag.
|
public native void | setReadable(boolean readable)Sets the file or directory readable attribute to the
indicated value. The readable attribute for the file on the actual
file system is set immediately upon invocation of this method. If the
file system doesn't support a settable read attribute, this method is
ignored and canRead() always returns true.
|
public native void | setWritable(boolean writable)Sets the file or directory associated with this file handler writable
attribute to the
indicated value. The writable attribute for the file on the actual
file system is set immediately upon invocation of the method. If the
file system doesn't support a settable write attribute, this method is
ignored and canWrite() always returns true.
|
private static java.lang.String[] | split(java.lang.String data, char separatorChar, int startingPoint)Parses a separated list of strings into a string array.
An escaped separator (backslash followed by separatorChar) is not
treated as a separator.
if (startingPoint == data.length()) {
return new String[0];
}
Vector elementList = new Vector();
if (data.charAt(startingPoint) == separatorChar) {
startingPoint++;
}
int startSearchAt = startingPoint;
int startOfElement = startingPoint;
for (int i; (i = data.indexOf(separatorChar, startSearchAt)) != -1; ) {
if (i != 0 && data.charAt(i - 1) == '\\") {
// escaped semicolon. don't treat it as a separator
startSearchAt = i + 1;
} else {
String element = data.substring(startOfElement, i);
elementList.addElement(element);
startSearchAt = startOfElement = i + 1;
}
}
if (data.length() > startOfElement) {
if (elementList.size() == 0) {
return new String[] { data.substring(startOfElement) };
}
elementList.addElement(data.substring(startOfElement));
}
String[] elements = new String[elementList.size()];
for (int i = 0; i < elements.length; i++) {
elements[i] = (String) elementList.elementAt(i);
}
return elements;
|
public native long | totalSize()Determines the total size of the file system the connection's target
resides on.
|
public native void | truncate(long byteOffset)Truncates the file, discarding all data from the given byte offset to
the current end of the file. If the byte offset provided is greater
than or equal to the file's current byte count, the method returns
without changing the file.
|
public long | usedSize()Determines the used memory of a file system the connection's target
resides on. This may only be an estimate and may vary based
on platform-specific file system blocking and metadata information.
return totalSize() - availableSize();
|
public native int | write(byte[] b, int off, int len)Write data from an array to the file.
|