Author: mturk Date: Sun Apr 19 09:48:47 2009 New Revision: 766441 URL: http://svn.apache.org/viewvc?rev=766441&view=rev Log: Fill the missing File constructors
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java?rev=766441&r1=766440&r2=766441&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java Sun Apr 19 09:48:47 2009 @@ -77,13 +77,13 @@ */ protected final void finalize() throws Throwable - { + { try { cleanup0(); } catch (InstantiationException ex) { // Class is alreay uninitialized. // Ignore. - } + } } /** 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=766441&r1=766440&r2=766441&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 Sun Apr 19 09:48:47 2009 @@ -17,25 +17,145 @@ package org.apache.commons.runtime.io; import java.io.IOException; +import java.net.URI; -/** File extends the {...@code java.io.File} object. +/** + * An abstract representation of file and directory pathnames that + * extends the {...@code java.io.File} object. + * <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 extends java.io.File { + // Native methods from libacr. private static native int ftype0(String pathname); + // Catched FileType Enum integer value. + private int fileType = -1; + + /* Private constructor used from native code + * that assigns the file type so we don't need + * to query it from the OS file system. + */ + private File(String pathname, int fileType) + { + super(pathname); + this.fileType = fileType; + } + /** - * Create new File. + * Creates a new {...@code File} instance from a {...@code parent} pathname + * string and a {...@code child} pathname string. + * <p> + * If {...@code parent} is {...@code null} then the new {...@code File} instance + * is created as if by invoking the single-argument {...@code File} + * constructor on the given {...@code child} pathname string. + * </p> + * <p> + * Otherwise the {...@code parent} pathname string is taken to denote a + * directory, and the {...@code child} pathname string is taken to denote + * either a directory or a file. If the {...@code child} pathname string is + * absolute then it is converted into a relative pathname in a + * system-dependent way. If {...@code parent} is the empty string then the + * new {...@code File} instance is created by converting child into an + * abstract pathname and resolving the result against a system-dependent + * default directory. Otherwise each pathname string is converted into an + * abstract pathname and the child abstract pathname is resolved + * against the parent. + * + * @param parent The parent pathname string. + * @param child The child pathname string. + * @throws NullPointerException If the {...@code child} is {...@code null}. + */ + public File(String parent, String child) + throws NullPointerException + { + super(parent, child); + } + + /** + * Creates a new {...@code File} instance from a {...@code parent} abstract + * pathname and a {...@code child} pathname string. + * <p> + * If {...@code parent} is {...@code null} then the new {...@code File} instance is + * created as if by invoking the single-argument {...@code File} constructor + * on the given {...@code child} pathname string. + * </p> + * <p> + * Otherwise the {...@code parent} abstract pathname is taken to denote a + * directory, and the {...@code child} pathname string is taken to denote + * either a directory or a file. If the {...@code child} pathname string is + * absolute then it is converted into a relative pathname in a + * system-dependent way. If {...@code parent} is the empty abstract pathname + * then the new {...@code File} instance is created by converting {...@code child} + * into an abstract pathname and resolving the result against a + * system-dependent default directory. Otherwise each pathname string + * is converted into an abstract pathname and the child abstract pathname + * is resolved against the parent. + * + * @param parent The parent abstract pathname. + * @param child The child pathname string. + * @throws NullPointerException If the {...@code child} is {...@code null}. + */ + public File(File parent, String child) + throws NullPointerException + { + super(parent, child); + } + + /** + * 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 pathname A pathname string. + * @throws NullPointerException If the {...@code pathname} is {...@code null}. */ public File(String pathname) + throws NullPointerException { super(pathname); } + /** + * Creates a new {...@code File} instance by converting the given + * {...@code file:} URI into an abstract pathname. + * <p> + * The exact form of a {...@code file:} URI is system-dependent, + * hence the transformation performed by this constructor is also + * system-dependent. + * + * @param uri An absolute, hierarchical URI with a scheme equal to + * "file", a non-empty path component, and undefined authority, + * query, and fragment components. + * @throws NullPointerException If the {...@code uri} is {...@code null}. + * @throws IllegalArgumentException If the preconditions on the parameter do not hold. + */ + public File(URI uri) + throws NullPointerException, IllegalArgumentException + { + super(uri); + } + + /** + * Returns the {...@link FileType} of the file denoted by this abstract + * pathname. + * + * @return {...@link FileType} representing the type of the file. + * @throws IOException If an I/O error occured. + * @see FileType + */ public FileType getFileType() throws IOException { - return FileType.valueOf(ftype0(getPath())); + // We could catch the IOException here and rethrow again + // to hide the 'Native Method' in Stack trace. + if (fileType < 0) + fileType = ftype0(getPath()); + return FileType.valueOf(fileType); } } Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c?rev=766441&r1=766440&r2=766441&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Sun Apr 19 09:48:47 2009 @@ -48,7 +48,10 @@ if (GetFullPathNameW(fname, ACR_HBUFF_LEN, tmpname, &tmpoff)) { if (!wcsncmp(tmpname, L"\\\\.\\", 4)) { - if (tmpoff == tmpname + 4) { + if (!wcsnicmp(tmpname + 4, L"pipe\\", 5)) { + type = ACR_FT_PIPE; + } + else if (tmpoff == tmpname + 4) { type = ACR_FT_CHR; } /* For WHATEVER reason, CHR devices such as \\.\con