You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/10/08 17:41:41 UTC
svn commit: r823210 - in /commons/sandbox/runtime/trunk/src/main:
java/org/apache/commons/runtime/io/ native/os/unix/ native/os/win32/
native/shared/
Author: mturk
Date: Thu Oct 8 15:41:40 2009
New Revision: 823210
URL: http://svn.apache.org/viewvc?rev=823210&view=rev
Log:
Fill in the FileInstance API
Modified:
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/FileWrapper.java
commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c
commons/sandbox/runtime/trunk/src/main/native/shared/fsysio.c
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=823210&r1=823209&r2=823210&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 Thu Oct 8 15:41:40 2009
@@ -489,9 +489,9 @@
/**
* Get system temporary directory path.
*
- * @param {@link java.io.File#pathSeparator} delimited list of directories
- * to use as temporary directory. Firts one that is accessible will
- * be used.
+ * @param searchPath {@link java.io.File#pathSeparator} delimited list of
+ * directories to use as temporary directory. Firts one that is
+ * accessible will be used.
* @return Temporary directory {@code File} instance.
* @throws SecurityException if Write access to directories listed inside
* {@code searchPath} is denied.
@@ -510,14 +510,11 @@
/**
* Get system temporary directory path.
*
- * @param {@link java.io.File#pathSeparator} delimited list of directories
- * to use as temporary directory. Firts one that is accessible will
- * be used.
* @return Temporary directory {@code File} instance.
* @throws SecurityException if Write access to system temporary directory
* is denied.
*/
- public synchronized static File getTempDirectory()
+ public synchronized static File getTempDirectory()
throws SecurityException
{
if (tmpDir == null) {
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=823210&r1=823209&r2=823210&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 Thu Oct 8 15:41:40 2009
@@ -21,12 +21,14 @@
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.TimeoutException;
import org.apache.commons.runtime.util.StringManager;
import java.io.Closeable;
import java.io.Flushable;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.SyncFailedException;
+import java.nio.ByteBuffer;
import java.util.EnumSet;
/**
@@ -39,9 +41,25 @@
*/
public class FileInstance implements Closeable, Flushable
{
+ /**
+ * Seek from the current position.
+ */
+ public static final int SEEK_CUR = 0;
+ /**
+ * Seek from the file begin
+ */
+ public static final int SEEK_SET = 1;
+ /**
+ * Seek from the currect end-of-file position
+ */
+ public static final int SEEK_END = 2;
+
/* File's descriptor object
*/
private Descriptor fd;
+ /* File's object lock
+ */
+ private Object sync = new Object();
/**
* Return the {@link Descriptor} accosicated with this file.
@@ -134,6 +152,354 @@
}
/**
+ * Clear the file errors.
+ * <p>
+ * Method clears all pending file errors and resets the
+ * end-of-file mark.
+ * </p>
+ *
+ * @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 void clearerr()
+ throws IOException
+ {
+ FileWrapper.clearerr(fd);
+ fd.clearerr();
+ }
+
+ /**
+ * Return cannonical file path.
+ * <p>
+ * Returned path is in Operating system cannonical form with all relative
+ * path elements removed. Depending on the Operating system this method
+ * either returns the real operating system file name, or tranformed file
+ * name by combining the currect working directory path and file path at the
+ * the time of file creation.
+ * </p>
+ *
+ * @return Cannonical file path.
+ *
+ * @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 String getPath()
+ throws IOException
+ {
+ return FileWrapper.name(fd);
+ }
+
+ /**
+ * Lock the entire file.
+ *
+ * @param type
+ * {@code FileLockType} to acquire.
+ *
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the lock
+ * operation is in progress.
+ * @throws TimeoutException
+ * If lock operation times out.
+ * @throws IOException
+ * If some other I/O error occurs.
+ * @see #unlock
+ */
+ public void lock(EnumSet<FileLockType> type)
+ throws IOException
+ {
+ FileWrapper.lock(fd, type);
+ }
+
+ /**
+ * Lock the file region.
+ * <p>
+ * Locking a region of file gives a locking process exclusive access to
+ * the specified file region. Locking can go beyond the end of the current
+ * file. This is useful to coordinate adding records to the end of file.
+ * </p>
+ * <p>
+ * <b>Warning:</b>
+ * <br/>
+ * Locks may not overlap and existing region of the file.
+ * </p>
+ *
+ * @param type
+ * {@code FileLockType} to acquire.
+ * @param offset
+ * The offset in bytes where the lock should begin.
+ * @param length
+ * The length of the byte region to be locked.
+ *
+ * @throws IllegalArgumentException
+ * If {@code offset < 0} or {@code length < 0}.
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the lock
+ * operation is in progress.
+ * @throws TimeoutException
+ * If read operation times out.
+ * @throws IOException
+ * If some other I/O error occurs.
+ * @see #unlock
+ */
+ public void lock(EnumSet<FileLockType> type, long offset, long length)
+ throws IllegalArgumentException, IOException
+ {
+ if (offset < 0 || length < 0 || offset < length) {
+ // unlock position is negative
+ throw new IllegalArgumentException();
+ }
+ FileWrapper.lock(fd, type, offset, length);
+ }
+
+ /**
+ * Unlock the file.
+ *
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the unlock
+ * operation is in progress.
+ * @throws TimeoutException
+ * If unlock operation times out.
+ * @throws IOException
+ * If some other I/O error occurs.
+ * @see #lock
+ */
+ public void unlock()
+ throws IOException
+ {
+ FileWrapper.unlock(fd);
+ }
+
+ /**
+ * Unlock the file region.
+ *
+ * @param offset
+ * The offset in bytes where the locked region begins.
+ * @param length
+ * The length of the byte region to be unlocked.
+ *
+ * @throws IllegalArgumentException
+ * If {@code offset < 0} or {@code length < 0}.
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the unlock
+ * operation is in progress.
+ * @throws TimeoutException
+ * If read operation times out.
+ * @throws IOException
+ * If some other I/O error occurs.
+ * @see #lock
+ */
+ public void unlock(long offset, long length)
+ throws IllegalArgumentException, IOException
+ {
+ if (offset < 0 || length < 0 || offset < length) {
+ // unlock position is negative
+ throw new IllegalArgumentException();
+ }
+ FileWrapper.unlock(fd, offset, length);
+ }
+
+ /**
+ * Moves this file's file pointer to a new position, from where following
+ * {@code read}, {@code write} or {@code skip} operations are done. The
+ * position may be greater than the current length of the file, but the
+ * file's length will only change if the moving of the pointer is followed
+ * by a {@code write} operation.
+ *
+ * @param pos
+ * The new file pointer position.
+ * @throws IllegalArgumentException
+ * If {@code pos < 0}.
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the set
+ * operation is in progress.
+ * @throws IOException
+ * If some other I/O error occurs.
+ */
+ public void setFilePointer(long pos)
+ throws IllegalArgumentException, IOException
+ {
+ if (pos < 0) {
+ // seek position is negative
+ throw new IllegalArgumentException();
+ }
+ synchronized (sync) {
+ FileWrapper.seek(fd, SEEK_SET, pos);
+ }
+ }
+
+ /**
+ * Moves this file's file pointer to a new position, from where following
+ * {@code read}, {@code write} or {@code skip} operations are done.
+ * Depending on the {@code moveMethod} the starting point for the
+ * file pointer move can be one of the following values:
+ * <pre>
+ * SEEK_SET The starting point is zero (0) or the beginning of the file.
+ * SEEK_CUR The starting point is the current value of the file pointer.
+ * SEEK_END The starting point is the current end-of-file position.
+ * <pre>
+ * @param moveMethod
+ * Starting point for the file pointer move.
+ * @param off
+ * Move offset in bytes.
+ *
+ * @throws IllegalArgumentException
+ * If {@code moveMethod < SEEK_CUR} or
+ * {@code moveMethod > SEEK_END}.
+ * @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 void moveFilePointer(int moveMethod, long off)
+ throws IOException
+ {
+ if (moveMethod < SEEK_CUR || moveMethod > SEEK_END) {
+ // move method is invalid
+ throw new IllegalArgumentException();
+ }
+ if (moveMethod == SEEK_SET && off < 0) {
+ // seek position is negative
+ throw new IllegalArgumentException();
+ }
+ synchronized (sync) {
+ FileWrapper.seek(fd, moveMethod, off);
+ }
+ }
+
+ /**
+ * Skips over {@code count} bytes in this file. Less than {@code count}
+ * bytes are skipped if the end of the file 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 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 int skipBytes(int count)
+ throws IOException
+ {
+ if (count > 0) {
+ synchronized (sync) {
+ long cur = FileWrapper.seek(fd, SEEK_CUR, 0L);
+ long eof = FileWrapper.seek(fd, SEEK_END, 0L);
+
+ int cnt = (int)((cur + count > eof) ? eof - cur : count);
+ FileWrapper.seek(fd, SEEK_SET, cnt);
+ return cnt;
+ }
+ }
+ return 0;
+ }
+
+ /**
+ * Gets the current position within this file. All reads and
+ * writes take place at the current file pointer position.
+ *
+ * @return the current offset in bytes from the beginning of the file.
+ *
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the get
+ * operation is in progress.
+ * @throws IOException
+ * If some other I/O error occurs.
+ */
+ public long getFilePointer()
+ throws IOException
+ {
+ return FileWrapper.seek(fd, SEEK_CUR, 0L);
+ }
+
+ /**
+ * 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 long length()
+ throws IOException
+ {
+ synchronized (sync) {
+ long cur = FileWrapper.seek(fd, SEEK_CUR, 0L);
+ long end = FileWrapper.seek(fd, SEEK_END, 0L);
+
+ FileWrapper.seek(fd, SEEK_SET, cur);
+ return end;
+ }
+ }
+
+ /**
+ * Sets the length of this file to {@code newLength}. If the current file is
+ * smaller, it is expanded but the contents from the previous end of the
+ * file to the new end are undefined. The file is truncated if its current
+ * size is bigger than {@code newLength}. If the current file pointer
+ * position is in the truncated part, it is set to the end of the file.
+ *
+ * @param newLength
+ * the new file length in bytes.
+ * @throws IllegalArgumentException
+ * If {@code newLength < 0}.
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the set
+ * operation is in progress.
+ * @throws IOException
+ * If some other I/O error occurs.
+ */
+ public void setLength(long newLength)
+ throws IllegalArgumentException, IOException
+ {
+ if (newLength < 0) {
+ throw new IllegalArgumentException();
+ }
+ synchronized (sync) {
+ FileWrapper.trunc(fd, newLength);
+ }
+ }
+
+ /**
* Reads a single byte from the current position in this file and returns
* it as an integer in the range from 0 to 255. Returns {@code -1} if the
* end of the file has been reached. Blocks until one byte has been read,
@@ -151,12 +517,42 @@
* If some other I/O error occurs.
*/
public int read()
- throws IndexOutOfBoundsException, IOException
+ throws IOException
{
return FileWrapper.read(fd);
}
/**
+ * Reads bytes from the current position in this file and stores them in the
+ * byte array {@code buffer}. The maximum number of bytes read corresponds
+ * to the size of {@code buffer}. Blocks until at least one byte has been
+ * read if the file is in blocking mode.
+ *
+ * @param buffer
+ * The byte array in which to store the bytes read.
+ * @return The number of bytes actually read or {@code -1} if the end of
+ * the file has been reached.
+ *
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the read
+ * operation is in progress.
+ * @throws TimeoutException
+ * If read operation times out.
+ * @throws IOException
+ * if this file is closed or another I/O error occurs.
+ */
+ public int read(byte[] buffer)
+ throws IOException
+ {
+ if (buffer.length == 0) {
+ return 0;
+ }
+ return FileWrapper.read(fd, buffer, 0, buffer.length);
+ }
+
+ /**
* Reads at most {@code count} bytes from the current position in this file
* and stores them in the byte array {@code buffer} starting at
* {@code offset}. Blocks until {@code count} bytes have been read,
@@ -181,6 +577,8 @@
* @throws AsyncClosedDescriptorException
* If another thread closes this file while the read
* operation is in progress.
+ * @throws TimeoutException
+ * If read operation times out.
* @throws IOException
* If some other I/O error occurs.
*/
@@ -196,4 +594,635 @@
}
return FileWrapper.read(fd, buffer, offset, count);
}
+
+ /**
+ * Reads bytes from the current position in this file and stores them in the
+ * {@code pointer}. The maximum number of bytes read corresponds
+ * to the size of {@code pointer}. Blocks until at least one byte has been
+ * read if the file is in blocking mode.
+ *
+ * @param pointer
+ * The {@code Pointer} in which to store the bytes read.
+ * @return The number of bytes actually read or {@code -1} if the end of
+ * the file has been reached.
+ *
+ * @throws NullPointerException
+ * If {@code pointer} is {@code null}.
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the read
+ * operation is in progress.
+ * @throws TimeoutException
+ * If read operation times out.
+ * @throws IOException
+ * if this file is closed or another I/O error occurs.
+ */
+ public long read(Pointer pointer)
+ throws NullPointerException, IOException
+ {
+ if (pointer.isNull())
+ throw new NullPointerException();
+ return FileWrapper.read(fd, pointer, 0L, pointer.sizeof());
+ }
+
+ /**
+ * Reads at most {@code count} bytes from the current position in this file
+ * and stores them in the Pointer {@code pointer} starting at
+ * {@code offset}. Blocks until {@code count} bytes have been read,
+ * the end of the file is reached or an exception is thrown.
+ *
+ * @param pointer
+ * The {code Pointer} in which to store the bytes read from
+ * this file.
+ * @param offset
+ * The initial position in {@code pointer} to store the bytes read
+ * from this file.
+ * @param count
+ * The maximum number of bytes to store in {@code pointer}.
+ *
+ * @return The number of bytes actually read or {@code -1} if the end of
+ * the stream has been reached.
+ *
+ * @throws NullPointerException
+ * If {@code pointer} is {@code null}.
+ * @throws IndexOutOfBoundsException
+ * If {@code offset < 0} or {@code count < 0}, or if
+ * {@code offset + count} is greater than the size of
+ * {@code buffer}.
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the read
+ * operation is in progress.
+ * @throws TimeoutException
+ * If read operation times out.
+ * @throws IOException
+ * If some other I/O error occurs.
+ */
+ public long read(Pointer pointer, long offset, long count)
+ throws NullPointerException, IndexOutOfBoundsException, IOException
+ {
+ if (pointer.isNull())
+ throw new NullPointerException();
+ if (count < 0 || offset < 0) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (count == 0L) {
+ /* Returning zero usually represents a timeout.
+ */
+ return 0L;
+ }
+ return FileWrapper.read(fd, pointer, offset, count);
+ }
+
+ /**
+ * Reads bytes from the current position in this file and stores them in the
+ * {@code buffer}. The maximum number of bytes read corresponds
+ * to the size of {@code buffer}. Blocks until at least one byte has been
+ * read if the file is in blocking mode.
+ *
+ * @param buffer
+ * The {@code ByteBuffer} in which to store the bytes read.
+ * @return The number of bytes actually read or {@code -1} if the end of
+ * the file has been reached.
+ *
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the read
+ * operation is in progress.
+ * @throws TimeoutException
+ * If read operation times out.
+ * @throws IOException
+ * if this file is closed or another I/O error occurs.
+ */
+ public int read(ByteBuffer buffer)
+ throws IOException
+ {
+ return FileWrapper.read(fd, buffer, 0, buffer.capacity());
+ }
+
+ /**
+ * Reads at most {@code count} bytes from the current position in this file
+ * and stores them in the ByteBuffer {@code buffer} starting at
+ * {@code offset}. Blocks until {@code count} bytes have been read,
+ * the end of the file is reached or an exception is thrown.
+ *
+ * @param buffer
+ * The {code ByteBuffer} in which to store the bytes read from
+ * this file.
+ * @param offset
+ * The initial position in {@code buffer} to store the bytes read
+ * from this file.
+ * @param count
+ * The maximum number of bytes to store in {@code buffer}.
+ *
+ * @return The number of bytes actually read or {@code -1} if the end of
+ * the stream has been reached.
+ *
+ * @throws IndexOutOfBoundsException
+ * If {@code offset < 0} or {@code count < 0}, or if
+ * {@code offset + count} is greater than the size of
+ * {@code buffer}.
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the read
+ * operation is in progress.
+ * @throws TimeoutException
+ * If read operation times out.
+ * @throws IOException
+ * If some other I/O error occurs.
+ */
+ public int read(ByteBuffer buffer, int offset, int count)
+ throws IndexOutOfBoundsException, IOException
+ {
+ if (count > (buffer.capacity() - offset) || count < 0 || offset < 0)
+ throw new IndexOutOfBoundsException();
+ if (count == 0) {
+ /* Returning zero usually represents a timeout.
+ */
+ return 0;
+ }
+ return FileWrapper.read(fd, buffer, offset, count);
+ }
+
+ /**
+ * Writes a byte to this file, starting at the current file pointer. Only
+ * the least significant byte of the integer {@code b} is written.
+ *
+ * @param b
+ * the byte to write to this file.
+ *
+ * @return The number of bytes actually written.
+ *
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the read
+ * operation is in progress.
+ * @throws TimeoutException
+ * If write operation times out.
+ * @throws IOException
+ * If some other I/O error occurs.
+ */
+ public int write(int b)
+ throws IOException
+ {
+ return FileWrapper.write(fd, b);
+ }
+
+ /**
+ * Writes the entire contents of the byte array {@code buffer} to this file,
+ * starting at the current file pointer.
+ *
+ * @param buffer
+ * the buffer to write.
+ * @return The number of bytes actually written.
+ *
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the write
+ * operation is in progress.
+ * @throws TimeoutException
+ * If write operation times out.
+ * @throws IOException
+ * If some other I/O error occurs.
+ */
+ public int write(byte[] buffer)
+ throws IOException
+ {
+ if (buffer.length == 0) {
+ return 0;
+ }
+ return FileWrapper.write(fd, buffer, 0, buffer.length);
+ }
+
+ /**
+ * Writes {@code count} bytes from the byte array {@code buffer} to this
+ * file, starting at the current file pointer and using {@code offset} as
+ * the first position within {@code buffer} to get bytes.
+ *
+ * @param buffer
+ * The buffer to write to this file.
+ * @param offset
+ * The index of the first byte in {@code buffer} to write.
+ * @param count
+ * The number of bytes from {@code buffer} to write.
+ * @return The number of bytes actually written.
+ *
+ * @throws IndexOutOfBoundsException
+ * If {@code offset < 0} or {@code count < 0}, or if
+ * {@code offset + count} is greater than the size of
+ * {@code buffer}.
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the write
+ * operation is in progress.
+ * @throws TimeoutException
+ * If write operation times out.
+ * @throws IOException
+ * If some other I/O error occurs.
+ */
+ public int write(byte[] buffer, int offset, int count)
+ throws IndexOutOfBoundsException, IOException
+ {
+ if (count > (buffer.length - offset) || count < 0 || offset < 0) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (count == 0) {
+ return 0;
+ }
+ return FileWrapper.write(fd, buffer, offset, count);
+ }
+
+ /**
+ * Writes the entire contents of the Pointer {@code pointer} to this file,
+ * starting at the current file pointer.
+ *
+ * @param pointer
+ * the {@code Pointer} to write.
+ * @return The number of bytes actually written.
+ *
+ * @throws NullPointerException
+ * If {@code pointer} is {@code null}.
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the write
+ * operation is in progress.
+ * @throws TimeoutException
+ * If write operation times out.
+ * @throws IOException
+ * If some other I/O error occurs.
+ */
+ public long write(Pointer pointer)
+ throws NullPointerException, IOException
+ {
+ if (pointer.isNull())
+ throw new NullPointerException();
+ return FileWrapper.write(fd, pointer, 0L, pointer.sizeof());
+ }
+
+ /**
+ * Writes {@code count} bytes from the Pointer {@code pointer} to this
+ * file, starting at the current file pointer and using {@code offset} as
+ * the first position within {@code pointer} to get bytes.
+ *
+ * @param pointer
+ * The {@code Pointer} to write to this file.
+ * @param offset
+ * The index of the first byte in {@code pointer} to write.
+ * @param count
+ * The number of bytes from {@code pointer} to write.
+ * @return The number of bytes actually written.
+ *
+ * @throws NullPointerException
+ * If {@code pointer} is {@code null}.
+ * @throws IndexOutOfBoundsException
+ * If {@code offset < 0} or {@code count < 0}, or if
+ * {@code offset + count} is greater than the size of
+ * {@code pointer}.
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the write
+ * operation is in progress.
+ * @throws TimeoutException
+ * If write operation times out.
+ * @throws IOException
+ * If some other I/O error occurs.
+ */
+ public long write(Pointer pointer, int offset, int count)
+ throws IndexOutOfBoundsException, IOException
+ {
+ if (pointer.isNull())
+ throw new NullPointerException();
+ if (count < 0L || offset < 0L) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (count == 0) {
+ return 0;
+ }
+ return FileWrapper.write(fd, pointer, offset, count);
+ }
+
+ /**
+ * Writes the entire contents of the ByteBuffer {@code buffer} to this file,
+ * starting at the current file pointer.
+ *
+ * @param buffer
+ * The {@code ByteBuffer} to write.
+ * @return The number of bytes actually written.
+ *
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the write
+ * operation is in progress.
+ * @throws TimeoutException
+ * If write operation times out.
+ * @throws IOException
+ * If some other I/O error occurs.
+ */
+ public int write(ByteBuffer buffer)
+ throws IOException
+ {
+ return FileWrapper.write(fd, buffer, 0, buffer.capacity());
+ }
+
+ /**
+ * Writes {@code count} bytes from the ByteBuffer {@code buffer} to this
+ * file, starting at the current file pointer and using {@code offset} as
+ * the first position within {@code buffer} to get bytes.
+ *
+ * @param buffer
+ * The {@code ByteBuffer} to write to this file.
+ * @param offset
+ * The index of the first byte in {@code buffer} to write.
+ * @param count
+ * The number of bytes from {@code buffer} to write.
+ * @return The number of bytes actually written.
+ *
+ * @throws IndexOutOfBoundsException
+ * If {@code offset < 0} or {@code count < 0}, or if
+ * {@code offset + count} is greater than the size of
+ * {@code buffer}.
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the write
+ * operation is in progress.
+ * @throws TimeoutException
+ * If write operation times out.
+ * @throws IOException
+ * If some other I/O error occurs.
+ */
+ public int write(ByteBuffer buffer, int offset, int count)
+ throws IndexOutOfBoundsException, IOException
+ {
+ if (count > (buffer.capacity() - offset) || count < 0 || offset < 0) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (count == 0) {
+ return 0;
+ }
+ return FileWrapper.write(fd, buffer, offset, count);
+ }
+
+ /**
+ * Writes {@code count} arrays from the array of byte arrays {@code array}
+ * to this file, starting at the current file pointer and using
+ * {@code offset} as the first position within {@code array} to get bytes.
+ *
+ * @param array
+ * The array of buffer arrays to write to this file.
+ * @param offset
+ * The index of the first array in {@code array} to write.
+ * @param count
+ * The number of arrays from {@code array} to write.
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code count < 0}, {@code offset < 0} or
+ * {@code count + offset} is greater than the size of
+ * {@code array}.
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the write
+ * operation is in progress.
+ * @throws TimeoutException
+ * If write operation times out.
+ * @throws IOException
+ * If some other I/O error occurs.
+ */
+ public long write(byte[][] array, int offset, int count)
+ throws IndexOutOfBoundsException, IOException
+ {
+ if (count > (array.length - offset) || count < 0 || offset < 0) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (count == 0) {
+ return 0;
+ }
+ return FileWrapper.write(fd, array, offset, count);
+ }
+
+
+ /**
+ * Writes {@code count} arrays from the ByteBufferr {@code array}
+ * to this file, starting at the current file pointer and using
+ * {@code offset} as the first position within {@code array} to get bytes.
+ *
+ * @param array
+ * The {@code ByteBuffer} array to write to this file.
+ * @param offset
+ * The index of the first array in {@code array} to write.
+ * @param count
+ * The number of arrays from {@code array} to write.
+ * @throws IndexOutOfBoundsException
+ * if {@code count < 0}, {@code offset < 0} or
+ * {@code count + offset} is greater than the size of
+ * {@code array}.
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the write
+ * operation is in progress.
+ * @throws TimeoutException
+ * If write operation times out.
+ * @throws IOException
+ * If some other I/O error occurs.
+ */
+ public long write(ByteBuffer[] array, int offset, int count)
+ throws IndexOutOfBoundsException, IOException
+ {
+ if (count > (array.length - offset) || count < 0 || offset < 0) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (count == 0) {
+ return 0;
+ }
+ return FileWrapper.write(fd, array, offset, count);
+ }
+
+
+ /**
+ * Writes {@code count} bytes from the byte array {@code buffer} to this
+ * file, starting at the current file pointer and using {@code offset} as
+ * the first position within {@code buffer} to get bytes.
+ * <p>
+ * Method tries to fully write provided data blocking if necessary
+ * regardless of file blocking mode.
+ * </p>
+ *
+ * @param buffer
+ * The buffer to write to this file.
+ * @param offset
+ * The index of the first byte in {@code buffer} to write.
+ * @param count
+ * The number of bytes from {@code buffer} to write.
+ * @return The number of bytes actually written.
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code count < 0}, {@code offset < 0} or
+ * {@code count + offset} is greater than the size of
+ * {@code array}.
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the write
+ * operation is in progress.
+ * @throws IOException
+ * If some other I/O error occurs.
+ */
+ public int writeFully(byte[] buffer, int offset, int count)
+ throws IndexOutOfBoundsException, IOException
+ {
+ if (count > (buffer.length - offset) || count < 0 || offset < 0) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (count == 0) {
+ return 0;
+ }
+ return FileWrapper.writeFully(fd, buffer, offset, count);
+ }
+
+ /**
+ * Writes the entire contents of the ByteBuffer {@code buffer} to this file,
+ * starting at the current file pointer.
+ *
+ * @param buffer
+ * the {@code ByteBuffer} to write.
+ * @return The number of bytes actually written.
+ *
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the write
+ * operation is in progress.
+ * @throws IOException
+ * If some other I/O error occurs.
+ */
+ public int writeFully(ByteBuffer buffer)
+ throws IOException
+ {
+ return FileWrapper.write(fd, buffer, 0, buffer.capacity());
+ }
+
+ /**
+ * Writes {@code count} bytes from the ByteBuffer {@code buffer} to this
+ * file, starting at the current file pointer and using {@code offset} as
+ * the first position within {@code buffer} to get bytes.
+ * <p>
+ * Method tries to fully write provided data blocking if necessary
+ * regardless of file blocking mode.
+ * </p>
+ *
+ * @param buffer
+ * The buffer to write to this file.
+ * @param offset
+ * The index of the first byte in {@code buffer} to write.
+ * @param count
+ * The number of bytes from {@code buffer} to write.
+ * @return The number of bytes actually written.
+ *
+ * @throws IndexOutOfBoundsException
+ * If {@code offset < 0} or {@code count < 0}, or if
+ * {@code offset + count} is greater than the size of
+ * {@code buffer}.
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the write
+ * operation is in progress.
+ * @throws IOException
+ * If some other I/O error occurs.
+ */
+ public int writeFully(ByteBuffer buffer, int offset, int count)
+ throws IndexOutOfBoundsException, IOException
+ {
+ if (count > (buffer.capacity() - offset) || count < 0 || offset < 0) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (count == 0) {
+ return 0;
+ }
+ return FileWrapper.writeFully(fd, buffer, offset, count);
+ }
+
+
+ /**
+ * Writes the entire contents of the Pointer {@code pointer} to this file,
+ * starting at the current file pointer.
+ *
+ * @param pointer
+ * the {@code Pointer} to write.
+ * @return The number of bytes actually written.
+ *
+ * @throws NullPointerException
+ * If {@code pointer} is {@code null}.
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the write
+ * operation is in progress.
+ * @throws TimeoutException
+ * If write operation times out.
+ * @throws IOException
+ * If some other I/O error occurs.
+ */
+ public long writeFully(Pointer pointer)
+ throws NullPointerException, IOException
+ {
+ if (pointer.isNull())
+ throw new NullPointerException();
+ return FileWrapper.write(fd, pointer, 0L, pointer.sizeof());
+ }
+
+ /**
+ * Writes {@code count} bytes from the Pointer {@code pointer} to this
+ * file, starting at the current file pointer and using {@code offset} as
+ * the first position within {@code buffer} to get bytes.
+ * <p>
+ * Method tries to fully write provided data blocking if necessary
+ * regardless of file blocking mode.
+ * </p>
+ *
+ * @param pointer
+ * The {@code Pointer} to write to this file.
+ * @param offset
+ * The index of the first byte in {@code pointer} to write.
+ * @param count
+ * The number of bytes from {@code pointer} to write.
+ * @return The number of bytes actually written.
+ *
+ * @throws NullPointerException
+ * If {@code pointer} is {@code null}.
+ * @throws IndexOutOfBoundsException
+ * If {@code offset < 0} or {@code count < 0}, or if
+ * {@code offset + count} is greater than the size of
+ * {@code pointer}.
+ * @throws ClosedDescriptorException
+ * If this file is closed.
+ * @throws AsyncClosedDescriptorException
+ * If another thread closes this file while the write
+ * operation is in progress.
+ * @throws IOException
+ * If some other I/O error occurs.
+ */
+ public long writeFully(Pointer pointer, long offset, long count)
+ throws NullPointerException, IndexOutOfBoundsException, IOException
+ {
+ if (pointer.isNull())
+ throw new NullPointerException();
+ if (count == 0) {
+ return 0;
+ }
+ return FileWrapper.writeFully(fd, pointer, offset, count);
+ }
+
}
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=823210&r1=823209&r2=823210&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 Thu Oct 8 15:41:40 2009
@@ -17,13 +17,18 @@
package org.apache.commons.runtime.io;
import org.apache.commons.runtime.Descriptor;
+import org.apache.commons.runtime.Pointer;
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.TimeoutException;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.nio.ByteBuffer;
import java.util.EnumSet;
/**
- * File wrappe class.
+ * File wrapper class.
* <p>
* Apache Commons Runtime {@code FileWrapper} provides static
* method API for native file portable layer.
@@ -38,6 +43,9 @@
}
private static native boolean eof0(int fd);
+ /**
+ * Returns {@code true} if file reached end-of-file.
+ */
public static boolean eof(Descriptor fd)
throws IOException
{
@@ -46,6 +54,33 @@
return eof0(fd.fd());
}
+ private static native int eof1(int fd);
+ /**
+ * Clear the file mark.
+ */
+ public static void clearerr(Descriptor fd)
+ throws IOException
+ {
+ if (!fd.valid())
+ throw new ClosedDescriptorException();
+ int rc = eof1(fd.fd());
+ if (rc != 0) {
+ throw new IOException(Status.describe(rc));
+ }
+ }
+
+ private static native String name0(int fd);
+ /**
+ * Returns real file name.
+ */
+ public static String name(Descriptor fd)
+ throws IOException
+ {
+ if (!fd.valid())
+ throw new ClosedDescriptorException();
+ return name0(fd.fd());
+ }
+
private static native Descriptor open0(String path, int mode)
throws FileNotFoundException, IOException, SecurityException;
/**
@@ -92,17 +127,112 @@
return open1(path.getPath(), imode, iprot);
}
+ private static native int lock0(int fd, int type)
+ throws IOException;
+ /**
+ * Lock the entire file.
+ *
+ */
+ public static void lock(Descriptor fd, EnumSet<FileLockType> type)
+ throws IOException
+ {
+ if (!fd.valid())
+ throw new ClosedDescriptorException();
+ int rc = lock0(fd.fd(), FileLockType.bitmapOf(type));
+ if (rc != 0) {
+ throw new IOException(Status.describe(rc));
+ }
+ }
+
+ private static native int lock1(int fd, int type, long off, long len)
+ throws IOException;
+ /**
+ * Lock file region.
+ *
+ */
+ public static void lock(Descriptor fd, EnumSet<FileLockType> type,
+ long off, long len)
+ throws IOException
+ {
+ if (!fd.valid())
+ throw new ClosedDescriptorException();
+ int rc = lock1(fd.fd(), FileLockType.bitmapOf(type), off, len);
+ if (rc != 0) {
+ throw new IOException(Status.describe(rc));
+ }
+ }
- private static native int read0(int fd);
+ private static native int unlock0(int fd)
+ throws IOException;
+ /**
+ * Unlock the entire file.
+ *
+ */
+ public static void unlock(Descriptor fd)
+ throws IOException
+ {
+ if (!fd.valid())
+ throw new ClosedDescriptorException();
+ int rc = unlock0(fd.fd());
+ if (rc != 0) {
+ throw new IOException(Status.describe(rc));
+ }
+ }
+
+ private static native int unlock1(int fd, long off, long len)
+ throws IOException;
+ /**
+ * Unlock file region.
+ *
+ */
+ public static void unlock(Descriptor fd, long off, long len)
+ throws IOException
+ {
+ if (!fd.valid())
+ throw new ClosedDescriptorException();
+ int rc = unlock1(fd.fd(), off, len);
+ if (rc != 0) {
+ throw new IOException(Status.describe(rc));
+ }
+ }
+
+ private static native long seek0(int fd, int whence, long off)
+ throws IOException;
+ /**
+ * Set file pointer
+ */
+ public static long seek(Descriptor fd, int whence, long off)
+ throws IOException
+ {
+ if (!fd.valid())
+ throw new ClosedDescriptorException();
+ return seek0(fd.fd(), whence, off);
+ }
+
+ private static native int trunc0(int fd, long len)
+ throws IOException;
+ /**
+ * Set new file length.
+ */
+ public static void trunc(Descriptor fd, long len)
+ throws IOException
+ {
+ if (!fd.valid())
+ throw new ClosedDescriptorException();
+ int rc = trunc0(fd.fd(), len);
+ if (rc != 0) {
+ throw new IOException(Status.describe(rc));
+ }
+ }
+
+ private static native int read0(int fd)
+ throws IOException;
/**
* Read one byte from the Descriptor.
* <p>
* On error {@code -1} is returned and {@code Descriptor.errno()}
* holds the error code.
* </p>
- *
- * return byte read or {@code -1} on error.
- * @throws ClosedDescriptorException if the {@code fd) is closed.
*/
public static int read(Descriptor fd)
throws IOException
@@ -112,21 +242,16 @@
return read0(fd.fd());
}
- private static native int read1(int fd, byte [] b, int off, int len);
+ private static native int read1(int fd, byte[] b, int off, int len)
+ throws IOException;
/**
* Reads up to {@code len} bytes of data from this file into an
* array of bytes. If {@code len} is not zero, the method blocks
* until some input is available; otherwise, no bytes are read and
* {@code 0} is returned.
- * <p>
- * On error {@code -1} is returned and {@code Descriptor.errno()}
- * holds the error code.
- * </p>
*
- * return byte read or {@code -1} on error.
- * @throws ClosedDescriptorException if the {@code fd) is closed.
*/
- public static int read(Descriptor fd, byte [] b, int off, int len)
+ public static int read(Descriptor fd, byte[] b, int off, int len)
throws IOException
{
if (!fd.valid())
@@ -134,7 +259,42 @@
return read1(fd.fd(), b, off, len);
}
- private static native int write0(int fd, int val);
+ private static native long read2(int fd, Pointer p, long off, long len)
+ throws IndexOutOfBoundsException, IOException;
+ /**
+ * Reads up to {@code len} bytes of data from this file into an
+ * {@code Pointer}. If {@code len} is not zero, the method blocks
+ * until some input is available; otherwise, no bytes are read and
+ * {@code 0} is returned.
+ *
+ */
+ public static long read(Descriptor fd, Pointer p, long off, long len)
+ throws IndexOutOfBoundsException, IOException
+ {
+ if (!fd.valid())
+ throw new ClosedDescriptorException();
+ return read2(fd.fd(), p, off, len);
+ }
+
+ private static native int read3(int fd, ByteBuffer b, int off, int len)
+ throws IOException;
+ /**
+ * Reads up to {@code len} bytes of data from this file into an direct
+ * {@code ByteBuffer}. If {@code len} is not zero, the method blocks
+ * until some input is available; otherwise, no bytes are read and
+ * {@code 0} is returned.
+ *
+ */
+ public static int read(Descriptor fd, ByteBuffer b, int off, int len)
+ throws IOException
+ {
+ if (!fd.valid())
+ throw new ClosedDescriptorException();
+ return read3(fd.fd(), b, off, len);
+ }
+
+ private static native int write0(int fd, int val)
+ throws IOException;
/**
* Write one byte to the Descriptor.
* <p>
@@ -142,8 +302,6 @@
* holds the error code.
* </p>
*
- * @return Number of bytes written
- * @throws ClosedDescriptorException if the {@code fd) is closed.
*/
public static int write(Descriptor fd, int val)
throws IOException
@@ -153,5 +311,132 @@
return write0(fd.fd(), val);
}
-}
+ private static native int write1(int fd, byte[] b, int off, int len)
+ throws IOException;
+ /**
+ * Writes {@code len} bytes from the byte array {@code b} to this
+ * file, starting at the current file pointer and using {@code off} as
+ * the first position within {@code buf} to get bytes.
+ *
+ */
+ public static int write(Descriptor fd, byte[] b, int off, int len)
+ throws IOException
+ {
+ if (!fd.valid())
+ throw new ClosedDescriptorException();
+ return write1(fd.fd(), b, off, len);
+ }
+ private static native long write2(int fd, Pointer p, long off, long len)
+ throws IndexOutOfBoundsException, IOException;
+ /**
+ * Writes {@code len} bytes from the byte array {@code b} to this
+ * file, starting at the current file pointer and using {@code off} as
+ * the first position within {@code b} to get bytes.
+ *
+ */
+ public static long write(Descriptor fd, Pointer p, long off, long len)
+ throws IndexOutOfBoundsException, IOException
+ {
+ if (!fd.valid())
+ throw new ClosedDescriptorException();
+ return write2(fd.fd(), p, off, len);
+ }
+
+ private static native int write3(int fd, ByteBuffer b, int off, int len)
+ throws IOException;
+ /**
+ * Writes {@code len} bytes from the ByteBuffer {@code b} to this
+ * file, starting at the current file pointer and using {@code off} as
+ * the first position within {@code buf} to get bytes.
+ *
+ */
+ public static int write(Descriptor fd, ByteBuffer b, int off, int len)
+ throws IOException
+ {
+ if (!fd.valid())
+ throw new ClosedDescriptorException();
+ return write3(fd.fd(), b, off, len);
+ }
+
+ private static native long write4(int fd, byte[][] a, int off, int len)
+ throws IndexOutOfBoundsException, IOException;
+ /**
+ * Writes {@code len} array from the array of byte arrays {@code a} to this
+ * file, starting at the current file pointer and using {@code off} as
+ * the first position within {@code a} to get bytes.
+ *
+ */
+ public static long write(Descriptor fd, byte[][] a, int off, int len)
+ throws IndexOutOfBoundsException, IOException
+ {
+ if (!fd.valid())
+ throw new ClosedDescriptorException();
+ return write4(fd.fd(), a, off, len);
+ }
+
+ private static native long write5(int fd, ByteBuffer[] a, int off, int len)
+ throws IndexOutOfBoundsException, IOException;
+ /**
+ * Writes {@code len} arrays from the ByteBuffer array {@code a} to this
+ * file, starting at the current file pointer and using {@code off} as
+ * the first position within {@code a} to get bytes.
+ *
+ */
+ public static long write(Descriptor fd, ByteBuffer[] a, int off, int len)
+ throws IndexOutOfBoundsException, IOException
+ {
+ if (!fd.valid())
+ throw new ClosedDescriptorException();
+ return write5(fd.fd(), a, off, len);
+ }
+
+ private static native int fullw0(int fd, byte[] b, int off, int len)
+ throws IOException;
+ /**
+ * Writes {@code len} bytes from the byte array {@code b} to this
+ * file, starting at the current file pointer and using {@code off} as
+ * the first position within {@code buf} to get bytes.
+ *
+ */
+ public static int writeFully(Descriptor fd, byte[] b, int off, int len)
+ throws IOException
+ {
+ if (!fd.valid())
+ throw new ClosedDescriptorException();
+ return fullw0(fd.fd(), b, off, len);
+ }
+
+ private static native long fullw1(int fd, Pointer p, long off, long len)
+ throws IOException;
+ /**
+ * Writes {@code len} bytes from the Pointer {@code p} to this
+ * file, starting at the current file pointer and using {@code off} as
+ * the first position within {@code p} to get bytes.
+ *
+ */
+ public static long writeFully(Descriptor fd, Pointer p, long off, long len)
+ throws IOException
+ {
+ if (!fd.valid())
+ throw new ClosedDescriptorException();
+ return fullw1(fd.fd(), p, off, len);
+ }
+
+ private static native int fullw2(int fd, ByteBuffer b, int off, int len)
+ throws IOException;
+ /**
+ * Writes {@code len} bytes from the ByteBuffer {@code b} to this
+ * file, starting at the current file pointer and using {@code off} as
+ * the first position within {@code b} to get bytes.
+ *
+ */
+ public static int writeFully(Descriptor fd, ByteBuffer b, int off, int len)
+ throws IOException
+ {
+ if (!fd.valid())
+ throw new ClosedDescriptorException();
+ return fullw2(fd.fd(), b, off, len);
+ }
+
+}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c?rev=823210&r1=823209&r2=823210&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c Thu Oct 8 15:41:40 2009
@@ -834,11 +834,11 @@
}
-ACR_IO_EXPORT_DECLARE(jint, FileWrapper, read2)(ACR_JNISTDARGS,
- jint file,
- jobject ptr,
- jlong off,
- jlong len)
+ACR_IO_EXPORT_DECLARE(jlong, FileWrapper, read2)(ACR_JNISTDARGS,
+ jint file,
+ jobject ptr,
+ jlong off,
+ jlong len)
{
size_t pl;
size_t po = (size_t)off;
@@ -881,7 +881,7 @@
rc = ACR_TIMEUP;
}
if (rd > 0)
- return (jint)rd;
+ return (jlong)rd;
ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
switch (rc) {
@@ -904,8 +904,8 @@
ACR_IO_EXPORT_DECLARE(jint, FileWrapper, read3)(ACR_JNISTDARGS,
jint file,
jobject dbb,
- jlong off,
- jlong len)
+ jint off,
+ jint len)
{
#if defined(_DEBUG)
size_t pl;
@@ -1079,11 +1079,11 @@
return -1;
}
-ACR_IO_EXPORT_DECLARE(jint, FileWrapper, write2)(ACR_JNISTDARGS,
- jint file,
- jobject ptr,
- jlong off,
- jlong len)
+ACR_IO_EXPORT_DECLARE(jlong, FileWrapper, write2)(ACR_JNISTDARGS,
+ jint file,
+ jobject ptr,
+ jlong off,
+ jlong len)
{
size_t pl;
size_t po = (size_t)off;
@@ -1123,7 +1123,7 @@
rc = ACR_TIMEUP;
}
if (wr > 0)
- return (jint)wr;
+ return (jlong)wr;
ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
switch (rc) {
@@ -1209,11 +1209,11 @@
}
#define ACR_IOVEC_ON_STACK 32
-ACR_IO_EXPORT_DECLARE(jint, FileWrapper, write4)(ACR_JNISTDARGS,
- jint file,
- jobjectArray vec,
- jint off,
- jint len)
+ACR_IO_EXPORT_DECLARE(jlong, FileWrapper, write4)(ACR_JNISTDARGS,
+ jint file,
+ jobjectArray vec,
+ jint off,
+ jint len)
{
size_t i;
size_t pl;
@@ -1286,7 +1286,7 @@
x_free(boa);
}
if (wr > 0)
- return (jint)wr;
+ return (jlong)wr;
ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
switch (rc) {
@@ -1304,11 +1304,11 @@
return -1;
}
-ACR_IO_EXPORT_DECLARE(jint, FileWrapper, write5)(ACR_JNISTDARGS,
- jint file,
- jobjectArray vec,
- jint off,
- jint len)
+ACR_IO_EXPORT_DECLARE(jlong, FileWrapper, write5)(ACR_JNISTDARGS,
+ jint file,
+ jobjectArray vec,
+ jint off,
+ jint len)
{
size_t i;
size_t pl;
@@ -1365,7 +1365,7 @@
if (iov != onstack)
x_free(iov);
if (wr > 0)
- return (jint)wr;
+ return (jlong)wr;
ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
switch (rc) {
@@ -1451,11 +1451,11 @@
return -1;
}
-ACR_IO_EXPORT_DECLARE(jint, FileWrapper, fullw1)(ACR_JNISTDARGS,
- jint file,
- jobject ptr,
- jlong off,
- jlong len)
+ACR_IO_EXPORT_DECLARE(jlong, FileWrapper, fullw1)(ACR_JNISTDARGS,
+ jint file,
+ jobject ptr,
+ jlong off,
+ jlong len)
{
size_t pl;
size_t po = (size_t)off;
@@ -1505,7 +1505,7 @@
rc = ACR_TIMEUP;
}
if (wt > 0)
- return (jint)wt;
+ return (jlong)wt;
ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
switch (rc) {
@@ -1526,8 +1526,8 @@
ACR_IO_EXPORT_DECLARE(jint, FileWrapper, fullw2)(ACR_JNISTDARGS,
jint file,
jobject dbb,
- jlong off,
- jlong len)
+ jint off,
+ jint len)
{
#if defined(_DEBUG)
size_t pl;
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c?rev=823210&r1=823209&r2=823210&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c Thu Oct 8 15:41:40 2009
@@ -1063,11 +1063,11 @@
return -1;
}
-ACR_IO_EXPORT_DECLARE(jint, FileWrapper, read2)(ACR_JNISTDARGS,
- jint file,
- jobject ptr,
- jlong off,
- jlong len)
+ACR_IO_EXPORT_DECLARE(jlong, FileWrapper, read2)(ACR_JNISTDARGS,
+ jint file,
+ jobject ptr,
+ jlong off,
+ jlong len)
{
size_t pl;
DWORD po = (DWORD)off;
@@ -1176,7 +1176,7 @@
finally:
if (rd > 0)
- return (jint)rd;
+ return (jlong)rd;
if (f->eof)
return -1;
@@ -1200,8 +1200,8 @@
ACR_IO_EXPORT_DECLARE(jint, FileWrapper, read3)(ACR_JNISTDARGS,
jint file,
jobject dbb,
- jlong off,
- jlong len)
+ jint off,
+ jint len)
{
#if defined(_DEBUG)
DWORD pl;
@@ -1554,11 +1554,11 @@
return -1;
}
-ACR_IO_EXPORT_DECLARE(jint, FileWrapper, write2)(ACR_JNISTDARGS,
- jint file,
- jobject ptr,
- jlong off,
- jlong len)
+ACR_IO_EXPORT_DECLARE(jlong, FileWrapper, write2)(ACR_JNISTDARGS,
+ jint file,
+ jobject ptr,
+ jlong off,
+ jlong len)
{
size_t pl;
jbyte *pb;
@@ -1657,7 +1657,7 @@
if (locked)
do_unlock(f);
if (wr)
- return (jint)wr;
+ return (jlong)wr;
ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
switch (rc) {
@@ -1679,8 +1679,8 @@
ACR_IO_EXPORT_DECLARE(jint, FileWrapper, write3)(ACR_JNISTDARGS,
jint file,
jobject dbb,
- jlong off,
- jlong len)
+ jint off,
+ jint len)
{
#if defined(_DEBUG)
DWORD pl;
@@ -1802,11 +1802,11 @@
return -1;
}
-ACR_IO_EXPORT_DECLARE(jint, FileWrapper, write4)(ACR_JNISTDARGS,
- jint file,
- jobjectArray vec,
- jint off,
- jint len)
+ACR_IO_EXPORT_DECLARE(jlong, FileWrapper, write4)(ACR_JNISTDARGS,
+ jint file,
+ jobjectArray vec,
+ jint off,
+ jint len)
{
DWORD i;
DWORD pl;
@@ -1818,7 +1818,7 @@
jbyte *bab;
DWORD bal;
int locked = 0;
- DWORD nbytes = 0;
+ INT64 nbytes = 0;
LPOVERLAPPED lpo = NULL;
acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
@@ -1913,7 +1913,7 @@
if (locked)
do_unlock(f);
if (nbytes)
- return (jint)nbytes;
+ return (jlong)nbytes;
ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
switch (rc) {
@@ -1947,7 +1947,7 @@
void *bbb;
DWORD bbl;
int locked = 0;
- DWORD nbytes = 0;
+ INT64 nbytes = 0;
LPOVERLAPPED lpo = NULL;
acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
@@ -2042,7 +2042,7 @@
if (locked)
do_unlock(f);
if (nbytes)
- return (jint)nbytes;
+ return (jlong)nbytes;
ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
switch (rc) {
@@ -2190,11 +2190,11 @@
return -1;
}
-ACR_IO_EXPORT_DECLARE(jint, FileWrapper, fullw1)(ACR_JNISTDARGS,
- jint file,
- jobject ptr,
- jlong off,
- jlong len)
+ACR_IO_EXPORT_DECLARE(jlong, FileWrapper, fullw1)(ACR_JNISTDARGS,
+ jint file,
+ jobject ptr,
+ jlong off,
+ jlong len)
{
size_t pl;
jbyte *pb;
@@ -2304,7 +2304,7 @@
if (locked)
do_unlock(f);
if (nbytes)
- return (jint)nbytes;
+ return (jlong)nbytes;
ACR_DescriptorSetErrEx(_E, f->descriptor, rc);
switch (rc) {
@@ -2326,8 +2326,8 @@
ACR_IO_EXPORT_DECLARE(jint, FileWrapper, fullw2)(ACR_JNISTDARGS,
jint file,
jobject dbb,
- jlong off,
- jlong len)
+ jint off,
+ jint len)
{
#if defined(_DEBUG)
DWORD pl;
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=823210&r1=823209&r2=823210&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/fsysio.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/fsysio.c Thu Oct 8 15:41:40 2009
@@ -57,6 +57,19 @@
return V2Z(f->eof);
}
+ACR_IO_EXPORT_DECLARE(jint, FileWrapper, eof1)(ACR_JNISTDARGS,
+ jint file)
+{
+ acr_file_t *f = (acr_file_t *)ACR_IOH_FDATA(file);
+
+ if (ACR_IOH_FTYPE(file) != ACR_DT_FILE)
+ return ACR_EFTYPE;
+ if (IS_INVALID_HANDLE(f))
+ return ACR_EBADF;
+ f->eof = 0;
+ return 0;
+}
+
ACR_IO_EXPORT_DECLARE(jboolean, FileWrapper, blocking0)(ACR_JNISTDARGS,
jint file)
{