aboutsummaryrefslogtreecommitdiff
path: root/libjava/classpath/gnu/java/nio
diff options
context:
space:
mode:
authorTom Tromey <tromey@gcc.gnu.org>2005-09-23 21:31:04 +0000
committerTom Tromey <tromey@gcc.gnu.org>2005-09-23 21:31:04 +0000
commit1ea63ef8be1cc54dd0de9d82c684713a1dcf1e06 (patch)
tree3ca4b2e68dc14c3128b9c781d23f1d0b1f2bee49 /libjava/classpath/gnu/java/nio
parent9b044d19517541c95681d35a92dbc81e6e21d94f (diff)
downloadgcc-1ea63ef8be1cc54dd0de9d82c684713a1dcf1e06.zip
gcc-1ea63ef8be1cc54dd0de9d82c684713a1dcf1e06.tar.gz
gcc-1ea63ef8be1cc54dd0de9d82c684713a1dcf1e06.tar.bz2
Imported Classpath 0.18.
* sources.am, Makefile.in: Updated. * Makefile.am (nat_source_files): Removed natProxy.cc. * java/lang/reflect/natProxy.cc: Removed. * gnu/classpath/jdwp/VMFrame.java, gnu/classpath/jdwp/VMIdManager.java, gnu/classpath/jdwp/VMVirtualMachine.java, java/lang/reflect/VMProxy.java: New files. 2005-09-23 Thomas Fitzsimmons <fitzsim@redhat.com> * scripts/makemake.tcl (verbose): Add gnu/java/awt/peer/qt to BC list. 2005-09-23 Thomas Fitzsimmons <fitzsim@redhat.com> * gnu/java/net/DefaultContentHandlerFactory.java (getContent): Remove ClasspathToolkit references. 2005-09-23 Thomas Fitzsimmons <fitzsim@redhat.com> * gnu/awt/xlib/XCanvasPeer.java: Add new peer methods. * gnu/awt/xlib/XFramePeer.java: Likewise. * gnu/awt/xlib/XGraphicsConfiguration.java: Likewise. 2005-09-23 Thomas Fitzsimmons <fitzsim@redhat.com> * Makefile.am (libgcjawt_la_SOURCES): Remove jawt.c. Add classpath/native/jawt/jawt.c. * Makefile.in: Regenerate. * jawt.c: Remove file. * include/Makefile.am (tool_include__HEADERS): Remove jawt.h and jawt_md.h. Add ../classpath/include/jawt.h and ../classpath/include/jawt_md.h. * include/Makefile.in: Regenerate. * include/jawt.h: Regenerate. * include/jawt_md.h: Regenerate. From-SVN: r104586
Diffstat (limited to 'libjava/classpath/gnu/java/nio')
-rw-r--r--libjava/classpath/gnu/java/nio/FileLockImpl.java42
-rw-r--r--libjava/classpath/gnu/java/nio/channels/FileChannelImpl.java90
-rw-r--r--libjava/classpath/gnu/java/nio/charset/UTF_16Decoder.java12
-rw-r--r--libjava/classpath/gnu/java/nio/charset/iconv/IconvDecoder.java4
-rw-r--r--libjava/classpath/gnu/java/nio/charset/iconv/IconvEncoder.java4
5 files changed, 102 insertions, 50 deletions
diff --git a/libjava/classpath/gnu/java/nio/FileLockImpl.java b/libjava/classpath/gnu/java/nio/FileLockImpl.java
index 245fa73..673ca25 100644
--- a/libjava/classpath/gnu/java/nio/FileLockImpl.java
+++ b/libjava/classpath/gnu/java/nio/FileLockImpl.java
@@ -1,5 +1,5 @@
-/* FileLockImpl.java --
- Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+/* FileLockImpl.java -- FileLock associated with a FileChannelImpl.
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -44,20 +44,29 @@ import java.io.IOException;
import java.nio.channels.FileLock;
/**
+ * A FileLock associated with a FileChannelImpl.
+ *
* @author Michael Koch
* @since 1.4
*/
-public class FileLockImpl extends FileLock
+public final class FileLockImpl extends FileLock
{
- private FileChannelImpl ch;
-
+ /**
+ * Whether or not this lock is valid, false when channel is closed or
+ * release has been explicitly called.
+ */
+ private boolean valid;
+
public FileLockImpl (FileChannelImpl channel, long position,
long size, boolean shared)
{
super (channel, position, size, shared);
- ch = channel;
+ valid = true;
}
+ /**
+ * Releases this lock.
+ */
protected void finalize()
{
try
@@ -70,13 +79,26 @@ public class FileLockImpl extends FileLock
}
}
- public boolean isValid ()
+ /**
+ * Whether or not this lock is valid, false when channel is closed or
+ * release has been explicitly called.
+ */
+ public boolean isValid()
{
- return channel().isOpen();
+ if (valid)
+ valid = channel().isOpen();
+ return valid;
}
- public synchronized void release () throws IOException
+ /**
+ * Releases the lock if it is still valid. Marks this lock as invalid.
+ */
+ public void release() throws IOException
{
- ch.unlock(position(), size());
+ if (isValid())
+ {
+ valid = false;
+ ((FileChannelImpl) channel()).unlock(position(), size());
+ }
}
}
diff --git a/libjava/classpath/gnu/java/nio/channels/FileChannelImpl.java b/libjava/classpath/gnu/java/nio/channels/FileChannelImpl.java
index a87a2e8..0ee5d3f 100644
--- a/libjava/classpath/gnu/java/nio/channels/FileChannelImpl.java
+++ b/libjava/classpath/gnu/java/nio/channels/FileChannelImpl.java
@@ -73,6 +73,10 @@ public final class FileChannelImpl extends FileChannel
public static final int SYNC = 16;
public static final int DSYNC = 32;
+ public static FileChannelImpl in;
+ public static FileChannelImpl out;
+ public static FileChannelImpl err;
+
private static native void init();
static
@@ -83,6 +87,10 @@ public final class FileChannelImpl extends FileChannel
}
init();
+
+ in = new FileChannelImpl(0, READ);
+ out = new FileChannelImpl(1, WRITE);
+ err = new FileChannelImpl(2, WRITE);
}
/**
@@ -97,6 +105,8 @@ public final class FileChannelImpl extends FileChannel
private int mode;
+ final String description;
+
/* Open a file. MODE is a combination of the above mode flags. */
/* This is a static factory method, so that VM implementors can decide
* substitute subclasses of FileChannelImpl. */
@@ -109,7 +119,8 @@ public final class FileChannelImpl extends FileChannel
private FileChannelImpl(File file, int mode)
throws FileNotFoundException
{
- final String path = file.getPath();
+ String path = file.getPath();
+ description = path;
fd = open (path, mode);
this.mode = mode;
@@ -126,21 +137,26 @@ public final class FileChannelImpl extends FileChannel
/* ignore it */
}
- throw new FileNotFoundException(path + " is a directory");
+ throw new FileNotFoundException(description + " is a directory");
}
}
- /* Used by init() (native code) */
+ /**
+ * Constructor for default channels in, out and err.
+ *
+ * Used by init() (native code).
+ *
+ * @param fd the file descriptor (0, 1, 2 for stdin, stdout, stderr).
+ *
+ * @param mode READ or WRITE
+ */
FileChannelImpl (int fd, int mode)
{
this.fd = fd;
this.mode = mode;
+ this.description = "descriptor(" + fd + ")";
}
- public static FileChannelImpl in;
- public static FileChannelImpl out;
- public static FileChannelImpl err;
-
private native int open (String path, int mode) throws FileNotFoundException;
public native int available () throws IOException;
@@ -179,7 +195,7 @@ public final class FileChannelImpl extends FileChannel
throws IOException
{
if (position < 0)
- throw new IllegalArgumentException ();
+ throw new IllegalArgumentException ("position: " + position);
long oldPosition = implPosition ();
position (position);
int result = read(dst);
@@ -230,7 +246,7 @@ public final class FileChannelImpl extends FileChannel
throws IOException
{
if (position < 0)
- throw new IllegalArgumentException ();
+ throw new IllegalArgumentException ("position: " + position);
if (!isOpen ())
throw new ClosedChannelException ();
@@ -288,10 +304,11 @@ public final class FileChannelImpl extends FileChannel
throw new NonWritableChannelException();
}
else
- throw new IllegalArgumentException ();
+ throw new IllegalArgumentException ("mode: " + mode);
if (position < 0 || size < 0 || size > Integer.MAX_VALUE)
- throw new IllegalArgumentException ();
+ throw new IllegalArgumentException ("position: " + position
+ + ", size: " + size);
return mapImpl(nmode, position, (int) size);
}
@@ -336,7 +353,8 @@ public final class FileChannelImpl extends FileChannel
{
if (position < 0
|| count < 0)
- throw new IllegalArgumentException ();
+ throw new IllegalArgumentException ("position: " + position
+ + ", count: " + count);
if (!isOpen ())
throw new ClosedChannelException ();
@@ -399,7 +417,8 @@ public final class FileChannelImpl extends FileChannel
{
if (position < 0
|| count < 0)
- throw new IllegalArgumentException ();
+ throw new IllegalArgumentException ("position: " + position
+ + ", count: " + count);
if (!isOpen ())
throw new ClosedChannelException ();
@@ -424,24 +443,31 @@ public final class FileChannelImpl extends FileChannel
return total;
}
- public FileLock tryLock (long position, long size, boolean shared)
+ // Shared sanity checks between lock and tryLock methods.
+ private void lockCheck(long position, long size, boolean shared)
throws IOException
{
if (position < 0
|| size < 0)
- throw new IllegalArgumentException ();
+ throw new IllegalArgumentException ("position: " + position
+ + ", size: " + size);
if (!isOpen ())
- throw new ClosedChannelException ();
+ throw new ClosedChannelException();
- if (shared && (mode & READ) == 0)
- throw new NonReadableChannelException ();
-
- if (!shared && (mode & WRITE) == 0)
- throw new NonWritableChannelException ();
+ if (shared && ((mode & READ) == 0))
+ throw new NonReadableChannelException();
+ if (!shared && ((mode & WRITE) == 0))
+ throw new NonWritableChannelException();
+ }
+
+ public FileLock tryLock (long position, long size, boolean shared)
+ throws IOException
+ {
+ lockCheck(position, size, shared);
+
boolean completed = false;
-
try
{
begin();
@@ -468,15 +494,9 @@ public final class FileChannelImpl extends FileChannel
public FileLock lock (long position, long size, boolean shared)
throws IOException
{
- if (position < 0
- || size < 0)
- throw new IllegalArgumentException ();
-
- if (!isOpen ())
- throw new ClosedChannelException ();
+ lockCheck(position, size, shared);
boolean completed = false;
-
try
{
boolean lockable = lock(position, size, shared, true);
@@ -504,7 +524,7 @@ public final class FileChannelImpl extends FileChannel
throws IOException
{
if (newPosition < 0)
- throw new IllegalArgumentException ();
+ throw new IllegalArgumentException ("newPostition: " + newPosition);
if (!isOpen ())
throw new ClosedChannelException ();
@@ -519,7 +539,7 @@ public final class FileChannelImpl extends FileChannel
throws IOException
{
if (size < 0)
- throw new IllegalArgumentException ();
+ throw new IllegalArgumentException ("size: " + size);
if (!isOpen ())
throw new ClosedChannelException ();
@@ -532,4 +552,12 @@ public final class FileChannelImpl extends FileChannel
return this;
}
+
+ public String toString()
+ {
+ return (this.getClass()
+ + "[fd=" + fd
+ + ",mode=" + mode + ","
+ + description + "]");
+ }
}
diff --git a/libjava/classpath/gnu/java/nio/charset/UTF_16Decoder.java b/libjava/classpath/gnu/java/nio/charset/UTF_16Decoder.java
index 302c83e..e3927d9 100644
--- a/libjava/classpath/gnu/java/nio/charset/UTF_16Decoder.java
+++ b/libjava/classpath/gnu/java/nio/charset/UTF_16Decoder.java
@@ -1,5 +1,5 @@
/* UTF_16Decoder.java --
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -105,8 +105,9 @@ final class UTF_16Decoder extends CharsetDecoder
}
// FIXME: Change so you only do a single comparison here.
- char c = byteOrder == BIG_ENDIAN ? (char) ((b1 << 8) | b2)
- : (char) ((b2 << 8) | b1);
+ char c = (byteOrder == BIG_ENDIAN
+ ? (char) (((b1 & 0xFF) << 8) | (b2 & 0xFF))
+ : (char) (((b2 & 0xFF) << 8) | (b1 & 0xFF)));
if (0xD800 <= c && c <= 0xDFFF)
{
@@ -119,8 +120,9 @@ final class UTF_16Decoder extends CharsetDecoder
return CoderResult.UNDERFLOW;
byte b3 = in.get ();
byte b4 = in.get ();
- char d = byteOrder == BIG_ENDIAN ? (char) ((b3 << 8) | b4)
- : (char) ((b4 << 8) | b3);
+ char d = (byteOrder == BIG_ENDIAN
+ ? (char) (((b3 & 0xFF) << 8) | (b4 & 0xFF))
+ : (char) (((b4 & 0xFF) << 8) | (b3 & 0xFF)));
// make sure d is a low surrogate
if (d < 0xDC00 || d > 0xDFFF)
return CoderResult.malformedForLength (2);
diff --git a/libjava/classpath/gnu/java/nio/charset/iconv/IconvDecoder.java b/libjava/classpath/gnu/java/nio/charset/iconv/IconvDecoder.java
index fa265a9..fa6f497 100644
--- a/libjava/classpath/gnu/java/nio/charset/iconv/IconvDecoder.java
+++ b/libjava/classpath/gnu/java/nio/charset/iconv/IconvDecoder.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.nio.charset.iconv;
-import gnu.classpath.RawData;
+import gnu.classpath.Pointer;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
@@ -55,7 +55,7 @@ final class IconvDecoder extends CharsetDecoder
openIconv(info.iconvName());
}
- private RawData data;
+ private Pointer data;
private int inremaining;
private int outremaining;
diff --git a/libjava/classpath/gnu/java/nio/charset/iconv/IconvEncoder.java b/libjava/classpath/gnu/java/nio/charset/iconv/IconvEncoder.java
index bb10c9b..d5cc887 100644
--- a/libjava/classpath/gnu/java/nio/charset/iconv/IconvEncoder.java
+++ b/libjava/classpath/gnu/java/nio/charset/iconv/IconvEncoder.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.nio.charset.iconv;
-import gnu.classpath.RawData;
+import gnu.classpath.Pointer;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
@@ -49,7 +49,7 @@ import java.nio.charset.CoderResult;
final class IconvEncoder extends CharsetEncoder
{
- private RawData data;
+ private Pointer data;
private int inremaining;
private int outremaining;