📄 owfile.java
字号:
* @throws NullPointerException * If parameter <code>dest</code> is <code>null</code> */ public boolean renameTo(OWFile dest) { return fd.renameTo(dest); } /** * Sets the last-modified time of the file or directory named by this * abstract pathname. * * <p> All platforms support file-modification times to the nearest second, * but some provide more precision. The argument will be truncated to fit * the supported precision. If the operation succeeds and no intervening * operations on the file take place, then the next invocation of the * <code>{@link #lastModified}</code> method will return the (possibly * truncated) <code>time</code> argument that was passed to this method. * * @param time The new last-modified time, measured in milliseconds since * the epoch (00:00:00 GMT, January 1, 1970) * * @return <code>true</code> if and only if the operation succeeded; * <code>false</code> otherwise * * @throws IllegalArgumentException If the argument is negative */ public boolean setLastModified(long time) { return false; // not supported } /** * 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. * * @return <code>true</code> if and only if the operation succeeded; * <code>false</code> otherwise */ public boolean setReadOnly() { boolean result = fd.setReadOnly(); return result; } //-------- //-------- Filesystem Interface Methods //-------- /** * List the available filesystem roots. * * <p> A particular Java platform may support zero or more * hierarchically-organized Filesystems. Each Filesystem has a * <code>root</code> directory from which all other files in that file * system can be reached. Windows platforms, for example, have a root * directory for each active drive; UNIX platforms have a single root * directory, namely <code>"/"</code>. The set of available filesystem * roots is affected by various system-level operations such the insertion * or ejection of removable media and the disconnecting or unmounting of * physical or virtual disk drives. * * <p> This method returns an array of <code>OWFile</code> objects that * denote the root directories of the available filesystem roots. It is * guaranteed that the canonical pathname of any file physically present on * the local machine will begin with one of the roots returned by this * method. * * <p> The canonical pathname of a file that resides on some other machine * and is accessed via a remote-filesystem protocol such as SMB or NFS may * or may not begin with one of the roots returned by this method. If the * pathname of a remote file is syntactically indistinguishable from the * pathname of a local file then it will begin with one of the roots * returned by this method. Thus, for example, <code>OWFile</code> objects * denoting the root directories of the mapped network drives of a Windows * platform will be returned by this method, while <code>OWFile</code> * objects containing UNC pathnames will not be returned by this method. * * @param owc OneWireContainer that this Filesystem resides on * * @return An array of <code>OWFile</code> objects denoting the available * filesystem roots, or <code>null</code> if the set of roots * could not be determined. The array will be empty if there are * no filesystem roots. */ public static OWFile[] listRoots(OneWireContainer owc) { OWFile[] roots = new OWFile [1]; roots [0] = new OWFile(owc, "/"); return roots; } //-------- //-------- Misc Methods //-------- /** * Compares two abstract pathnames lexicographically. The ordering * defined by this method depends upon the underlying system. On UNIX * systems, alphabetic case is significant in comparing pathnames; on Win32 * systems it is not. * * @param pathname The abstract pathname to be compared to this abstract * pathname * * @return Zero if the argument is equal to this abstract pathname, a * value less than zero if this abstract pathname is * lexicographically less than the argument, or a value greater * than zero if this abstract pathname is lexicographically * - greater than the argument */ public int compareTo(OWFile pathname) { OneWireContainer[] owd = fd.getOneWireContainers(); String this_path = owd[0].getAddressAsString() + getPath(); String compare_path = pathname.getOneWireContainer().getAddressAsString() + pathname.getPath(); return this_path.compareTo(compare_path); } /** * Compares this abstract pathname to another object. If the other object * is an abstract pathname, then this function behaves like <code>{@link * #compareTo(OWFile)}</code>. Otherwise, it throws a * <code>ClassCastException</code>, since abstract pathnames can only be * compared to abstract pathnames. * * @param o The <code>Object</code> to be compared to this abstract * pathname * * @return If the argument is an abstract pathname, returns zero * if the argument is equal to this abstract pathname, a value * less than zero if this abstract pathname is lexicographically * less than the argument, or a value greater than zero if this * abstract pathname is lexicographically greater than the * argument * * @throws <code>ClassCastException</code> if the argument is not an * abstract pathname * * @see java.lang.Comparable */ public int compareTo(Object o) { return compareTo((OWFile) o); } /** * Tests this abstract pathname for equality with the given object. * Returns <code>true</code> if and only if the argument is not * <code>null</code> and is an abstract pathname that denotes the same file * or directory as this abstract pathname. Whether or not two abstract * pathnames are equal depends upon the underlying system. On UNIX * systems, alphabetic case is significant in comparing pathnames; on Win32 * systems it is not. * * @param obj The object to be compared with this abstract pathname * * @return <code>true</code> if and only if the objects are the same; * <code>false</code> otherwise */ public boolean equals(Object obj) { if (obj == null) return false; if (!(obj instanceof OWFile)) return false; return (compareTo((OWFile) obj) == 0); } /** * 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 <em>or</em> of its pathname string * and the decimal value <code>1234321</code>. On Win32 systems, the hash * code is equal to the exclusive <em>or</em> of its pathname string, * convered to lower case, and the decimal value <code>1234321</code>. * * @return A hash code for this abstract pathname */ public int hashCode() { return fd.getHashCode(); } /** * Returns the pathname string of this abstract pathname. This is just the * string returned by the <code>{@link #getPath}</code> method. * * @return The string form of this abstract pathname */ public String toString() { return fd.getPath(); } //-------- //-------- Custom additions, not normally in File class //-------- /** * Returns the <code>OWFileDescriptor</code> * object that represents the connection to * the actual file in the Filesystem being * used by this <code>OWFileInputStream</code>. * * @return the file descriptor object associated with this File. * @exception IOException if an I/O error occurs. * @see com.dalsemi.onewire.application.file.OWFileDescriptor */ public OWFileDescriptor getFD() throws IOException { return fd; } /** * Gets the OneWireContainer that this File resides on. This * is where the 'filesystem' resides. If this Filesystem * spans multiple devices then this method returns the * 'MASTER' device. * * @return the OneWireContainer for this Filesystem */ public OneWireContainer getOneWireContainer() { OneWireContainer[] owd = fd.getOneWireContainers(); return owd[0]; } /** * Gets the OneWireContainer(s) that this File resides on. This * is where the 'filesystem' resides. The first device * is the 'MASTER' device and the other devices are 'SATELLITE' * devices. * * @return the OneWireContainer(s) for this Filesystem */ public OneWireContainer[] getOneWireContainers() { return fd.getOneWireContainers(); } /** * Format the Filesystem on the 1-Wire device provided in * the constructor. This operation is required before any * file IO is possible. <P> * <b>WARNING</b> this will remove any files/directories. * <P> * @exception IOException if an I/O error occurs. */ public void format() throws IOException { try { fd.format(); } catch (OneWireException e) { throw new IOException(e.toString()); } } /** * Gets the number of bytes available on this device for * file and directory information. * * @return number of free bytes in the Filesystem * * @exception IOException if an I/O error occurs */ public int getFreeMemory() throws IOException { try { return fd.getFreeMemory(); } catch (OneWireException e) { throw new IOException(e.toString()); } } /** * Closes this file and releases any system resources * associated with this stream. This file may no longer * be used after this operation. * * @exception IOException if an I/O error occurs. */ public void close() throws IOException { fd.close(); fd = null; } /** * Get's an array of integers that represents the page * list of the file or directory represented by this * OWFile. * * @return node page list file or directory * * @exception IOException if an I/O error occurs. */ public int[] getPageList() throws IOException { if (fd != null) { if (!fd.exists()) return new int[0]; } else return new int[0]; try { return fd.getPageList(); } catch (OneWireException e) { throw new IOException(e.toString()); } } /** * Returns an integer which represents the starting memory page * of the file or directory represented by this OWFile. * * @return The starting page of the file or directory. * * @exception IOException if the file doesn't exist */ public int getStartPage() throws IOException { if(fd != null && fd.exists()) { return fd.getStartPage(); } else { throw new FileNotFoundException(); } } /** * 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. * * @return PagedMemoryBank for the specified page */ public PagedMemoryBank getMemoryBankForPage(int page) { if (fd != null) { if (!fd.exists()) return null; } else return null; return fd.getMemoryBankForPage(page); } /** * 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. * * @return local page for the specified Filesystem page * (memory bank specific) */ public int getLocalPage(int page) { if (fd != null) { if (!fd.exists()) return 0; } else return 0; return fd.getLocalPage(page); } /** * Cleans up the connection to the file, and ensures that the * <code>close</code> method of this file output stream is * called when there are no more references to this stream. * * @exception IOException if an I/O error occurs. * @see java.io.FileInputStream#close() */ protected void finalize() throws IOException { if (fd != null) fd.close(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -