Channels.java (newInputStream, [...]): Optimize when argument is a FileChannelImpl.

* java/nio/channels/Channels.java (newInputStream, newOutputStream):
	Optimize when argument is a FileChannelImpl.
	(newInputStream(FileChannelImpl), newOutputStream(FileChannelImpl)):
	New native methods.
	* java/nio/channels/natChannels.cc:  New file for new native methods.
	* Makefile.am:  Update accordingly.

From-SVN: r78867
This commit is contained in:
Per Bothner 2004-03-03 15:50:03 -08:00
parent d79944f484
commit dd0a905f24
5 changed files with 141 additions and 92 deletions

View file

@ -41,8 +41,11 @@ import gnu.java.nio.ChannelInputStream;
import gnu.java.nio.ChannelOutputStream;
import gnu.java.nio.InputStreamChannel;
import gnu.java.nio.OutputStreamChannel;
import gnu.java.nio.channels.FileChannelImpl;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.Charset;
@ -59,16 +62,23 @@ public final class Channels
*/
public static InputStream newInputStream(ReadableByteChannel ch)
{
if (ch instanceof FileChannelImpl)
return newInputStream((FileChannelImpl) ch);
return new ChannelInputStream(ch);
}
/**
* Constructs a stream that writes bytes to the given channel.
*/
public static OutputStream newOutputStream(WritableByteChannel ch)
{
if (ch instanceof FileChannelImpl)
return newOutputStream((FileChannelImpl) ch);
return new ChannelOutputStream(ch);
}
static native FileInputStream newInputStream(FileChannelImpl ch);
static native FileOutputStream newOutputStream(FileChannelImpl ch);
/**
* Constructs a channel that reads bytes from the given stream.
@ -77,7 +87,7 @@ public final class Channels
{
return new InputStreamChannel(in);
}
/**
* Constructs a channel that writes bytes to the given stream.
*/