aboutsummaryrefslogtreecommitdiff
path: root/libjava/classpath/java/nio
diff options
context:
space:
mode:
authorMatthias Klose <doko@gcc.gnu.org>2007-08-04 10:53:49 +0000
committerMatthias Klose <doko@gcc.gnu.org>2007-08-04 10:53:49 +0000
commitf06a83c0b2f7761510836194a6c9a8a72000937c (patch)
tree871b70a606d87369d5aa9d6f621baedc13b49eba /libjava/classpath/java/nio
parent2c3de459b647a72fc35d66adeda274ba0f14347b (diff)
downloadgcc-f06a83c0b2f7761510836194a6c9a8a72000937c.zip
gcc-f06a83c0b2f7761510836194a6c9a8a72000937c.tar.gz
gcc-f06a83c0b2f7761510836194a6c9a8a72000937c.tar.bz2
Import GNU Classpath (libgcj-import-20070727).
libjava/ 2007-08-04 Matthias Klose <doko@ubuntu.com> Import GNU Classpath (libgcj-import-20070727). * Regenerate class and header files. * Regenerate auto* files. * include/jvm.h: * jni-libjvm.cc (Jv_JNI_InvokeFunctions): Rename type. * jni.cc (_Jv_JNIFunctions, _Jv_JNI_InvokeFunctions): Likewise. * jni.cc (_Jv_JNI_CallAnyMethodA, _Jv_JNI_CallAnyVoidMethodA, _Jv_JNI_CallMethodA, _Jv_JNI_CallVoidMethodA, _Jv_JNI_CallStaticMethodA, _Jv_JNI_CallStaticVoidMethodA, _Jv_JNI_NewObjectA, _Jv_JNI_SetPrimitiveArrayRegion): Constify jvalue parameter. * java/lang/reflect/natMethod.cc (_Jv_CallAnyMethodA): Likewise. * java/lang/VMFloat.java (toString, parseFloat): New. * gnu/awt/xlib/XToolkit.java (setAlwaysOnTop, isModalityTypeSupported, isModalExclusionTypeSupported): New (stub only). * gnu/awt/xlib/XCanvasPeer.java (requestFocus): Likewise. * gnu/awt/xlib/XFramePeer.java (updateMinimumSize, updateIconImages, updateFocusableWindowState, setModalBlocked, getBoundsPrivate, setAlwaysOnTop): Likewise. * gnu/awt/xlib/XFontPeer.java (canDisplay): Update signature. * scripts/makemake.tcl: Ignore gnu/javax/sound/sampled/gstreamer, ignore javax.sound.sampled.spi.MixerProvider, ignore .in files. * HACKING: Mention --enable-gstreamer-peer, removal of generated files. libjava/classpath/ 2007-08-04 Matthias Klose <doko@ubuntu.com> * java/util/EnumMap.java (clone): Add cast. From-SVN: r127204
Diffstat (limited to 'libjava/classpath/java/nio')
-rw-r--r--libjava/classpath/java/nio/Buffer.java61
-rw-r--r--libjava/classpath/java/nio/CharBuffer.java15
-rw-r--r--libjava/classpath/java/nio/CharSequenceBuffer.java208
-rw-r--r--libjava/classpath/java/nio/CharViewBufferImpl.java2
-rw-r--r--libjava/classpath/java/nio/DoubleViewBufferImpl.java2
-rw-r--r--libjava/classpath/java/nio/FloatViewBufferImpl.java2
-rw-r--r--libjava/classpath/java/nio/IntViewBufferImpl.java2
-rw-r--r--libjava/classpath/java/nio/LongViewBufferImpl.java2
-rw-r--r--libjava/classpath/java/nio/ShortViewBufferImpl.java2
9 files changed, 276 insertions, 20 deletions
diff --git a/libjava/classpath/java/nio/Buffer.java b/libjava/classpath/java/nio/Buffer.java
index 2c7e00d..c2569ee 100644
--- a/libjava/classpath/java/nio/Buffer.java
+++ b/libjava/classpath/java/nio/Buffer.java
@@ -358,4 +358,65 @@ public abstract class Buffer
(arraylength < length + offset))
throw new IndexOutOfBoundsException ();
}
+
+ /**
+ * Returns the backing array of this buffer, if this buffer has one.
+ * Modification to the array are directly visible in this buffer and vice
+ * versa.
+ *
+ * <p>
+ * If this is a read-only buffer, then a {@link ReadOnlyBufferException} is
+ * thrown because exposing the array would allow to circumvent the read-only
+ * property. If this buffer doesn't have an array, then an
+ * {@link UnsupportedOperationException} is thrown. Applications should check
+ * if this buffer supports a backing array by calling {@link #hasArray}
+ * first.</p>
+ *
+ * @return the backing array of this buffer
+ *
+ * @throws ReadOnlyBufferException when this buffer is read only
+ * @throws UnsupportedOperationException when this buffer does not provide
+ * a backing array
+ *
+ * @since 1.6
+ */
+ public abstract Object array();
+
+ /**
+ * Returns <code>true</code> if this buffer can provide a backing array,
+ * <code>false</code> otherwise. When <code>true</code>, application code
+ * can call {@link #array()} to access this backing array.
+ *
+ * @return <code>true</code> if this buffer can provide a backing array,
+ * <code>false</code> otherwise
+ *
+ * @since 1.6
+ */
+ public abstract boolean hasArray();
+
+ /**
+ * For buffers that are backed by a Java array, this returns the offset
+ * into that array at which the buffer content starts.
+ *
+ * @return the offset into the backing array at which the buffer content
+ * starts
+ * @throws ReadOnlyBufferException when this buffer is read only
+ * @throws UnsupportedOperationException when this buffer does not provide
+ * a backing array
+ *
+ * @since 1.6
+ */
+ public abstract int arrayOffset();
+
+ /**
+ * Returns <code>true</code> when this buffer is direct, <code>false</code>
+ * otherwise. A direct buffer is usually backed by a raw memory area instead
+ * of a Java array.
+ *
+ * @return <code>true</code> when this buffer is direct, <code>false</code>
+ * otherwise
+ *
+ * @since 1.6
+ */
+ public abstract boolean isDirect();
}
diff --git a/libjava/classpath/java/nio/CharBuffer.java b/libjava/classpath/java/nio/CharBuffer.java
index 34f429f..2feada4 100644
--- a/libjava/classpath/java/nio/CharBuffer.java
+++ b/libjava/classpath/java/nio/CharBuffer.java
@@ -107,20 +107,7 @@ public abstract class CharBuffer extends Buffer
*/
public static final CharBuffer wrap(CharSequence seq, int start, int end)
{
- // FIXME: implement better handling of java.lang.String.
- // Probably share data with String via reflection.
-
- int len = end - start;
-
- if( len < 0 )
- throw new IndexOutOfBoundsException();
-
- char[] buffer = new char[len];
-
- for (int i = 0; i < len; i++)
- buffer[i] = seq.charAt(i + start);
-
- return wrap(buffer, 0, len).asReadOnlyBuffer();
+ return new CharSequenceBuffer(seq, start, end);
}
/**
diff --git a/libjava/classpath/java/nio/CharSequenceBuffer.java b/libjava/classpath/java/nio/CharSequenceBuffer.java
new file mode 100644
index 0000000..26aad1c
--- /dev/null
+++ b/libjava/classpath/java/nio/CharSequenceBuffer.java
@@ -0,0 +1,208 @@
+/* CharBuffer.java --
+ Copyright (C) 2007 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.nio;
+
+/**
+ * A CharBuffer that wraps a {@link CharSequence}.
+ */
+final class CharSequenceBuffer
+ extends CharBuffer
+{
+
+ /**
+ * The wrapped char sequence.
+ */
+ private CharSequence charSequence;
+
+ /**
+ * Creates a new CharSequenceBuffer.
+ *
+ * @param charSeq the CharSequence to wrap
+ * @param capacity the capacity
+ * @param limit the limit
+ * @param position the position
+ * @param mark the mark
+ * @param offs the offset
+ */
+ CharSequenceBuffer(CharSequence charSeq, int capacity, int limit,
+ int position, int mark, int offs)
+ {
+ super(capacity, limit, position, mark);
+ charSequence = charSeq;
+ array_offset = offs;
+ }
+
+ /**
+ * Creates a new instance of CharSequenceBuffer, wrapping the specified
+ * {@link CharSequence}.
+ *
+ * @param charSeq the char sequence to wrap
+ * @param start the start index in the char sequence
+ * @param end the end index in the char sequence
+ */
+ CharSequenceBuffer(CharSequence charSeq, int start, int end)
+ {
+ this(charSeq, charSeq.length(), end, start, -1, 0);
+ }
+
+ /**
+ * Returns a read-only view of this buffer.
+ */
+ public CharBuffer asReadOnlyBuffer()
+ {
+ return duplicate();
+ }
+
+ /**
+ * This buffer class is not writable by definition and thus throws
+ * a ReadOnlyBufferException here.
+ */
+ public CharBuffer compact()
+ {
+ throw new ReadOnlyBufferException();
+ }
+
+ /**
+ * Returns a duplicate of this buffer.
+ *
+ * @return a duplicate of this buffer
+ */
+ public CharBuffer duplicate()
+ {
+ return new CharSequenceBuffer(charSequence, cap, limit, pos, mark, 0);
+ }
+
+ /**
+ * Returns the character at the current position.
+ *
+ * @return the character at the current position
+ */
+ public char get()
+ {
+ if (pos >= limit)
+ throw new BufferUnderflowException();
+
+ return charSequence.charAt(array_offset + pos++);
+ }
+
+ /**
+ * Returns the character at the specified position.
+ *
+ * @return the character at the specified position
+ */
+ public char get(int index)
+ {
+ if (index < 0 || index >= limit)
+ throw new IndexOutOfBoundsException();
+
+ return charSequence.charAt(array_offset + index);
+ }
+
+ /**
+ * Cannot be direct, return <code>false</code> here.
+ *
+ * @return false
+ */
+ public boolean isDirect()
+ {
+ return false;
+ }
+
+ /**
+ * Returns the byte order of this buffer. This is always the native byte
+ * order.
+ *
+ * @return the byte order of this buffer
+ */
+ public ByteOrder order()
+ {
+ return ByteOrder.nativeOrder();
+ }
+
+ /**
+ * This buffer class is not writable by definition and thus throws
+ * a ReadOnlyBufferException here.
+ */
+ public CharBuffer put(char b)
+ {
+ throw new ReadOnlyBufferException();
+ }
+
+ /**
+ * This buffer class is not writable by definition and thus throws
+ * a ReadOnlyBufferException here.
+ */
+ public CharBuffer put(int index, char b)
+ {
+ throw new ReadOnlyBufferException();
+ }
+
+ /**
+ * Returns a slice of this buffer, exposing the current position and limit.
+ */
+ public CharBuffer slice()
+ {
+ int newCapacity = limit - pos;
+ return new CharSequenceBuffer(charSequence, newCapacity, newCapacity, 0,
+ -1, pos);
+ }
+
+ /**
+ * Returns a sub sequence from the specified start index and with the
+ * specified length.
+ *
+ * @param start the start index
+ * @param length the length of the sub sequence
+ */
+ public CharSequence subSequence(int start, int length)
+ {
+ int begin = array_offset + start + pos;
+ return charSequence.subSequence(begin, begin + length);
+ }
+
+ /**
+ * This kind of CharBuffer is read-only, so we return <code>true</code>
+ * here.
+ */
+ public boolean isReadOnly()
+ {
+ return true;
+ }
+
+}
diff --git a/libjava/classpath/java/nio/CharViewBufferImpl.java b/libjava/classpath/java/nio/CharViewBufferImpl.java
index 3198315..33bbac8 100644
--- a/libjava/classpath/java/nio/CharViewBufferImpl.java
+++ b/libjava/classpath/java/nio/CharViewBufferImpl.java
@@ -133,7 +133,7 @@ class CharViewBufferImpl extends CharBuffer
public CharBuffer slice ()
{
// Create a sliced copy of this object that shares its content.
- return new CharViewBufferImpl (bb, (position () >> 1) + offset,
+ return new CharViewBufferImpl (bb, (position () << 1) + offset,
remaining (), remaining (), 0, -1,
isReadOnly (), endian);
}
diff --git a/libjava/classpath/java/nio/DoubleViewBufferImpl.java b/libjava/classpath/java/nio/DoubleViewBufferImpl.java
index e860f2f..d139915 100644
--- a/libjava/classpath/java/nio/DoubleViewBufferImpl.java
+++ b/libjava/classpath/java/nio/DoubleViewBufferImpl.java
@@ -130,7 +130,7 @@ final class DoubleViewBufferImpl extends DoubleBuffer
public DoubleBuffer slice ()
{
- return new DoubleViewBufferImpl (bb, (position () >> 3) + offset,
+ return new DoubleViewBufferImpl (bb, (position () << 3) + offset,
remaining(), remaining(), 0, -1,
readOnly, endian);
}
diff --git a/libjava/classpath/java/nio/FloatViewBufferImpl.java b/libjava/classpath/java/nio/FloatViewBufferImpl.java
index 55770d5..8bb342d 100644
--- a/libjava/classpath/java/nio/FloatViewBufferImpl.java
+++ b/libjava/classpath/java/nio/FloatViewBufferImpl.java
@@ -131,7 +131,7 @@ final class FloatViewBufferImpl extends FloatBuffer
public FloatBuffer slice ()
{
// Create a sliced copy of this object that shares its content.
- return new FloatViewBufferImpl (bb, (position () >> 2) + offset,
+ return new FloatViewBufferImpl (bb, (position () << 2) + offset,
remaining(), remaining(), 0, -1,
readOnly, endian);
}
diff --git a/libjava/classpath/java/nio/IntViewBufferImpl.java b/libjava/classpath/java/nio/IntViewBufferImpl.java
index d0b0057..cd8307f 100644
--- a/libjava/classpath/java/nio/IntViewBufferImpl.java
+++ b/libjava/classpath/java/nio/IntViewBufferImpl.java
@@ -131,7 +131,7 @@ final class IntViewBufferImpl extends IntBuffer
public IntBuffer slice ()
{
// Create a sliced copy of this object that shares its content.
- return new IntViewBufferImpl (bb, (position () >> 2) + offset,
+ return new IntViewBufferImpl (bb, (position () << 2) + offset,
remaining(), remaining(), 0, -1,
readOnly, endian);
}
diff --git a/libjava/classpath/java/nio/LongViewBufferImpl.java b/libjava/classpath/java/nio/LongViewBufferImpl.java
index 9c3452a..eefbcbd 100644
--- a/libjava/classpath/java/nio/LongViewBufferImpl.java
+++ b/libjava/classpath/java/nio/LongViewBufferImpl.java
@@ -131,7 +131,7 @@ final class LongViewBufferImpl extends LongBuffer
public LongBuffer slice ()
{
// Create a sliced copy of this object that shares its content.
- return new LongViewBufferImpl (bb, (position () >> 3) + offset,
+ return new LongViewBufferImpl (bb, (position () << 3) + offset,
remaining(), remaining(), 0, -1,
readOnly, endian);
}
diff --git a/libjava/classpath/java/nio/ShortViewBufferImpl.java b/libjava/classpath/java/nio/ShortViewBufferImpl.java
index cdd5595..df713361 100644
--- a/libjava/classpath/java/nio/ShortViewBufferImpl.java
+++ b/libjava/classpath/java/nio/ShortViewBufferImpl.java
@@ -131,7 +131,7 @@ final class ShortViewBufferImpl extends ShortBuffer
public ShortBuffer slice ()
{
// Create a sliced copy of this object that shares its content.
- return new ShortViewBufferImpl (bb, (position () >> 1) + offset,
+ return new ShortViewBufferImpl (bb, (position () << 1) + offset,
remaining(), remaining(), 0, -1,
readOnly, endian);
}