/*
* 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.
*/
/**
* "Portable" implementation of AsynchronousFileChannel for use on operating
* systems that don't support asynchronous file I/O.
*/
public class SimpleAsynchronousFileChannelImpl
extends AsynchronousFileChannelImpl
{
// lazy initialization of default thread pool for file I/O
private static class DefaultExecutorHolder {
}
// Used to make native read and write calls
// Thread-safe set of IDs of native threads, for signalling
boolean reading,
boolean writing,
{
}
boolean reading,
boolean writing,
{
// Executor is either default or based on pool parameters
}
// mark channel as closed
synchronized (fdObj) {
if (closed)
return; // already closed
closed = true;
// from this point on, if another thread invokes the begin() method
// then it will throw ClosedChannelException
}
// Invalidate and release any locks that we still hold
// signal any threads blocked on this channel
// wait until all async I/O operations have completely gracefully
try {
// do nothing
} finally {
}
// close file
}
try {
long n = 0L;
try {
begin();
do {
return n;
} finally {
end(n >= 0L);
}
} finally {
}
}
if (size < 0L)
throw new IllegalArgumentException("Negative size");
if (!writing)
throw new NonWritableChannelException();
try {
long n = 0L;
try {
begin();
do {
// truncate file if 'size' less than current size
do {
}
return this;
} finally {
end(n > 0);
}
} finally {
}
}
try {
int n = 0;
try {
begin();
do {
} finally {
end(n >= 0);
}
} finally {
}
}
final long size,
final boolean shared,
final A attachment,
{
throw new NonReadableChannelException();
throw new NonWritableChannelException();
// add to lock table
return null;
}
public void run() {
try {
int n;
try {
begin();
do {
throw new AsynchronousCloseException();
}
} catch (IOException x) {
if (!isOpen())
x = new AsynchronousCloseException();
exc = x;
} finally {
end();
}
} finally {
}
} else {
}
}
};
boolean executed = false;
try {
executed = true;
} finally {
if (!executed) {
// rollback
}
}
return result;
}
throws IOException
{
throw new NonReadableChannelException();
throw new NonWritableChannelException();
// add to lock table
throw new ClosedChannelException();
boolean gotLock = false;
try {
begin();
int n;
do {
gotLock = true;
return fli; // lock acquired
}
if (n == FileDispatcher.NO_LOCK)
return null; // locked by someone else
if (n == FileDispatcher.INTERRUPTED)
throw new AsynchronousCloseException();
// should not get here
throw new AssertionError();
} finally {
if (!gotLock)
end();
}
}
}
final long position,
final A attachment,
{
if (position < 0)
throw new IllegalArgumentException("Negative position");
if (!reading)
throw new NonReadableChannelException();
if (dst.isReadOnly())
throw new IllegalArgumentException("Read-only buffer");
// complete immediately if channel closed or no space remaining
return null;
}
public void run() {
int n = 0;
try {
begin();
do {
if (n < 0 && !isOpen())
throw new AsynchronousCloseException();
} catch (IOException x) {
if (!isOpen())
x = new AsynchronousCloseException();
exc = x;
} finally {
end();
}
} else {
}
}
};
return result;
}
final long position,
final A attachment,
{
if (position < 0)
throw new IllegalArgumentException("Negative position");
if (!writing)
throw new NonWritableChannelException();
// complete immediately if channel is closed or no bytes remaining
return null;
}
public void run() {
int n = 0;
try {
begin();
do {
if (n < 0 && !isOpen())
throw new AsynchronousCloseException();
} catch (IOException x) {
if (!isOpen())
x = new AsynchronousCloseException();
exc = x;
} finally {
end();
}
} else {
}
}
};
return result;
}
}