The main practical use for a file descriptor is to create a OWFileInputStream
or OWFileOutputStream
to contain it.
Applications should not create their own file descriptors.
Public Member Functions | |
OWFileDescriptor () | |
Construct an invalid 1-Wire FileDescriptor. | |
boolean | valid () |
Tests if this file descriptor object is valid. | |
void | sync () throws OWSyncFailedException |
Force all system buffers to synchronize with the underlying device. | |
Protected Member Functions | |
OWFileDescriptor (OneWireContainer owd, String newPath) | |
Construct a 1-Wire FileDescrioptor providing the Filesystem 1-Wire device and file path. | |
OWFileDescriptor (OneWireContainer[] owd, String newPath) | |
Construct a 1-Wire FileDescrioptor providing the Filesystem 1-Wire device and file path. | |
void | setupFD (OneWireContainer[] owd, String newPath) |
Setups the 1-Wire FileDescrioptor providing the Filesystem 1-Wire device(s) and file path. | |
void | open () throws OWFileNotFoundException |
Opens the file for reading. | |
void | close () throws IOException |
Closes this file descriptor and releases any system resources associated with this stream. | |
void | create (boolean append, boolean isDirectory, boolean makeParents, int startPage, int numberPages) throws OWFileNotFoundException |
Creates a directory or file to write. | |
void | format () throws OneWireException, OneWireIOException |
Format the Filesystem on the 1-Wire device. | |
int | read (byte b[], int off, int len) throws IOException |
Reads up to len bytes of data from this input stream into an array of bytes. | |
int | read () throws IOException |
Reads a byte of data from this input stream. | |
long | skip (long n) throws IOException |
Skips over and discards n bytes of data from the input stream. | |
int | available () throws IOException |
Returns the number of bytes that can be read from this file input stream without blocking. | |
void | write (int b) throws IOException |
Writes the specified byte to this file output stream. | |
void | write (byte b[], int off, int len) throws IOException |
Writes len bytes from the specified byte array starting at offset off to this file output stream. | |
String | getName () |
Returns the name of the file or directory denoted by this abstract pathname. | |
String | getParent () |
Returns the pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory. | |
String | getPath () |
Converts this abstract pathname into a pathname string. | |
boolean | exists () |
Checks to see if the file exists. | |
boolean | canRead () |
Checks to see if can read the file associated with this descriptor. | |
boolean | canWrite () |
Checks to see if the file represented by this descriptor is writable. | |
boolean | isDirectory () |
Checks to see if this is a directory. | |
boolean | isFile () |
Checks to see if this is a file. | |
boolean | isHidden () |
Checks to see if this directory is hidden. | |
long | length () |
Get the estimated length of the file represented by this descriptor. | |
boolean | delete () |
Delete this file or directory represented by this descriptor. | |
String[] | list () |
Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname. | |
boolean | renameTo (OWFile dest) |
Renames the file denoted by this abstract pathname. | |
boolean | setReadOnly () |
Marks the file or directory named by this abstract pathname so that only read operations are allowed. | |
void | mark (int readlimit) |
Mark the current position in the file being read for later reference. | |
void | reset () throws IOException |
Reset the the read of this file back to the marked position. | |
void | markPageUsed (int page) throws OneWireException |
Mark the specified page as used in the page bitmap. | |
boolean | freePage (int page) throws OneWireException |
free the specified page as being un-used in the page bitmap | |
int | getFirstFreePage (boolean counterPage) throws OneWireException |
Get the first free page from the page bitmap. | |
int | getNextFreePage (boolean counterPage) throws OneWireException |
Get the next free page from the page bitmap. | |
int | getFreeMemory () throws OneWireException |
Gets the number of bytes available on this device for file and directory information. | |
void | writeBitMap () throws OneWireException |
Write the page bitmap back to the device. | |
void | readBitMap () throws OneWireException |
Read the page bitmap. | |
int[] | getPageList () throws OneWireException |
Get's an array of integers that represents the page list of the file or directory represented by this OWFile. | |
int | getStartPage () throws IOException |
Returns an integer which represents the starting memory page of the file or directory represented by this OWFile. | |
PagedMemoryBank | getMemoryBankForPage (int page) |
Get's the memory bank object for the specified page. | |
int | getLocalPage (int page) |
Get's the local page number on the memory bank object for the specified page. | |
int | verifyDeviceMap (int startPage, int numberOfContainers, boolean setOverdrive) throws OneWireException |
Verify the Device Map of a MASTER device is correct. | |
boolean | createNewFile () throws IOException |
Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist. | |
int | getHashCode () |
Computes a hash code for this abstract pathname. | |
OneWireContainer[] | getOneWireContainers () |
Gets the OneWireContainers that represent this Filesystem. | |
void | free () |
Free's this file descriptors system resources. |
OWFileDescriptor | ( | ) |
Construct an invalid 1-Wire FileDescriptor.
OWFileDescriptor | ( | OneWireContainer | owd, | |
String | newPath | |||
) | [protected] |
Construct a 1-Wire FileDescrioptor providing the Filesystem 1-Wire device and file path.
owd | - 1-Wire container where the filesystem resides | |
newPath | - path containing the file/directory that represents this file descriptor |
OWFileDescriptor | ( | OneWireContainer[] | owd, | |
String | newPath | |||
) | [protected] |
Construct a 1-Wire FileDescrioptor providing the Filesystem 1-Wire device and file path.
owd | - 1-Wire container where the filesystem resides | |
newPath | - path containing the file/directory that represents this file descriptor |
void setupFD | ( | OneWireContainer[] | owd, | |
String | newPath | |||
) | [protected] |
Setups the 1-Wire FileDescrioptor providing the Filesystem 1-Wire device(s) and file path.
owd | - 1-Wire container where the filesystem resides | |
newPath | - path containing the file/directory that represents this file descriptor |
boolean valid | ( | ) |
Tests if this file descriptor object is valid.
true
if the file descriptor object represents a valid, open file, socket, or other active I/O connection; false
otherwise. void sync | ( | ) | throws OWSyncFailedException |
Force all system buffers to synchronize with the underlying device.
This method returns after all modified data and attributes of this FileDescriptor have been written to the relevant device(s). In particular, if this FileDescriptor refers to a physical storage medium, such as a file in a file system, sync will not return until all in-memory modified copies of buffers associated with this FileDesecriptor have been written to the physical medium.
sync is meant to be used by code that requires physical storage (such as a file) to be in a known state For example, a class that provided a simple transaction facility might use sync to ensure that all changes to a file caused by a given transaction were recorded on a storage medium.
sync only affects buffers downstream of this FileDescriptor. If any in-memory buffering is being done by the application (for example, by a BufferedOutputStream object), those buffers must be flushed into the OWFileDescriptor (for example, by invoking OutputStream.flush) before that data will be affected by sync.
This method may be called multiple times if the source of OWSyncFailedException has been rectified (1-Wire device was reattached to the network).
OWSyncFailedException | Thrown when the buffers cannot be flushed, or because the system cannot guarantee that all the buffers have been synchronized with physical media. |
void open | ( | ) | throws OWFileNotFoundException [protected] |
Opens the file for reading.
If successfull (no exceptions) then the following class member variables will be set:
FileNotFoundException | when the file/directory path is invalid or there was an IOException thrown when trying to read the device. |
void close | ( | ) | throws IOException [protected] |
Closes this file descriptor and releases any system resources associated with this stream.
Any cached writes are flushed into the filesystem. This file descriptor may no longer be used for writing bytes. If successfull (no exceptions) then the following class member variables will be set:
IOException | if an I/O error occurs |
void create | ( | boolean | append, | |
boolean | isDirectory, | |||
boolean | makeParents, | |||
int | startPage, | |||
int | numberPages | |||
) | throws OWFileNotFoundException [protected] |
Creates a directory or file to write.
append | for files only, true to append data to end of file, false to reset the file | |
isDirectory | true if creating a directory, false for a file | |
makeParents | true if creating all needed parent directories in order to create the file/directory | |
startPageNum | starting page of file/directory, -1 if not renaming | |
numberPages | number of pages in file/directory, -1 if not renaming |
FileNotFoundException | if file already opened to write, if makeParents=false and parent directories not found, if file is read only, or if there is an IO error reading filesystem |
void format | ( | ) | throws OneWireException, OneWireIOException [protected] |
Format the Filesystem on the 1-Wire device.
WARNING: all files/directories will be deleted in the process.
OneWireException | when adapter is not setup properly | |
OneWireIOException | when an IO error occured reading the 1-Wire device |
int read | ( | byte | b[], | |
int | off, | |||
int | len | |||
) | throws IOException [protected] |
Reads up to len
bytes of data from this input stream into an array of bytes.
This method blocks until some input is available.
b | the buffer into which the data is read. | |
off | the start offset of the data. | |
len | the maximum number of bytes read. |
-1
if there is no more data because the end of the file has been reached. IOException | if an I/O error occurs. |
int read | ( | ) | throws IOException [protected] |
Reads a byte of data from this input stream.
This method blocks if no input is yet available.
-1
if the end of the file is reached. IOException | if an I/O error occurs. |
long skip | ( | long | n | ) | throws IOException [protected] |
Skips over and discards n
bytes of data from the input stream.
The skip
method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0
. The actual number of bytes skipped is returned.
n | the number of bytes to be skipped. |
IOException | if an I/O error occurs. |
int available | ( | ) | throws IOException [protected] |
Returns the number of bytes that can be read from this file input stream without blocking.
IOException | if an I/O error occurs. |
void write | ( | int | b | ) | throws IOException [protected] |
Writes the specified byte to this file output stream.
Implements the write
method of OutputStream
.
b | the byte to be written. |
IOException | if an I/O error occurs. |
void write | ( | byte | b[], | |
int | off, | |||
int | len | |||
) | throws IOException [protected] |
Writes len
bytes from the specified byte array starting at offset off
to this file output stream.
b | the data. | |
off | the start offset in the data. | |
len | the number of bytes to write. |
IOException | if an I/O error occurs. |
String getName | ( | ) | [protected] |
Returns the name of the file or directory denoted by this abstract pathname.
This is just the last name in the pathname's name sequence. If the pathname's name sequence is empty, then the empty string is returned.
String getParent | ( | ) | [protected] |
Returns the pathname string of this abstract pathname's parent, or null
if this pathname does not name a parent directory.
The parent of an abstract pathname consists of the pathname's prefix, if any, and each name in the pathname's name sequence except for the last. If the name sequence is empty then the pathname does not name a parent directory.
null
if this pathname does not name a parent String getPath | ( | ) | [protected] |
Converts this abstract pathname into a pathname string.
The resulting string uses the default name-separator character to separate the names in the name sequence.
boolean exists | ( | ) | [protected] |
Checks to see if the file exists.
boolean canRead | ( | ) | [protected] |
Checks to see if can read the file associated with this descriptor.
boolean canWrite | ( | ) | [protected] |
Checks to see if the file represented by this descriptor is writable.
boolean isDirectory | ( | ) | [protected] |
Checks to see if this is a directory.
boolean isFile | ( | ) | [protected] |
Checks to see if this is a file.
boolean isHidden | ( | ) | [protected] |
Checks to see if this directory is hidden.
long length | ( | ) | [protected] |
Get the estimated length of the file represented by this descriptor.
This is calculated by looking at how may pages the file is using so is not a very accurate measure.
boolean delete | ( | ) | [protected] |
Delete this file or directory represented by this descriptor.
Will fail if it is a read-only file or a non-empty directory.
String [] list | ( | ) | [protected] |
Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname.
If this abstract pathname does not denote a directory, then this method returns null
. Otherwise an array of strings is returned, one for each file or directory in the directory. Names denoting the directory itself and the directory's parent directory are not included in the result. Each string is a file name rather than a complete path.
There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order.
null
if this abstract pathname does not denote a directory, or if an I/O error occurs. boolean renameTo | ( | OWFile | dest | ) | [protected] |
Renames the file denoted by this abstract pathname.
dest | The new abstract pathname for the named file |
true
if and only if the renaming succeeded; false
otherwiseNullPointerException | If parameter dest is null |
boolean setReadOnly | ( | ) | [protected] |
Marks the file or directory named by this abstract pathname so that only read operations are allowed.
After invoking this method the file or directory is guaranteed not to change until it is either deleted or marked to allow write access. Whether or not a read-only file or directory may be deleted depends upon the underlying system.
true
if and only if the operation succeeded; false
otherwise void mark | ( | int | readlimit | ) | [protected] |
Mark the current position in the file being read for later reference.
readlimit | limit to keep track of the current position |
void reset | ( | ) | throws IOException [protected] |
Reset the the read of this file back to the marked position.
IOException | when a read error occurs |
void markPageUsed | ( | int | page | ) | throws OneWireException [protected] |
Mark the specified page as used in the page bitmap.
page | number to mark as used |
OneWireException | when an IO exception occurs |
boolean freePage | ( | int | page | ) | throws OneWireException [protected] |
free the specified page as being un-used in the page bitmap
page | number to mark as un-used |
OneWireException | when an IO error occurs |
int getFirstFreePage | ( | boolean | counterPage | ) | throws OneWireException [protected] |
Get the first free page from the page bitmap.
counterPage | true if page needed is a 'counter' page (used in for monitary files) |
OneWireException | when an IO exception occurs |
int getNextFreePage | ( | boolean | counterPage | ) | throws OneWireException [protected] |
Get the next free page from the page bitmap.
counterPage | true if page needed is a 'counter' page (used in for monitary files) |
OneWireException | when an IO exception occurs |
int getFreeMemory | ( | ) | throws OneWireException [protected] |
Gets the number of bytes available on this device for file and directory information.
OneWireException | when an IO exception occurs |
void writeBitMap | ( | ) | throws OneWireException [protected] |
void readBitMap | ( | ) | throws OneWireException [protected] |
int [] getPageList | ( | ) | throws OneWireException [protected] |
Get's an array of integers that represents the page list of the file or directory represented by this OWFile.
OneWireException | if an I/O error occurs. |
int getStartPage | ( | ) | throws IOException [protected] |
Returns an integer which represents the starting memory page of the file or directory represented by this OWFile.
IOException | if the file doesn't exist |
PagedMemoryBank getMemoryBankForPage | ( | int | page | ) | [protected] |
Get's the memory bank object for the specified page.
This is significant if the Filesystem spans memory banks on the same or different devices.
int getLocalPage | ( | int | page | ) | [protected] |
Get's the local page number on the memory bank object for the specified page.
This is significant if the Filesystem spans memory banks on the same or different devices.
int verifyDeviceMap | ( | int | startPage, | |
int | numberOfContainers, | |||
boolean | setOverdrive | |||
) | throws OneWireException [protected] |
Verify the Device Map of a MASTER device is correct.
page | starting page number of the device map file | |
numberOfContainers | to re-create the OneWireContainer array in the instance variable from the devices listed in the device map 'owd[]'. Zero indicates leave the list alone. >0 means recreate the array keeping the same MASTER device. | |
setOverdrive | true if set new containers to do a max speed of overdrive if possible |
OneWireException | when an IO error occurs |
boolean createNewFile | ( | ) | throws IOException [protected] |
Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist.
The check for the existence of the file and the creation of the file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the file.
true
if the named file does not exist and was successfully created; false
if the named file already existsIOException | If an I/O error occurred |
int getHashCode | ( | ) | [protected] |
Computes a hash code for this abstract pathname.
Because equality of abstract pathnames is inherently system-dependent, so is the computation of their hash codes. On UNIX systems, the hash code of an abstract pathname is equal to the exclusive or of its pathname string and the decimal value 1234321
. On Win32 systems, the hash code is equal to the exclusive or of its pathname string, convered to lower case, and the decimal value 1234321
.
OneWireContainer [] getOneWireContainers | ( | ) | [protected] |
Gets the OneWireContainers that represent this Filesystem.