Author: mturk Date: Fri Oct 23 08:10:04 2009 New Revision: 828953 URL: http://svn.apache.org/viewvc?rev=828953&view=rev Log: Second stage of decoupling File from java.io.File. File now only provide static methods
Removed: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Detachable.java Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Container.java commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileInstance.java commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileLock.java commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileLockImpl.java commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileStream.java commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileWrapper.java commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMap.java commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMapProvider.java commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Stream.java commons/sandbox/runtime/trunk/src/main/native/shared/fsysio.c Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Container.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Container.java?rev=828953&r1=828952&r2=828953&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Container.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Container.java Fri Oct 23 08:10:04 2009 @@ -22,7 +22,7 @@ * The base class for all classes offerering * detach method to it's child objects. */ -public interface Container +public interface Container<T> { /** @@ -35,6 +35,6 @@ * * @param data Object to detach. */ - public void detach(Detachable data); + public void detach(T data); } Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java?rev=828953&r1=828952&r2=828953&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java Fri Oct 23 08:10:04 2009 @@ -53,6 +53,11 @@ dd.close(); } + public Path getPath() + { + return path; + } + private static native Descriptor open0(String path) throws FileNotFoundException, IOException, SecurityException; /** Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java?rev=828953&r1=828952&r2=828953&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java Fri Oct 23 08:10:04 2009 @@ -18,23 +18,30 @@ import java.io.FileNotFoundException; import java.io.IOException; +import java.io.Flushable; +import java.io.IOException; +import java.io.SyncFailedException; import java.net.URI; +import java.util.Enumeration; import java.util.EnumSet; +import java.util.Vector; import org.apache.commons.runtime.Descriptor; import org.apache.commons.runtime.Group; import org.apache.commons.runtime.User; +import org.apache.commons.runtime.exception.ClosedDescriptorException; +import org.apache.commons.runtime.exception.AsyncClosedDescriptorException; +import org.apache.commons.runtime.exception.InvalidDescriptorException; +import org.apache.commons.runtime.exception.OverlappingFileLockException; +import org.apache.commons.runtime.exception.TimeoutException; import org.apache.commons.runtime.util.StringManager; /** - * An abstract representation of file and directory pathnames that - * extends the {...@code java.io.File} object. + * Provides static methods for the creation, copying, deletion, + * moving and opening of files. * <p> - * Apache Commons Runtime {...@code File} extends the standard functionality - * of the {...@code java.io.File} object, by adding extra features found - * in modern Operating systems. * </p> */ -public class File +public final class File { // Native methods from libacr. @@ -68,42 +75,36 @@ boolean full) throws IOException, SecurityException; private static native int unlink0(String pathname); - private Path path; - private int type = -1; - public Path getPath() + private File() { - return path; + // No instance } - /* Private constructor used from native code - * that assigns the file type so we don't need - * to query it from the OS file system. + /** + * The "standard" input stream {...@code FileStream}. */ - private File(Path path, int type) - { - this.path = path; - this.type = type; - } - + public static final FileStream STDIN; /** - * Create new {...@code File} instance by converting the given pathname - * into an abstract pathname. If the given string is the empty path, - * then the result is the empty abstract pathname. - * - * @param path A file path. + * The "standard" output stream {...@code FileStream}. */ - public File(Path path) - { - this.path = path; - } + public static final FileStream STDOUT; + /** + * The "standard" error stream {...@code FileStream}. + */ + public static final FileStream STDERR; - public File(String path) - throws NullPointerException, IllegalArgumentException - { - this.path = new Path(path); + static { + /* Initialize the "standard" FileStream. + * Note that those descriptors can be NULL in + * case the FileStream.open call fails. + */ + STDIN = new FileStreamImpl(FileWrapper.open(0, null)); + STDOUT = new FileStreamImpl(FileWrapper.open(1, null)); + STDERR = new FileStreamImpl(FileWrapper.open(2, null)); } + /** * Returns the {...@link FileType} of the file denoted by this abstract * pathname. @@ -121,13 +122,10 @@ * the directories in the path prefix this {...@code File} path. * @see FileType */ - public FileType getFileType() + public static FileType getFileType(Path path) throws IOException, SecurityException { - // We could catch the IOException here and rethrow again - // to hide the 'Native Method' in Stack trace. - if (type < 0) - type = ftype0(path.toString()); + int type = ftype0(path.toString()); return FileType.valueOf(type); } @@ -149,43 +147,100 @@ } - public EnumSet<FileProtection> getFileProtection() + public static EnumSet<FileProtection> getFileProtection(Path path) throws IOException, SecurityException { int mode = fprot0(path.toString()); return FileProtection.valueOf(mode); } - public boolean setFileProtection(EnumSet<FileProtection> prot) + public static boolean setFileProtection(Path path, EnumSet<FileProtection> prot) throws IOException, SecurityException { return chmod0(path.toString(), FileProtection.bitmapOf(prot)); } - public boolean setFileProtection(FileProtection... prot) + public static boolean setFileProtection(Path path, FileProtection... prot) throws IOException, SecurityException { return chmod0(path.toString(), FileProtection.bitmapOf(prot)); } - public boolean setOwner(User user, Group group) + public static boolean setOwner(Path path, User user, Group group) throws IOException, SecurityException { return chown0(path.toString(), user.Id, group.Id); } - public boolean setOwner(User user) + public static boolean setOwner(Path path, User user) throws IOException, SecurityException { return chown0(path.toString(), user.Id, null); } - public boolean setOwner(Group group) + public static boolean setOwner(Path path, Group group) throws IOException, SecurityException { return chown0(path.toString(), null, group.Id); } + public static Descriptor create(Path path, EnumSet<FileOpenMode> mode) + throws FileNotFoundException, IOException, IllegalArgumentException, + SecurityException + { + if (mode == null) + throw new IllegalArgumentException(); + mode.add(FileOpenMode.CREATE); + Descriptor fd = FileWrapper.open(path, mode); + if (fd == null) { + // File exists and EXCL mode was given + throw new FileNotFoundException(Local.sm.get("file.EEXIST")); + } + return fd; + } + + public static Descriptor open(Path path, EnumSet<FileOpenMode> mode) + throws FileNotFoundException, IOException, IllegalArgumentException, + SecurityException + { + Descriptor fd = FileWrapper.open(path, mode); + if (fd == null) { + // File exists and EXCL mode was given + throw new FileNotFoundException(Local.sm.get("file.EEXIST")); + } + return fd; + } + + public static Descriptor open(Path path, FileOpenMode... mode) + throws FileNotFoundException, IOException, IllegalArgumentException, + SecurityException + { + return open(path, FileOpenMode.of(mode)); + } + + public static Descriptor open(Path path, + EnumSet<FileOpenMode> mode, + EnumSet<FileProtection> prot) + throws FileNotFoundException, IOException, IllegalArgumentException, + SecurityException + { + Descriptor fd = FileWrapper.open(path, mode, prot); + if (fd == null) { + // File exists and EXCL mode was given + throw new FileNotFoundException(Local.sm.get("file.EEXIST")); + } + return fd; + } + + public static Descriptor open(Path path, + EnumSet<FileOpenMode> mode, + FileProtection... prot) + throws FileNotFoundException, IOException, IllegalArgumentException, + SecurityException + { + return open(path, mode, FileProtection.of(prot)); + } + /** * Set attributes of the file denoted by this abstract pathname. * <p> @@ -207,8 +262,9 @@ * @throws SecurityException If Search permission is denied for one of * the directories in the path prefix this {...@code File} path. */ - public boolean setFileAttributes(EnumSet<FileAttributes> attributes, - EnumSet<FileAttributes> mask) + public static boolean setFileAttributes(Path path, + EnumSet<FileAttributes> attributes, + EnumSet<FileAttributes> mask) throws IOException, SecurityException { return attrs0(path.toString(), @@ -232,7 +288,7 @@ * @throws SecurityException If Search permission is denied for one of * the directories in the path prefix this {...@code File} path. */ - public EnumSet<FileAttributes> getFileAttributes() + public static EnumSet<FileAttributes> getFileAttributes(Path path) throws IOException, SecurityException { return FileAttributes.valueOf(attrg0(path.toString())); @@ -248,11 +304,10 @@ * the directories in the path prefix this {...@code File} path. * @see FileType */ - public boolean isSymbolicLink() + public static boolean isSymbolicLink(Path path) throws IOException, SecurityException { - if (type < 0) - type = ftype0(path.toString()); + int type = ftype0(path.toString()); return type == FileType.LNK.valueOf(); } @@ -298,56 +353,6 @@ } /** - * Creates a new abstract {...@code File} symbolic link instance with - * the path {...@code link} which contains the string of this {...@code File} - * isnstance pathname. - * <p> - * Symbolic links are interpreted at run-time as if the contents of - * the link had been substituted into the path being followed to find a - * file or directory. On some operating systems like - * {...@code Microsoft Windows} only ceratain versions support symbolic - * link concept with limitation of {...@code 32} symbolic links inside - * each directory. Windows versions before {...@code Windows Vista} do not - * support symbolic links at all in which case the - * {...@code UnsupportedOperationException} exception is thrown. - * </p> - * <p> - * Symbolic links may contain {...@code ..} path components, which - * (if used at the start of the link) refer to the parent - * directories of that in which the link resides. - * </p> - * <p> - * A symbolic link (also known as a soft link) may point to an existing - * file or to a nonexistent one; the latter case is known as a - * <em>dangling link</em>. - * </p> - * - * @param link The symbolic link name. - * @return New {...@code File} instance containing symbolic link to this - * file instance. - * @throws IOException in case of error. - * @throws SecurityException if Write access to the directory containing - * {...@code link} is denied, or one of the directories in the - * path prefix of {...@code link} did not allow search permission. - * @throws UnsupportedOperationException if the operating system doesn't - * support symbolic links. - */ - public File createSymbolicLink(Path link) - throws IOException, SecurityException, UnsupportedOperationException - { - - // False means EEXIST, so just consider it opened - // Check is made wather it points to the same target - mkslink0(path.toString(), link.toString()); - if (path.compareTo(target0(link.toString())) == 0) { - return new File(link, FileType.LNK.valueOf()); - } - else { - throw new IOException(Local.sm.get("symlink.EEXIST")); - } - } - - /** * Creates a hard link named {...@code link} which contains the string * {...@code target}. * <p> @@ -376,37 +381,6 @@ } /** - * Creates a new abstract {...@code File} hard link instance with - * the path {...@code link} which contains the string of this {...@code File} - * isnstance pathname. - * <p> - * This new name may be used exactly as the old one for any operation; - * both names refer to the same file (and so - * have the same permissions and ownership) and it is impossible to - * tell which name was the <em>original</em>. - * On some operating systems like - * {...@code Microsoft Windows} this operation is only supported on the - * {...@code NTFS} file system, and only for files, not directories. - * </p> - * - * @param link The link name. - * @return New {...@code File} instance containing hard link to this - * file instance. - * @throws IOException in case of error. - * @throws SecurityException if Write access to the directory containing - * {...@code link} is denied, or one of the directories in the - * path prefix of {...@code link} did not allow search permission. - */ - public File createHardLink(Path link) - throws IOException, SecurityException - { - // False means EEXIST, so just consider it opened - // Check is made wather it points to the same target - mkhlink0(path.toString(), link.toString()); - return new File(link, type); - } - - /** * Creates a new temporary directory with {...@code prefix}. * <p> * </p> @@ -417,11 +391,10 @@ * @throws SecurityException if Write access to the system temporary * directory is denied. */ - public File createTempDirectory(String prefix) + public static Path createTempDirectory(String prefix) throws IOException, SecurityException { - Path dir = tmpdir0(null, prefix); - return new File(dir); + return tmpdir0(null, prefix); } /** @@ -437,11 +410,10 @@ * @throws SecurityException if Write access to the directory specified * by {...@code path} is denied. */ - public File createTempDirectory(Path path, String prefix) + public static Path createTempDirectory(Path path, String prefix) throws IOException, SecurityException { - Path dir = tmpdir0(path.toString(), prefix); - return new File(dir); + return tmpdir0(path.toString(), prefix); } /** @@ -463,7 +435,7 @@ throw new IllegalArgumentException(); } Descriptor fd = FileWrapper.mktemp(directory, prefix, suffix, preserve); - return new FileStream(fd); + return new FileStreamImpl(fd); } /** @@ -481,7 +453,7 @@ throw new IllegalArgumentException(); } Descriptor fd = FileWrapper.mktemp(prefix, suffix, preserve); - return new FileStream(fd); + return new FileStreamImpl(fd); } /** @@ -493,29 +465,13 @@ * @throws SecurityException if search permission is denied for a * component of this abstract {...@code File} pathname prefix. */ - public Path getTargetPath() + public static Path getTargetPath(Path path) throws IOException, SecurityException { return target0(path.toString()); } /** - * Return new abstract {...@code File} target instance of this - * abstract {...@code File} instance. - * - * @return New {...@code File} instance this {...@code File} points to. - * @throws IOException if this {...@code File} is not symbolic or hard link - * or an I/O error occured. - * @throws SecurityException if search permission is denied for a - * component of this abstract {...@code File} pathname prefix. - */ - public File getTargetFile() - throws IOException, SecurityException - { - return new File(getTargetPath()); - } - - /** * Return this abstract {...@code File} system id. * * @return Existing {...@code File} system id. @@ -524,7 +480,7 @@ * @throws SecurityException if search permission is denied for a * component of this abstract {...@code File} pathname prefix. */ - public long fileId() + public static long getFileId(Path path) throws IOException, SecurityException { return inode0(path.toString()); @@ -547,32 +503,10 @@ * @throws IOException if some other I/O error occured. * @see FileInfo */ - public FileInfo stat() - throws IOException, SecurityException - { - boolean link = false; - if (type == -1 || type == FileType.LNK.valueOf()) - link = true; - return stat0(path.toString(), link, true); - } - - /** - * Return new {...@link FileInfo} object for the file {...@code Descriptor}. - * - * @param fd - * file {...@code Descriptor} for which to get the info. - * @throws ClosedDescriptorException - * If this file is closed. - * @throws AsyncClosedDescriptorException - * If another thread closes this file while the lock - * operation is in progress. - * @throws IOException - * If some other I/O error occurs. - */ - public static FileInfo stat(Descriptor fd) + public static FileInfo getFileInfo(Path path) throws IOException, SecurityException { - return FileWrapper.stat(fd); + return stat0(path.toString(), false, true); } /** @@ -600,12 +534,30 @@ return FileWrapper.name(fd); } - public boolean delete() + public static int delete(Path path) + { + return unlink0(path.toString()); + } + + /** + * Returns the length of this file in bytes. + * + * @return the file's length in bytes. + * + * @throws ClosedDescriptorException + * If this file is closed. + * @throws AsyncClosedDescriptorException + * If another thread closes this file while this + * operation is in progress. + * @throws IOException + * If some other I/O error occurs. + */ + public static long getLength(Path path) + throws IOException { - if (unlink0(path.toString()) == 0) - return true; - else - return false; + FileInfo info = stat0(path.toString(), false, false); + return info.Size; } + } Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileInstance.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileInstance.java?rev=828953&r1=828952&r2=828953&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileInstance.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileInstance.java Fri Oct 23 08:10:04 2009 @@ -39,38 +39,6 @@ // No instance } - public static Descriptor create(Path path, EnumSet<FileOpenMode> mode) - throws FileNotFoundException, IOException, IllegalArgumentException, - SecurityException - { - Descriptor fd = FileWrapper.open(path, mode); - if (fd == null) { - // File exists and EXCL mode was given - throw new FileNotFoundException(Local.sm.get("file.EEXIST")); - } - return fd; - } - - public static Descriptor create(Path path, FileOpenMode... mode) - throws FileNotFoundException, IOException, IllegalArgumentException, - SecurityException - { - return create(path, FileOpenMode.of(mode)); - } - - public static Descriptor create(Path path, EnumSet<FileOpenMode> mode, - EnumSet<FileProtection> prot) - throws FileNotFoundException, IOException, IllegalArgumentException, - SecurityException - { - Descriptor fd = FileWrapper.open(path, mode, prot); - if (fd == null) { - // File exists and EXCL mode was given - throw new FileNotFoundException(Local.sm.get("file.EEXIST")); - } - return fd; - } - /** * The "standard" input stream {...@code FileStream}. */ @@ -89,9 +57,9 @@ * Note that those descriptors can be NULL in * case the FileStream.open call fails. */ - STDIN = new FileStream(FileWrapper.open(0, null)); - STDOUT = new FileStream(FileWrapper.open(1, null)); - STDERR = new FileStream(FileWrapper.open(2, null)); + STDIN = new FileStreamImpl(FileWrapper.open(0, null)); + STDOUT = new FileStreamImpl(FileWrapper.open(1, null)); + STDERR = new FileStreamImpl(FileWrapper.open(2, null)); } /** @@ -130,7 +98,7 @@ throw new IllegalArgumentException(); } Descriptor fd = FileWrapper.open(which, mode); - return new FileStream(fd); + return new FileStreamImpl(fd); } public static FileStream createStdStream(int which, Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileLock.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileLock.java?rev=828953&r1=828952&r2=828953&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileLock.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileLock.java Fri Oct 23 08:10:04 2009 @@ -18,7 +18,6 @@ import org.apache.commons.runtime.Container; import org.apache.commons.runtime.Descriptor; -import org.apache.commons.runtime.Detachable; import org.apache.commons.runtime.exception.ClosedDescriptorException; import org.apache.commons.runtime.exception.AsyncClosedDescriptorException; import org.apache.commons.runtime.exception.InvalidDescriptorException; @@ -75,7 +74,7 @@ * Further care should be exercised when locking files maintained on network * file systems, since they often have further limitations. */ -public abstract class FileLock implements Detachable +public abstract class FileLock { /* Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileLockImpl.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileLockImpl.java?rev=828953&r1=828952&r2=828953&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileLockImpl.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileLockImpl.java Fri Oct 23 08:10:04 2009 @@ -18,7 +18,6 @@ import org.apache.commons.runtime.Container; import org.apache.commons.runtime.Descriptor; -import org.apache.commons.runtime.Detachable; import org.apache.commons.runtime.exception.ClosedDescriptorException; import org.apache.commons.runtime.exception.AsyncClosedDescriptorException; import org.apache.commons.runtime.exception.InvalidDescriptorException; @@ -29,7 +28,7 @@ /** * A {...@code FileLock} implementatiom. */ -class FileLockImpl extends FileLock implements Detachable +class FileLockImpl extends FileLock { /* @@ -48,13 +47,13 @@ /* * FileLock container object */ - private Container container; + private Container<FileLock> container; /** * Create new {...@code FileLock} that locks the entire file. * */ - public FileLockImpl(Container container, Descriptor fd, + public FileLockImpl(Container<FileLock> container, Descriptor fd, EnumSet<FileLockType> mode) { super(mode); @@ -68,7 +67,7 @@ * Create new {...@code FileLock} that locks the region of file. * */ - public FileLockImpl(Container container, Descriptor fd, + public FileLockImpl(Container<FileLock> container, Descriptor fd, EnumSet<FileLockType> mode, long start, long len) { super(mode); Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileStream.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileStream.java?rev=828953&r1=828952&r2=828953&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileStream.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileStream.java Fri Oct 23 08:10:04 2009 @@ -18,7 +18,6 @@ import org.apache.commons.runtime.Container; import org.apache.commons.runtime.Descriptor; -import org.apache.commons.runtime.Detachable; import org.apache.commons.runtime.Pointer; import org.apache.commons.runtime.exception.ClosedDescriptorException; import org.apache.commons.runtime.exception.AsyncClosedDescriptorException; @@ -42,18 +41,19 @@ * position of the next read or write operation can be moved forwards and * backwards after every operation. */ -public class FileStream extends SeekableStream implements Container +public abstract class FileStream extends Stream + implements Container<FileLock> { /* File's descriptor object */ - private Descriptor fd; + protected Descriptor fd; /* File's object lock */ - private Object sync = new Object(); + protected Object sync = new Object(); /* * List of all lock regions to this file. */ - private Vector<FileLockImpl> locks = new Vector<FileLockImpl>(2); + protected Vector<FileLockImpl> locks = new Vector<FileLockImpl>(2); /** * Return the {...@link Descriptor} accosicated with this file. @@ -65,7 +65,7 @@ return fd; } - public void detach(Detachable data) + public void detach(FileLock data) { locks.remove(data); } @@ -133,13 +133,6 @@ fd.sync(); } - /** Create new FileStream object from the {...@code fd}. - */ - public FileStream(Descriptor fd) - { - this.fd = fd; - } - /** * Clear the file errors. * <p> Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileWrapper.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileWrapper.java?rev=828953&r1=828952&r2=828953&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileWrapper.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileWrapper.java Fri Oct 23 08:10:04 2009 @@ -126,6 +126,19 @@ return name0(fd.fd()); } + private static native Path path0(int fd) + throws IOException; + /** + * Returns real file Path object. + */ + public static Path path(Descriptor fd) + throws IOException + { + if (!fd.valid()) + throw new ClosedDescriptorException(); + return path0(fd.fd()); + } + private static native int ftype0(int fd) throws IOException; /** Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMap.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMap.java?rev=828953&r1=828952&r2=828953&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMap.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMap.java Fri Oct 23 08:10:04 2009 @@ -16,6 +16,7 @@ package org.apache.commons.runtime.io; +import java.io.Closeable; import java.io.IOException; import java.util.Enumeration; import java.util.EnumSet; @@ -31,7 +32,7 @@ * <p> * </p> */ -public final class MemoryMap implements java.io.Closeable +public final class MemoryMap implements Closeable { /* * Reference to the OS memory map provider. Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMapProvider.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMapProvider.java?rev=828953&r1=828952&r2=828953&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMapProvider.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMapProvider.java Fri Oct 23 08:10:04 2009 @@ -16,6 +16,7 @@ package org.apache.commons.runtime.io; +import java.io.Closeable; import java.io.IOException; import java.util.Enumeration; import java.util.EnumSet; @@ -31,7 +32,7 @@ * <p> * </p> */ -class MemoryMapProvider implements java.io.Closeable +class MemoryMapProvider implements Closeable { /* * Reference to the OS memory mapped file descriptor @@ -55,6 +56,11 @@ this.map = map; } + public void detach(Pointer data) + { + mappedRegions.remove(data); + } + private static native Descriptor create0(String fname, int flags) throws IOException, SecurityException, OutOfMemoryError; /** Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Stream.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Stream.java?rev=828953&r1=828952&r2=828953&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Stream.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Stream.java Fri Oct 23 08:10:04 2009 @@ -120,4 +120,46 @@ return false; } + /** + * Moves this stream pointer to a new position, from where following + * {...@code read}, {...@code write} or {...@code skip} operations are done. + * + * @param how + * Starting point for the pointer move. + * @param off + * Move offset in bytes. + * @return new position + * + * @throws IllegalArgumentException + * If {...@code how == SeekMethod.SET} and + * {...@code off < 0}. + * @throws IOException + * If some other I/O error occurs. + * @see SeekMethod + */ + public abstract long seek(SeekMethod how, long off) + throws IOException; + + /** + * Skips over {...@code count} bytes in this stream. Less than {...@code count} + * bytes are skipped if the end of the stream is reached or an exception is + * thrown during the operation. Nothing is done if {...@code count} is + * negative. + * + * @param count + * The number of bytes to skip. + * + * @return The number of bytes actually skipped. + * + * @throws ClosedDescriptorException + * If this stream is closed. + * @throws AsyncClosedDescriptorException + * If another thread closes this stream while this + * operation is in progress. + * @throws IOException + * If some other I/O error occurs. + */ + public abstract int skip(int count) + throws IOException; + } Modified: commons/sandbox/runtime/trunk/src/main/native/shared/fsysio.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/fsysio.c?rev=828953&r1=828952&r2=828953&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/shared/fsysio.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/shared/fsysio.c Fri Oct 23 08:10:04 2009 @@ -136,3 +136,19 @@ } return PSTR_TO_JSTRING(f->name); } + +ACR_IO_EXPORT_DECLARE(jobject, FileWrapper, path0)(ACR_JNISTDARGS, + jint file) +{ + acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file); + + if (ACR_IOH_FTYPE(file) != ACR_DT_FILE) { + ACR_THROW_IO_IF_ERR(ACR_EFTYPE); + return NULL; + } + if (IS_INVALID_HANDLE(f)) { + ACR_THROW_IO_IF_ERR(ACR_EBADF); + return NULL; + } + return ACR_NewPathObject(_E, f->type, f->name); +}