aboutsummaryrefslogtreecommitdiff
path: root/libjava/java
diff options
context:
space:
mode:
authorPer Bothner <bothner@gcc.gnu.org>2004-03-03 15:50:03 -0800
committerPer Bothner <bothner@gcc.gnu.org>2004-03-03 15:50:03 -0800
commitdd0a905f24c159bc583a40aadedaf40a01c747bd (patch)
tree8da6fb814250474a55396eab60ccc38d2dedbe09 /libjava/java
parentd79944f48459240e0db73da18de5c6002f0238b6 (diff)
downloadgcc-dd0a905f24c159bc583a40aadedaf40a01c747bd.zip
gcc-dd0a905f24c159bc583a40aadedaf40a01c747bd.tar.gz
gcc-dd0a905f24c159bc583a40aadedaf40a01c747bd.tar.bz2
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
Diffstat (limited to 'libjava/java')
-rw-r--r--libjava/java/nio/channels/Channels.java14
-rw-r--r--libjava/java/nio/channels/natChannels.cc36
2 files changed, 48 insertions, 2 deletions
diff --git a/libjava/java/nio/channels/Channels.java b/libjava/java/nio/channels/Channels.java
index cb6154e..896e173 100644
--- a/libjava/java/nio/channels/Channels.java
+++ b/libjava/java/nio/channels/Channels.java
@@ -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.
*/
diff --git a/libjava/java/nio/channels/natChannels.cc b/libjava/java/nio/channels/natChannels.cc
new file mode 100644
index 0000000..5e363ee
--- /dev/null
+++ b/libjava/java/nio/channels/natChannels.cc
@@ -0,0 +1,36 @@
+// natChannels.cc - Native part of Channels class.
+
+/* Copyright (C) 2004 Free Software Foundation
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+#include <config.h>
+#include <gcj/cni.h>
+
+#include <java/nio/channels/Channels.h>
+#include <java/io/FileInputStream.h>
+#include <java/io/FileOutputStream.h>
+#include <gnu/java/nio/channels/FileChannelImpl.h>
+
+using java::nio::channels::Channels;
+using java::io::FileInputStream;
+using java::io::FileOutputStream;
+using gnu::java::nio::channels::FileChannelImpl;
+
+FileInputStream*
+Channels::newInputStream(FileChannelImpl* ch)
+{
+ // Needs to be native to bypass Java access protection.
+ return new FileInputStream (ch);
+}
+
+FileOutputStream*
+Channels::newOutputStream(FileChannelImpl* ch)
+{
+ // Needs to be native to bypass Java access protection.
+ return new FileOutputStream (ch);
+}