Commit 87939d70 by Michael Koch Committed by Michael Koch

2004-04-23 Michael Koch <konqueror@gmx.de>

	* gnu/java/nio/channels/FileChannelImpl.java
	(SET, CUR): Unused, removed.
	(read): Implement here directly.
	(implRead): Removed.
	(write): Implement here directly.
	(implWrite): Removed.

From-SVN: r81079
parent 5d837a58
2004-04-23 Michael Koch <konqueror@gmx.de>
* gnu/java/nio/channels/FileChannelImpl.java
(SET, CUR): Unused, removed.
(read): Implement here directly.
(implRead): Removed.
(write): Implement here directly.
(implWrite): Removed.
2004-04-23 Dalibor Topic <robilad@kaffe.org> 2004-04-23 Dalibor Topic <robilad@kaffe.org>
* javax/rmi/CORBA/PortableRemoteObjectDelegate.java, * javax/rmi/CORBA/PortableRemoteObjectDelegate.java,
......
...@@ -60,13 +60,8 @@ import java.nio.channels.WritableByteChannel; ...@@ -60,13 +60,8 @@ import java.nio.channels.WritableByteChannel;
* Instances of this class are created by invoking getChannel * Instances of this class are created by invoking getChannel
* Upon a Input/Output/RandomAccessFile object. * Upon a Input/Output/RandomAccessFile object.
*/ */
public final class FileChannelImpl extends FileChannel public final class FileChannelImpl extends FileChannel
{ {
// These are WHENCE values for seek.
static final int SET = 0;
static final int CUR = 1;
// These are mode values for open(). // These are mode values for open().
public static final int READ = 1; public static final int READ = 1;
public static final int WRITE = 2; public static final int WRITE = 2;
...@@ -139,7 +134,15 @@ public final class FileChannelImpl extends FileChannel ...@@ -139,7 +134,15 @@ public final class FileChannelImpl extends FileChannel
public int read (ByteBuffer dst) throws IOException public int read (ByteBuffer dst) throws IOException
{ {
return implRead (dst); int result;
byte[] buffer = new byte [dst.remaining ()];
result = read (buffer, 0, buffer.length);
if (result > 0)
dst.put (buffer, 0, result);
return result;
} }
public int read (ByteBuffer dst, long position) public int read (ByteBuffer dst, long position)
...@@ -149,25 +152,12 @@ public final class FileChannelImpl extends FileChannel ...@@ -149,25 +152,12 @@ public final class FileChannelImpl extends FileChannel
throw new IllegalArgumentException (); throw new IllegalArgumentException ();
long oldPosition = implPosition (); long oldPosition = implPosition ();
position (position); position (position);
int result = implRead (dst); int result = read(dst);
position (oldPosition); position (oldPosition);
return result; return result;
} }
private int implRead (ByteBuffer dst) throws IOException
{
int result;
byte[] buffer = new byte [dst.remaining ()];
result = read (buffer, 0, buffer.length);
if (result > 0)
dst.put (buffer, 0, result);
return result;
}
public native int read () public native int read ()
throws IOException; throws IOException;
...@@ -189,7 +179,20 @@ public final class FileChannelImpl extends FileChannel ...@@ -189,7 +179,20 @@ public final class FileChannelImpl extends FileChannel
public int write (ByteBuffer src) throws IOException public int write (ByteBuffer src) throws IOException
{ {
return implWrite (src); int len = src.remaining ();
if (src.hasArray())
{
byte[] buffer = src.array();
write(buffer, src.arrayOffset() + src.position(), len);
}
else
{
// Use a more efficient native method! FIXME!
byte[] buffer = new byte [len];
src.get (buffer, 0, len);
write (buffer, 0, len);
}
return len;
} }
public int write (ByteBuffer src, long position) public int write (ByteBuffer src, long position)
...@@ -209,30 +212,12 @@ public final class FileChannelImpl extends FileChannel ...@@ -209,30 +212,12 @@ public final class FileChannelImpl extends FileChannel
oldPosition = implPosition (); oldPosition = implPosition ();
seek (position); seek (position);
result = implWrite (src); result = write(src);
seek (oldPosition); seek (oldPosition);
return result; return result;
} }
private int implWrite (ByteBuffer src) throws IOException
{
int len = src.remaining ();
if (src.hasArray())
{
byte[] buffer = src.array();
write(buffer, src.arrayOffset() + src.position(), len);
}
else
{
// Use a more efficient native method! FIXME!
byte[] buffer = new byte [len];
src.get (buffer, 0, len);
write (buffer, 0, len);
}
return len;
}
public native void write (byte[] buffer, int offset, int length) public native void write (byte[] buffer, int offset, int length)
throws IOException; throws IOException;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment