/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Factory to create FileChannels and AsynchronousFileChannels.
*/
class WindowsChannelFactory {
private WindowsChannelFactory() { }
/**
* Do not follow reparse points when opening an existing file. Do not fail
* if the file is a reparse point.
*/
/**
* Represents the flags from a user-supplied set of open options.
*/
private static class Flags {
boolean read;
boolean write;
boolean append;
boolean truncateExisting;
boolean create;
boolean createNew;
boolean deleteOnClose;
boolean sparse;
boolean overlapped;
boolean sync;
boolean dsync;
// non-standard
boolean shareRead = true;
boolean shareWrite = true;
boolean shareDelete = true;
boolean noFollowLinks;
boolean openReparsePoint;
if (option instanceof StandardOpenOption) {
switch ((StandardOpenOption)option) {
default: throw new UnsupportedOperationException();
}
continue;
}
if (option instanceof ExtendedOpenOption) {
switch ((ExtendedOpenOption)option) {
default: throw new UnsupportedOperationException();
}
continue;
}
flags.noFollowLinks = true;
continue;
}
if (option == OPEN_REPARSE_POINT) {
flags.openReparsePoint = true;
continue;
}
throw new NullPointerException();
throw new UnsupportedOperationException();
}
return flags;
}
}
/**
*
* @param pathForWindows
* @param pathToCheck
* The path used for permission checks (if security manager)
*/
long pSecurityDescriptor)
throws WindowsException
{
// default is reading; append => writing
} else {
}
}
// validation
throw new IllegalArgumentException("READ + APPEND not allowed");
throw new IllegalArgumentException("APPEND + TRUNCATE_EXISTING not allowed");
}
/**
*
* @param pathForWindows
* @param pathToCheck
* The path used for permission checks (if security manager)
* @param pool
* The thread pool that the channel is associated with
*/
long pSecurityDescriptor,
throws IOException
{
// Overlapped I/O required
flags.overlapped = true;
// default is reading
}
// validation
throw new UnsupportedOperationException("APPEND not allowed");
// open file for overlapped I/O
try {
} catch (WindowsException x) {
return null;
}
// create the AsynchronousFileChannel
try {
} catch (IOException x) {
// IOException is thrown if the file handle cannot be associated
// with the completion port. All we can do is close the file.
throw x;
}
}
/**
* Opens file based on parameters and options, returning a FileDescriptor
* encapsulating the handle to the open file.
*/
long pSecurityDescriptor)
throws WindowsException
{
// set to true if file must be truncated after open
boolean truncateAfterOpen = false;
// map options
int dwDesiredAccess = 0;
int dwShareMode = 0;
if (flags.shareWrite)
if (flags.shareDelete)
// force create to fail if file is orphaned reparse point
} else {
if (flags.truncateExisting) {
// Windows doesn't have a creation disposition that exactly
// corresponds to CREATE + TRUNCATE_EXISTING so we use
// the OPEN_ALWAYS mode and then truncate the file.
if (dwCreationDisposition == OPEN_ALWAYS) {
truncateAfterOpen = true;
} else {
}
}
}
}
if (flags.overlapped)
if (flags.deleteOnClose)
// NOFOLLOW_LINKS and NOFOLLOW_REPARSEPOINT mean open reparse point
boolean okayToFollowLinks = true;
if (dwCreationDisposition != CREATE_NEW &&
(flags.noFollowLinks ||
{
okayToFollowLinks = false;
}
// permission check
if (pathToCheck != null) {
if (flags.deleteOnClose)
}
}
// open file
// make sure this isn't a symbolic link.
if (!okayToFollowLinks) {
try {
throw new WindowsException("File is symbolic link");
} catch (WindowsException x) {
throw x;
}
}
// truncate file (for CREATE + TRUNCATE_EXISTING case)
if (truncateAfterOpen) {
try {
} catch (WindowsException x) {
throw x;
}
}
// make the file sparse if needed
try {
} catch (WindowsException x) {
// ignore as sparse option is hint
}
}
// create FileDescriptor and return
return fdObj;
}
}