Initial revision
From-SVN: r102074
This commit is contained in:
@@ -0,0 +1,361 @@
|
||||
/* Buffer.java --
|
||||
Copyright (C) 2002, 2003, 2004 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;
|
||||
|
||||
import gnu.classpath.RawData;
|
||||
|
||||
/**
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class Buffer
|
||||
{
|
||||
int cap = 0;
|
||||
int limit = 0;
|
||||
int pos = 0;
|
||||
int mark = -1;
|
||||
RawData address;
|
||||
|
||||
/**
|
||||
* Creates a new Buffer.
|
||||
*
|
||||
* Should be package private.
|
||||
*/
|
||||
Buffer (int capacity, int limit, int position, int mark)
|
||||
{
|
||||
if (capacity < 0)
|
||||
throw new IllegalArgumentException ();
|
||||
|
||||
cap = capacity;
|
||||
limit (limit);
|
||||
position (position);
|
||||
|
||||
if (mark >= 0)
|
||||
{
|
||||
if (mark > pos)
|
||||
throw new IllegalArgumentException ();
|
||||
|
||||
this.mark = mark;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the capacity of the buffer.
|
||||
*
|
||||
* @return the capacity of the buffer
|
||||
*/
|
||||
public final int capacity ()
|
||||
{
|
||||
return cap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the buffer.
|
||||
*
|
||||
* @return this buffer
|
||||
*/
|
||||
public final Buffer clear ()
|
||||
{
|
||||
limit = cap;
|
||||
pos = 0;
|
||||
mark = -1;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flips the buffer.
|
||||
*
|
||||
* @return this buffer
|
||||
*/
|
||||
public final Buffer flip ()
|
||||
{
|
||||
limit = pos;
|
||||
pos = 0;
|
||||
mark = -1;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the buffer has remaining data to read or not.
|
||||
*
|
||||
* @return true if the buffer contains remaining data to read,
|
||||
* false otherwise
|
||||
*/
|
||||
public final boolean hasRemaining ()
|
||||
{
|
||||
return remaining() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether this buffer is read only or not.
|
||||
*
|
||||
* @return true if the buffer is read only, false otherwise
|
||||
*/
|
||||
public abstract boolean isReadOnly ();
|
||||
|
||||
/**
|
||||
* Retrieves the current limit of the buffer.
|
||||
*
|
||||
* @return the limit of the buffer
|
||||
*/
|
||||
public final int limit ()
|
||||
{
|
||||
return limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this buffer's limit.
|
||||
*
|
||||
* @param newLimit The new limit value; must be non-negative and no larger
|
||||
* than this buffer's capacity.
|
||||
*
|
||||
* @return this buffer
|
||||
*
|
||||
* @exception IllegalArgumentException If the preconditions on newLimit
|
||||
* do not hold.
|
||||
*/
|
||||
public final Buffer limit (int newLimit)
|
||||
{
|
||||
if ((newLimit < 0) || (newLimit > cap))
|
||||
throw new IllegalArgumentException ();
|
||||
|
||||
if (newLimit < mark)
|
||||
mark = -1;
|
||||
|
||||
if (pos > newLimit)
|
||||
pos = newLimit;
|
||||
|
||||
limit = newLimit;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this buffer's mark at its position.
|
||||
*
|
||||
* @return this buffer
|
||||
*/
|
||||
public final Buffer mark ()
|
||||
{
|
||||
mark = pos;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the current position of this buffer.
|
||||
*
|
||||
* @return the current position of this buffer
|
||||
*/
|
||||
public final int position ()
|
||||
{
|
||||
return pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this buffer's position. If the mark is defined and larger than the
|
||||
* new position then it is discarded.
|
||||
*
|
||||
* @param newPosition The new position value; must be non-negative and no
|
||||
* larger than the current limit.
|
||||
*
|
||||
* @return this buffer
|
||||
*
|
||||
* @exception IllegalArgumentException If the preconditions on newPosition
|
||||
* do not hold
|
||||
*/
|
||||
public final Buffer position (int newPosition)
|
||||
{
|
||||
if ((newPosition < 0) || (newPosition > limit))
|
||||
throw new IllegalArgumentException ();
|
||||
|
||||
if (newPosition <= mark)
|
||||
mark = -1;
|
||||
|
||||
pos = newPosition;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements between the current position and the limit.
|
||||
*
|
||||
* @return the number of remaining elements
|
||||
*/
|
||||
public final int remaining()
|
||||
{
|
||||
return limit - pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets this buffer's position to the previously-marked position.
|
||||
*
|
||||
* @return this buffer
|
||||
*
|
||||
* @exception InvalidMarkException If the mark has not been set.
|
||||
*/
|
||||
public final Buffer reset()
|
||||
{
|
||||
if (mark == -1)
|
||||
throw new InvalidMarkException ();
|
||||
|
||||
pos = mark;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewinds this buffer. The position is set to zero and the mark
|
||||
* is discarded.
|
||||
*
|
||||
* @return this buffer
|
||||
*/
|
||||
public final Buffer rewind()
|
||||
{
|
||||
pos = 0;
|
||||
mark = -1;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for underflow. This method is used internally to check
|
||||
* whether a buffer has enough elements left to satisfy a read
|
||||
* request.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are no remaining
|
||||
* elements in this buffer.
|
||||
*/
|
||||
final void checkForUnderflow()
|
||||
{
|
||||
if (!hasRemaining())
|
||||
throw new BufferUnderflowException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for underflow. This method is used internally to check
|
||||
* whether a buffer has enough elements left to satisfy a read
|
||||
* request for a given number of elements.
|
||||
*
|
||||
* @param length The length of a sequence of elements.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are not enough
|
||||
* remaining elements in this buffer.
|
||||
*/
|
||||
final void checkForUnderflow(int length)
|
||||
{
|
||||
if (remaining() < length)
|
||||
throw new BufferUnderflowException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for overflow. This method is used internally to check
|
||||
* whether a buffer has enough space left to satisfy a write
|
||||
* request.
|
||||
*
|
||||
* @exception BufferOverflowException If there is no remaining
|
||||
* space in this buffer.
|
||||
*/
|
||||
final void checkForOverflow()
|
||||
{
|
||||
if (!hasRemaining())
|
||||
throw new BufferOverflowException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for overflow. This method is used internally to check
|
||||
* whether a buffer has enough space left to satisfy a write
|
||||
* request for a given number of elements.
|
||||
*
|
||||
* @param length The length of a sequence of elements.
|
||||
*
|
||||
* @exception BufferUnderflowException If there is not enough
|
||||
* remaining space in this buffer.
|
||||
*/
|
||||
final void checkForOverflow(int length)
|
||||
{
|
||||
if (remaining() < length)
|
||||
throw new BufferOverflowException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if index is negative or not smaller than the buffer's
|
||||
* limit. This method is used internally to check whether
|
||||
* an indexed request can be fulfilled.
|
||||
*
|
||||
* @param index The requested position in the buffer.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
*/
|
||||
final void checkIndex(int index)
|
||||
{
|
||||
if (index < 0
|
||||
|| index >= limit ())
|
||||
throw new IndexOutOfBoundsException ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if buffer is read-only. This method is used internally to
|
||||
* check if elements can be put into a buffer.
|
||||
*
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
final void checkIfReadOnly()
|
||||
{
|
||||
if (isReadOnly())
|
||||
throw new ReadOnlyBufferException ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether an array is large enough to hold the given number of
|
||||
* elements at the given offset. This method is used internally to
|
||||
* check if an array is big enough.
|
||||
*
|
||||
* @param arraylength The length of the array.
|
||||
* @param offset The offset within the array of the first byte to be read;
|
||||
* must be non-negative and no larger than arraylength.
|
||||
* @param length The number of bytes to be read from the given array;
|
||||
* must be non-negative and no larger than arraylength - offset.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold
|
||||
*/
|
||||
static final void checkArraySize(int arraylength, int offset, int length)
|
||||
{
|
||||
if ((offset < 0) ||
|
||||
(length < 0) ||
|
||||
(arraylength < length + offset))
|
||||
throw new IndexOutOfBoundsException ();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/* BufferOverflowException.java --
|
||||
Copyright (C) 2002 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;
|
||||
|
||||
/**
|
||||
* @since 1.4
|
||||
*/
|
||||
public class BufferOverflowException extends RuntimeException
|
||||
{
|
||||
/**
|
||||
* Creates the exception
|
||||
*/
|
||||
public BufferOverflowException ()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/* BufferUnderflowException.java --
|
||||
Copyright (C) 2002 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;
|
||||
|
||||
/**
|
||||
* @since 1.4
|
||||
*/
|
||||
public class BufferUnderflowException extends RuntimeException
|
||||
{
|
||||
/**
|
||||
* Creates the exception
|
||||
*/
|
||||
public BufferUnderflowException ()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,651 @@
|
||||
/* ByteBuffer.java --
|
||||
Copyright (C) 2002, 2003, 2004 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;
|
||||
|
||||
/**
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class ByteBuffer extends Buffer
|
||||
implements Comparable
|
||||
{
|
||||
ByteOrder endian = ByteOrder.BIG_ENDIAN;
|
||||
|
||||
int array_offset;
|
||||
byte[] backing_buffer;
|
||||
|
||||
ByteBuffer (int capacity, int limit, int position, int mark)
|
||||
{
|
||||
super (capacity, limit, position, mark);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a new direct byte buffer.
|
||||
*/
|
||||
public static ByteBuffer allocateDirect (int capacity)
|
||||
{
|
||||
return DirectByteBufferImpl.allocate (capacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a new <code>ByteBuffer</code> object with a given capacity.
|
||||
*/
|
||||
public static ByteBuffer allocate (int capacity)
|
||||
{
|
||||
return wrap(new byte[capacity], 0, capacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a <code>byte</code> array into a <code>ByteBuffer</code>
|
||||
* object.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold
|
||||
*/
|
||||
public static final ByteBuffer wrap (byte[] array, int offset, int length)
|
||||
{
|
||||
// FIXME: In GCJ and other implementations where arrays may not
|
||||
// move we might consider, at least when offset==0:
|
||||
// return new DirectByteBufferImpl(array,
|
||||
// address_of_data(array) + offset,
|
||||
// length, length, 0, false);
|
||||
// This may be more efficient, mainly because we can then use the
|
||||
// same logic for all ByteBuffers.
|
||||
|
||||
return new ByteBufferImpl (array, 0, array.length, offset + length, offset, -1, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a <code>byte</code> array into a <code>ByteBuffer</code>
|
||||
* object.
|
||||
*/
|
||||
public static final ByteBuffer wrap (byte[] array)
|
||||
{
|
||||
return wrap (array, 0, array.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method transfers <code>byte</code>s from this buffer into the given
|
||||
* destination array. Before the transfer, it checks if there are fewer than
|
||||
* length <code>byte</code>s remaining in this buffer.
|
||||
*
|
||||
* @param dst The destination array
|
||||
* @param offset The offset within the array of the first <code>byte</code>
|
||||
* to be written; must be non-negative and no larger than dst.length.
|
||||
* @param length The maximum number of bytes to be written to the given array;
|
||||
* must be non-negative and no larger than dst.length - offset.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are fewer than length
|
||||
* <code>byte</code>s remaining in this buffer.
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold.
|
||||
*/
|
||||
public ByteBuffer get (byte[] dst, int offset, int length)
|
||||
{
|
||||
checkArraySize(dst.length, offset, length);
|
||||
checkForUnderflow(length);
|
||||
|
||||
for (int i = offset; i < offset + length; i++)
|
||||
{
|
||||
dst [i] = get ();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method transfers <code>byte</code>s from this buffer into the given
|
||||
* destination array.
|
||||
*
|
||||
* @param dst The byte array to write into.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are fewer than dst.length
|
||||
* <code>byte</code>s remaining in this buffer.
|
||||
*/
|
||||
public ByteBuffer get (byte[] dst)
|
||||
{
|
||||
return get (dst, 0, dst.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the the <code>ByteBUFFER</code> src
|
||||
* into the buffer. Before the transfer, it checks if there is fewer than
|
||||
* <code>src.remaining()</code> space remaining in this buffer.
|
||||
*
|
||||
* @param src The source data.
|
||||
*
|
||||
* @exception BufferOverflowException If there is insufficient space in this
|
||||
* buffer for the remaining <code>byte</code>s in the source buffer.
|
||||
* @exception IllegalArgumentException If the source buffer is this buffer.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public ByteBuffer put (ByteBuffer src)
|
||||
{
|
||||
if (src == this)
|
||||
throw new IllegalArgumentException ();
|
||||
|
||||
checkForOverflow(src.remaining());
|
||||
|
||||
if (src.remaining () > 0)
|
||||
{
|
||||
byte[] toPut = new byte [src.remaining ()];
|
||||
src.get (toPut);
|
||||
put (toPut);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the the <code>byte array</code> src
|
||||
* into the buffer. Before the transfer, it checks if there is fewer than
|
||||
* length space remaining in this buffer.
|
||||
*
|
||||
* @param src The array to copy into the buffer.
|
||||
* @param offset The offset within the array of the first byte to be read;
|
||||
* must be non-negative and no larger than src.length.
|
||||
* @param length The number of bytes to be read from the given array;
|
||||
* must be non-negative and no larger than src.length - offset.
|
||||
*
|
||||
* @exception BufferOverflowException If there is insufficient space in this
|
||||
* buffer for the remaining <code>byte</code>s in the source array.
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public ByteBuffer put (byte[] src, int offset, int length)
|
||||
{
|
||||
checkArraySize(src.length, offset, length);
|
||||
checkForOverflow(length);
|
||||
|
||||
for (int i = offset; i < offset + length; i++)
|
||||
put (src [i]);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the the <code>byte array</code> src
|
||||
* into the buffer.
|
||||
*
|
||||
* @param src The array to copy into the buffer.
|
||||
*
|
||||
* @exception BufferOverflowException If there is insufficient space in this
|
||||
* buffer for the remaining <code>byte</code>s in the source array.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public final ByteBuffer put (byte[] src)
|
||||
{
|
||||
return put (src, 0, src.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether ot not this buffer is backed by an accessible
|
||||
* <code>byte</code> array.
|
||||
*/
|
||||
public final boolean hasArray ()
|
||||
{
|
||||
return (backing_buffer != null
|
||||
&& !isReadOnly ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <code>byte</code> array that backs this buffer.
|
||||
*
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
* @exception UnsupportedOperationException If this buffer is not backed
|
||||
* by an accessible array.
|
||||
*/
|
||||
public final byte[] array ()
|
||||
{
|
||||
if (backing_buffer == null)
|
||||
throw new UnsupportedOperationException ();
|
||||
|
||||
checkIfReadOnly();
|
||||
|
||||
return backing_buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the offset within this buffer's backing array of the first element.
|
||||
*
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
* @exception UnsupportedOperationException If this buffer is not backed
|
||||
* by an accessible array.
|
||||
*/
|
||||
public final int arrayOffset ()
|
||||
{
|
||||
if (backing_buffer == null)
|
||||
throw new UnsupportedOperationException ();
|
||||
|
||||
checkIfReadOnly();
|
||||
|
||||
return array_offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates a hash code for this buffer.
|
||||
*
|
||||
* This is done with <code>int</code> arithmetic,
|
||||
* where ** represents exponentiation, by this formula:<br>
|
||||
* <code>s[position()] + 31 + (s[position()+1] + 30)*31**1 + ... +
|
||||
* (s[limit()-1]+30)*31**(limit()-1)</code>.
|
||||
* Where s is the buffer data. Note that the hashcode is dependent
|
||||
* on buffer content, and therefore is not useful if the buffer
|
||||
* content may change.
|
||||
*
|
||||
* @return the hash code
|
||||
*/
|
||||
public int hashCode ()
|
||||
{
|
||||
int hashCode = get(position()) + 31;
|
||||
int multiplier = 1;
|
||||
for (int i = position() + 1; i < limit(); ++i)
|
||||
{
|
||||
multiplier *= 31;
|
||||
hashCode += (get(i) + 30)*multiplier;
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this buffer is equal to obj.
|
||||
*/
|
||||
public boolean equals (Object obj)
|
||||
{
|
||||
if (obj instanceof ByteBuffer)
|
||||
{
|
||||
return compareTo (obj) == 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two <code>ByteBuffer</code> objects.
|
||||
*
|
||||
* @exception ClassCastException If obj is not an object derived from
|
||||
* <code>ByteBuffer</code>.
|
||||
*/
|
||||
public int compareTo (Object obj)
|
||||
{
|
||||
ByteBuffer other = (ByteBuffer) obj;
|
||||
|
||||
int num = Math.min(remaining(), other.remaining());
|
||||
int pos_this = position();
|
||||
int pos_other = other.position();
|
||||
|
||||
for (int count = 0; count < num; count++)
|
||||
{
|
||||
byte a = get(pos_this++);
|
||||
byte b = other.get(pos_other++);
|
||||
|
||||
if (a == b)
|
||||
continue;
|
||||
|
||||
if (a < b)
|
||||
return -1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return remaining() - other.remaining();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the byte order of this buffer.
|
||||
*/
|
||||
public final ByteOrder order ()
|
||||
{
|
||||
return endian;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies this buffer's byte order.
|
||||
*/
|
||||
public final ByteBuffer order (ByteOrder endian)
|
||||
{
|
||||
this.endian = endian;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the <code>byte</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are no remaining
|
||||
* <code>byte</code>s in this buffer.
|
||||
*/
|
||||
public abstract byte get ();
|
||||
|
||||
/**
|
||||
* Writes the <code>byte</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferOverflowException If there no remaining
|
||||
* <code>byte</code>s in this buffer.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public abstract ByteBuffer put (byte b);
|
||||
|
||||
/**
|
||||
* Absolute get method.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
*/
|
||||
public abstract byte get (int index);
|
||||
|
||||
/**
|
||||
* Absolute put method.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public abstract ByteBuffer put (int index, byte b);
|
||||
|
||||
/**
|
||||
* Compacts this buffer.
|
||||
*
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public abstract ByteBuffer compact ();
|
||||
|
||||
void shiftDown (int dst_offset, int src_offset, int count)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
put(dst_offset + i, get(src_offset + i));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether or not this buffer is direct.
|
||||
*/
|
||||
public abstract boolean isDirect ();
|
||||
|
||||
/**
|
||||
* Creates a new <code>ByteBuffer</code> whose content is a shared
|
||||
* subsequence of this buffer's content.
|
||||
*/
|
||||
public abstract ByteBuffer slice ();
|
||||
|
||||
/**
|
||||
* Creates a new <code>ByteBuffer</code> that shares this buffer's
|
||||
* content.
|
||||
*/
|
||||
public abstract ByteBuffer duplicate ();
|
||||
|
||||
/**
|
||||
* Creates a new read-only <code>ByteBuffer</code> that shares this
|
||||
* buffer's content.
|
||||
*/
|
||||
public abstract ByteBuffer asReadOnlyBuffer ();
|
||||
|
||||
/**
|
||||
* Creates a view of this byte buffer as a short buffer.
|
||||
*/
|
||||
public abstract ShortBuffer asShortBuffer ();
|
||||
|
||||
/**
|
||||
* Creates a view of this byte buffer as a char buffer.
|
||||
*/
|
||||
public abstract CharBuffer asCharBuffer ();
|
||||
|
||||
/**
|
||||
* Creates a view of this byte buffer as an integer buffer.
|
||||
*/
|
||||
public abstract IntBuffer asIntBuffer ();
|
||||
|
||||
/**
|
||||
* Creates a view of this byte buffer as a long buffer.
|
||||
*/
|
||||
public abstract LongBuffer asLongBuffer ();
|
||||
|
||||
/**
|
||||
* Creates a view of this byte buffer as a float buffer.
|
||||
*/
|
||||
public abstract FloatBuffer asFloatBuffer ();
|
||||
|
||||
/**
|
||||
* Creates a view of this byte buffer as a double buffer.
|
||||
*/
|
||||
public abstract DoubleBuffer asDoubleBuffer ();
|
||||
|
||||
/**
|
||||
* Relative get method for reading a character value.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are fewer than two bytes
|
||||
* remaining in this buffer.
|
||||
*/
|
||||
public abstract char getChar ();
|
||||
|
||||
/**
|
||||
* Relative put method for writing a character value.
|
||||
*
|
||||
* @exception BufferOverflowException If this buffer's current position is
|
||||
* not smaller than its limit.
|
||||
*/
|
||||
public abstract ByteBuffer putChar (char value);
|
||||
|
||||
/**
|
||||
* Absolute get method for reading a character value.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If there are fewer than two bytes
|
||||
* remaining in this buffer
|
||||
*/
|
||||
public abstract char getChar (int index);
|
||||
|
||||
/**
|
||||
* Absolute put method for writing a character value.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit, minus one.
|
||||
*/
|
||||
public abstract ByteBuffer putChar (int index, char value);
|
||||
|
||||
/**
|
||||
* Relative get method for reading a short value.
|
||||
*
|
||||
* @exception BufferUnderflowException If index is negative or not smaller
|
||||
* than the buffer's limit, minus one.
|
||||
*/
|
||||
public abstract short getShort ();
|
||||
|
||||
/**
|
||||
* Relative put method for writing a short value.
|
||||
*
|
||||
* @exception BufferOverflowException If this buffer's current position is
|
||||
* not smaller than its limit.
|
||||
*/
|
||||
public abstract ByteBuffer putShort (short value);
|
||||
|
||||
/**
|
||||
* Absolute get method for reading a short value.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If there are fewer than two bytes
|
||||
* remaining in this buffer
|
||||
*/
|
||||
public abstract short getShort (int index);
|
||||
|
||||
/**
|
||||
* Absolute put method for writing a short value.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit, minus one.
|
||||
*/
|
||||
public abstract ByteBuffer putShort (int index, short value);
|
||||
|
||||
/**
|
||||
* Relative get method for reading an integer value.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are fewer than four bytes
|
||||
* remaining in this buffer.
|
||||
*/
|
||||
public abstract int getInt ();
|
||||
|
||||
/**
|
||||
* Relative put method for writing an integer value.
|
||||
*
|
||||
* @exception BufferOverflowException If this buffer's current position is
|
||||
* not smaller than its limit.
|
||||
*/
|
||||
public abstract ByteBuffer putInt (int value);
|
||||
|
||||
/**
|
||||
* Absolute get method for reading an integer value.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit, minus three.
|
||||
*/
|
||||
public abstract int getInt (int index);
|
||||
|
||||
/**
|
||||
* Absolute put method for writing an integer value.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit, minus three.
|
||||
*/
|
||||
public abstract ByteBuffer putInt (int index, int value);
|
||||
|
||||
/**
|
||||
* Relative get method for reading a long value.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are fewer than eight bytes
|
||||
* remaining in this buffer.
|
||||
*/
|
||||
public abstract long getLong ();
|
||||
|
||||
/**
|
||||
* Relative put method for writing a long value.
|
||||
*
|
||||
* @exception BufferOverflowException If this buffer's current position is
|
||||
* not smaller than its limit.
|
||||
*/
|
||||
public abstract ByteBuffer putLong (long value);
|
||||
|
||||
/**
|
||||
* Absolute get method for reading a long value.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit, minus seven.
|
||||
*/
|
||||
public abstract long getLong (int index);
|
||||
|
||||
/**
|
||||
* Absolute put method for writing a float value.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit, minus seven.
|
||||
*/
|
||||
public abstract ByteBuffer putLong (int index, long value);
|
||||
|
||||
/**
|
||||
* Relative get method for reading a float value.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are fewer than four bytes
|
||||
* remaining in this buffer.
|
||||
*/
|
||||
public abstract float getFloat ();
|
||||
|
||||
/**
|
||||
* Relative put method for writing a float value.
|
||||
*
|
||||
* @exception BufferOverflowException If there are fewer than four bytes
|
||||
* remaining in this buffer.
|
||||
*/
|
||||
public abstract ByteBuffer putFloat (float value);
|
||||
|
||||
/**
|
||||
* Absolute get method for reading a float value.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit, minus three.
|
||||
*/
|
||||
public abstract float getFloat (int index);
|
||||
|
||||
/**
|
||||
* Relative put method for writing a float value.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit, minus three.
|
||||
*/
|
||||
public abstract ByteBuffer putFloat (int index, float value);
|
||||
|
||||
/**
|
||||
* Relative get method for reading a double value.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are fewer than eight bytes
|
||||
* remaining in this buffer.
|
||||
*/
|
||||
public abstract double getDouble ();
|
||||
|
||||
/**
|
||||
* Relative put method for writing a double value.
|
||||
*
|
||||
* @exception BufferOverflowException If this buffer's current position is
|
||||
* not smaller than its limit.
|
||||
*/
|
||||
public abstract ByteBuffer putDouble (double value);
|
||||
|
||||
/**
|
||||
* Absolute get method for reading a double value.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit, minus seven.
|
||||
*/
|
||||
public abstract double getDouble (int index);
|
||||
|
||||
/**
|
||||
* Absolute put method for writing a double value.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit, minus seven.
|
||||
*/
|
||||
public abstract ByteBuffer putDouble (int index, double value);
|
||||
|
||||
/**
|
||||
* Returns a string summarizing the state of this buffer.
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
return getClass ().getName () +
|
||||
"[pos=" + position () +
|
||||
" lim=" + limit () +
|
||||
" cap=" + capacity () + "]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,344 @@
|
||||
/* ByteBufferImpl.java --
|
||||
Copyright (C) 2003, 2004, 2005 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;
|
||||
|
||||
/**
|
||||
* @author Michael Koch (konqueror@gmx.de)
|
||||
*/
|
||||
final class ByteBufferHelper
|
||||
{
|
||||
public static char getChar (ByteBuffer buffer, ByteOrder order)
|
||||
{
|
||||
return (char) getShort (buffer, order);
|
||||
}
|
||||
|
||||
public static void putChar (ByteBuffer buffer, char value, ByteOrder order)
|
||||
{
|
||||
putShort (buffer, (short) value, order);
|
||||
}
|
||||
|
||||
public static char getChar (ByteBuffer buffer, int index, ByteOrder order)
|
||||
{
|
||||
return (char) getShort (buffer, index, order);
|
||||
}
|
||||
|
||||
public static void putChar (ByteBuffer buffer, int index,
|
||||
char value, ByteOrder order)
|
||||
{
|
||||
putShort (buffer, index, (short) value, order);
|
||||
}
|
||||
|
||||
public static short getShort (ByteBuffer buffer, ByteOrder order)
|
||||
{
|
||||
buffer.checkForUnderflow(2);
|
||||
|
||||
if (order == ByteOrder.LITTLE_ENDIAN)
|
||||
{
|
||||
return (short) ((buffer.get() & 0xff)
|
||||
+ (buffer.get() << 8));
|
||||
}
|
||||
|
||||
return (short) ((buffer.get() << 8)
|
||||
+ (buffer.get() & 0xff));
|
||||
}
|
||||
|
||||
public static void putShort (ByteBuffer buffer, short value, ByteOrder order)
|
||||
{
|
||||
buffer.checkForOverflow(2);
|
||||
|
||||
if (order == ByteOrder.LITTLE_ENDIAN)
|
||||
{
|
||||
buffer.put ((byte) value);
|
||||
buffer.put ((byte) (value >> 8));
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.put ((byte) (value >> 8));
|
||||
buffer.put ((byte) value);
|
||||
}
|
||||
}
|
||||
|
||||
public static short getShort (ByteBuffer buffer,
|
||||
int index, ByteOrder order)
|
||||
{
|
||||
if (order == ByteOrder.LITTLE_ENDIAN)
|
||||
{
|
||||
return (short) ((buffer.get (index) & 0xff)
|
||||
+ (buffer.get (++index) << 8));
|
||||
}
|
||||
|
||||
return (short) ((buffer.get (index) << 8)
|
||||
+ (buffer.get (++index) & 0xff));
|
||||
}
|
||||
|
||||
public static void putShort (ByteBuffer buffer, int index,
|
||||
short value, ByteOrder order)
|
||||
{
|
||||
if (order == ByteOrder.LITTLE_ENDIAN)
|
||||
{
|
||||
buffer.put (index, (byte) value);
|
||||
buffer.put (++index, (byte) (value >> 8));
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.put (index, (byte) (value >> 8));
|
||||
buffer.put (++index, (byte) value);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getInt (ByteBuffer buffer, ByteOrder order)
|
||||
{
|
||||
buffer.checkForUnderflow(4);
|
||||
|
||||
if (order == ByteOrder.LITTLE_ENDIAN)
|
||||
{
|
||||
return ((buffer.get() & 0xff)
|
||||
+ ((buffer.get() & 0xff) << 8)
|
||||
+ ((buffer.get() & 0xff) << 16)
|
||||
+ (buffer.get() << 24));
|
||||
}
|
||||
|
||||
return (int) ((buffer.get() << 24)
|
||||
+ ((buffer.get() & 0xff) << 16)
|
||||
+ ((buffer.get() & 0xff) << 8)
|
||||
+ (buffer.get() & 0xff));
|
||||
}
|
||||
|
||||
public static void putInt (ByteBuffer buffer, int value, ByteOrder order)
|
||||
{
|
||||
buffer.checkForOverflow(4);
|
||||
|
||||
if (order == ByteOrder.LITTLE_ENDIAN)
|
||||
{
|
||||
buffer.put ((byte) value);
|
||||
buffer.put ((byte) (value >> 8));
|
||||
buffer.put ((byte) (value >> 16));
|
||||
buffer.put ((byte) (value >> 24));
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.put ((byte) (value >> 24));
|
||||
buffer.put ((byte) (value >> 16));
|
||||
buffer.put ((byte) (value >> 8));
|
||||
buffer.put ((byte) value);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getInt (ByteBuffer buffer, int index, ByteOrder order)
|
||||
{
|
||||
if (order == ByteOrder.LITTLE_ENDIAN)
|
||||
{
|
||||
return ((buffer.get (index) & 0xff)
|
||||
+ ((buffer.get (++index) & 0xff) << 8)
|
||||
+ ((buffer.get (++index) & 0xff) << 16)
|
||||
+ (buffer.get (++index) << 24));
|
||||
}
|
||||
|
||||
return ((buffer.get (index) << 24)
|
||||
+ ((buffer.get (++index) & 0xff) << 16)
|
||||
+ ((buffer.get (++index) & 0xff) << 8)
|
||||
+ (buffer.get (++index) & 0xff));
|
||||
}
|
||||
|
||||
public static void putInt (ByteBuffer buffer, int index,
|
||||
int value, ByteOrder order)
|
||||
{
|
||||
if (order == ByteOrder.LITTLE_ENDIAN)
|
||||
{
|
||||
buffer.put (index, (byte) value);
|
||||
buffer.put (++index, (byte) (value >> 8));
|
||||
buffer.put (++index, (byte) (value >> 16));
|
||||
buffer.put (++index, (byte) (value >> 24));
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.put (index, (byte) (value >> 24));
|
||||
buffer.put (++index, (byte) (value >> 16));
|
||||
buffer.put (++index, (byte) (value >> 8));
|
||||
buffer.put (++index, (byte) value);
|
||||
}
|
||||
}
|
||||
|
||||
public static long getLong (ByteBuffer buffer, ByteOrder order)
|
||||
{
|
||||
buffer.checkForUnderflow(8);
|
||||
|
||||
if (order == ByteOrder.LITTLE_ENDIAN)
|
||||
{
|
||||
return ((buffer.get() & 0xff)
|
||||
+ (((buffer.get() & 0xff)) << 8)
|
||||
+ (((buffer.get() & 0xff)) << 16)
|
||||
+ (((buffer.get() & 0xffL)) << 24)
|
||||
+ (((buffer.get() & 0xffL)) << 32)
|
||||
+ (((buffer.get() & 0xffL)) << 40)
|
||||
+ (((buffer.get() & 0xffL)) << 48)
|
||||
+ (((long) buffer.get()) << 56));
|
||||
}
|
||||
|
||||
return ((((long) buffer.get()) << 56)
|
||||
+ ((buffer.get() & 0xffL) << 48)
|
||||
+ ((buffer.get() & 0xffL) << 40)
|
||||
+ ((buffer.get() & 0xffL) << 32)
|
||||
+ ((buffer.get() & 0xffL) << 24)
|
||||
+ ((buffer.get() & 0xff) << 16)
|
||||
+ ((buffer.get() & 0xff) << 8)
|
||||
+ (buffer.get() & 0xff));
|
||||
}
|
||||
|
||||
public static void putLong (ByteBuffer buffer, long value, ByteOrder order)
|
||||
{
|
||||
buffer.checkForOverflow(8);
|
||||
|
||||
if (order == ByteOrder.LITTLE_ENDIAN)
|
||||
{
|
||||
buffer.put ((byte) value);
|
||||
buffer.put ((byte) (value >> 8));
|
||||
buffer.put ((byte) (value >> 16));
|
||||
buffer.put ((byte) (value >> 24));
|
||||
buffer.put ((byte) (value >> 32));
|
||||
buffer.put ((byte) (value >> 40));
|
||||
buffer.put ((byte) (value >> 48));
|
||||
buffer.put ((byte) (value >> 56));
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.put ((byte) (value >> 56));
|
||||
buffer.put ((byte) (value >> 48));
|
||||
buffer.put ((byte) (value >> 40));
|
||||
buffer.put ((byte) (value >> 32));
|
||||
buffer.put ((byte) (value >> 24));
|
||||
buffer.put ((byte) (value >> 16));
|
||||
buffer.put ((byte) (value >> 8));
|
||||
buffer.put ((byte) value);
|
||||
}
|
||||
}
|
||||
|
||||
public static long getLong (ByteBuffer buffer, int index, ByteOrder order)
|
||||
{
|
||||
if (order == ByteOrder.LITTLE_ENDIAN)
|
||||
{
|
||||
return ((buffer.get (index) & 0xff)
|
||||
+ ((buffer.get (++index) & 0xff) << 8)
|
||||
+ ((buffer.get (++index) & 0xff) << 16)
|
||||
+ ((buffer.get (++index) & 0xffL) << 24)
|
||||
+ ((buffer.get (++index) & 0xffL) << 32)
|
||||
+ ((buffer.get (++index) & 0xffL) << 40)
|
||||
+ ((buffer.get (++index) & 0xffL) << 48)
|
||||
+ (((long) buffer.get (++index)) << 56));
|
||||
}
|
||||
|
||||
return ((((long) buffer.get (index)) << 56)
|
||||
+ ((buffer.get (++index) & 0xffL) << 48)
|
||||
+ ((buffer.get (++index) & 0xffL) << 40)
|
||||
+ ((buffer.get (++index) & 0xffL) << 32)
|
||||
+ ((buffer.get (++index) & 0xffL) << 24)
|
||||
+ ((buffer.get (++index) & 0xff) << 16)
|
||||
+ ((buffer.get (++index) & 0xff) << 8)
|
||||
+ (buffer.get (++index) & 0xff));
|
||||
}
|
||||
|
||||
public static void putLong (ByteBuffer buffer, int index,
|
||||
long value, ByteOrder order)
|
||||
{
|
||||
if (order == ByteOrder.LITTLE_ENDIAN)
|
||||
{
|
||||
buffer.put (index, (byte) value);
|
||||
buffer.put (++index, (byte) (value >> 8));
|
||||
buffer.put (++index, (byte) (value >> 16));
|
||||
buffer.put (++index, (byte) (value >> 24));
|
||||
buffer.put (++index, (byte) (value >> 32));
|
||||
buffer.put (++index, (byte) (value >> 40));
|
||||
buffer.put (++index, (byte) (value >> 48));
|
||||
buffer.put (++index, (byte) (value >> 56));
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.put (index, (byte) (value >> 56));
|
||||
buffer.put (++index, (byte) (value >> 48));
|
||||
buffer.put (++index, (byte) (value >> 40));
|
||||
buffer.put (++index, (byte) (value >> 32));
|
||||
buffer.put (++index, (byte) (value >> 24));
|
||||
buffer.put (++index, (byte) (value >> 16));
|
||||
buffer.put (++index, (byte) (value >> 8));
|
||||
buffer.put (++index, (byte) value);
|
||||
}
|
||||
}
|
||||
|
||||
public static float getFloat (ByteBuffer buffer, ByteOrder order)
|
||||
{
|
||||
return Float.intBitsToFloat (getInt (buffer, order));
|
||||
}
|
||||
|
||||
public static void putFloat (ByteBuffer buffer, float value, ByteOrder order)
|
||||
{
|
||||
putInt (buffer, Float.floatToRawIntBits (value), order);
|
||||
}
|
||||
|
||||
public static float getFloat (ByteBuffer buffer, int index, ByteOrder order)
|
||||
{
|
||||
return Float.intBitsToFloat (getInt (buffer, index, order));
|
||||
}
|
||||
|
||||
public static void putFloat (ByteBuffer buffer, int index,
|
||||
float value, ByteOrder order)
|
||||
{
|
||||
putInt (buffer, index, Float.floatToRawIntBits (value), order);
|
||||
}
|
||||
|
||||
public static double getDouble (ByteBuffer buffer, ByteOrder order)
|
||||
{
|
||||
return Double.longBitsToDouble (getLong (buffer, order));
|
||||
}
|
||||
|
||||
public static void putDouble (ByteBuffer buffer, double value, ByteOrder order)
|
||||
{
|
||||
putLong (buffer, Double.doubleToRawLongBits (value), order);
|
||||
}
|
||||
|
||||
public static double getDouble (ByteBuffer buffer, int index, ByteOrder order)
|
||||
{
|
||||
return Double.longBitsToDouble (getLong (buffer, index, order));
|
||||
}
|
||||
|
||||
public static void putDouble (ByteBuffer buffer, int index,
|
||||
double value, ByteOrder order)
|
||||
{
|
||||
putLong (buffer, index, Double.doubleToRawLongBits (value), order);
|
||||
}
|
||||
} // ByteBufferHelper
|
||||
|
||||
@@ -0,0 +1,379 @@
|
||||
/* ByteBufferImpl.java --
|
||||
Copyright (C) 2002, 2003, 2004, 2005 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;
|
||||
|
||||
/**
|
||||
* This is a Heap memory implementation
|
||||
*/
|
||||
final class ByteBufferImpl extends ByteBuffer
|
||||
{
|
||||
private boolean readOnly;
|
||||
|
||||
ByteBufferImpl (byte[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly)
|
||||
{
|
||||
super (capacity, limit, position, mark);
|
||||
this.backing_buffer = buffer;
|
||||
this.array_offset = offset;
|
||||
this.readOnly = readOnly;
|
||||
}
|
||||
|
||||
public CharBuffer asCharBuffer ()
|
||||
{
|
||||
return new CharViewBufferImpl (this, remaining() >> 1);
|
||||
}
|
||||
|
||||
public ShortBuffer asShortBuffer ()
|
||||
{
|
||||
return new ShortViewBufferImpl (this, remaining() >> 1);
|
||||
}
|
||||
|
||||
public IntBuffer asIntBuffer ()
|
||||
{
|
||||
return new IntViewBufferImpl (this, remaining() >> 2);
|
||||
}
|
||||
|
||||
public LongBuffer asLongBuffer ()
|
||||
{
|
||||
return new LongViewBufferImpl (this, remaining() >> 3);
|
||||
}
|
||||
|
||||
public FloatBuffer asFloatBuffer ()
|
||||
{
|
||||
return new FloatViewBufferImpl (this, remaining() >> 2);
|
||||
}
|
||||
|
||||
public DoubleBuffer asDoubleBuffer ()
|
||||
{
|
||||
return new DoubleViewBufferImpl (this, remaining() >> 3);
|
||||
}
|
||||
|
||||
public boolean isReadOnly ()
|
||||
{
|
||||
return readOnly;
|
||||
}
|
||||
|
||||
public ByteBuffer slice ()
|
||||
{
|
||||
return new ByteBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ());
|
||||
}
|
||||
|
||||
public ByteBuffer duplicate ()
|
||||
{
|
||||
return new ByteBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ());
|
||||
}
|
||||
|
||||
public ByteBuffer asReadOnlyBuffer ()
|
||||
{
|
||||
return new ByteBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true);
|
||||
}
|
||||
|
||||
void shiftDown (int dst_offset, int src_offset, int count)
|
||||
{
|
||||
System.arraycopy(backing_buffer, array_offset + src_offset,
|
||||
backing_buffer, array_offset + dst_offset,
|
||||
count);
|
||||
}
|
||||
|
||||
public ByteBuffer compact ()
|
||||
{
|
||||
checkIfReadOnly();
|
||||
mark = -1;
|
||||
int pos = position();
|
||||
if (pos > 0)
|
||||
{
|
||||
int count = remaining();
|
||||
shiftDown(0, pos, count);
|
||||
position(count);
|
||||
limit(capacity());
|
||||
}
|
||||
else
|
||||
{
|
||||
position(limit());
|
||||
limit(capacity());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isDirect ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the <code>byte</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are no remaining
|
||||
* <code>bytes</code> in this buffer.
|
||||
*/
|
||||
public byte get ()
|
||||
{
|
||||
if (pos >= limit)
|
||||
throw new BufferUnderflowException();
|
||||
|
||||
return backing_buffer [(pos++) + array_offset];
|
||||
}
|
||||
|
||||
/**
|
||||
* Bulk get
|
||||
*/
|
||||
public ByteBuffer get (byte[] dst, int offset, int length)
|
||||
{
|
||||
checkArraySize(dst.length, offset, length);
|
||||
if ( (limit - pos) < length) // check for overflow
|
||||
throw new BufferUnderflowException();
|
||||
|
||||
System.arraycopy(backing_buffer, pos + array_offset,
|
||||
dst, offset, length);
|
||||
pos += length;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Relative bulk put(), overloads the ByteBuffer impl.
|
||||
*/
|
||||
public ByteBuffer put (byte[] src, int offset, int length)
|
||||
{
|
||||
if ( (limit - pos) < length) // check for overflow
|
||||
throw new BufferOverflowException();
|
||||
checkArraySize(src.length, offset, length);
|
||||
|
||||
System.arraycopy(src, offset, backing_buffer, pos + array_offset, length);
|
||||
pos += length;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Relative put method. Writes <code>value</code> to the next position
|
||||
* in the buffer.
|
||||
*
|
||||
* @exception BufferOverflowException If there is no remaining
|
||||
* space in this buffer.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public ByteBuffer put (byte value)
|
||||
{
|
||||
if (readOnly)
|
||||
throw new ReadOnlyBufferException();
|
||||
if (pos >= limit)
|
||||
throw new BufferOverflowException();
|
||||
|
||||
backing_buffer [(pos++) + array_offset] = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute get method. Reads the <code>byte</code> at position
|
||||
* <code>index</code>.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
*/
|
||||
public byte get (int index)
|
||||
{
|
||||
checkIndex(index);
|
||||
|
||||
return backing_buffer [index + array_offset];
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute put method. Writes <code>value</code> to position
|
||||
* <code>index</code> in the buffer.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public ByteBuffer put (int index, byte value)
|
||||
{
|
||||
checkIfReadOnly();
|
||||
checkIndex(index);
|
||||
|
||||
backing_buffer [index + array_offset] = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public char getChar ()
|
||||
{
|
||||
return ByteBufferHelper.getChar(this, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putChar (char value)
|
||||
{
|
||||
if (readOnly)
|
||||
throw new ReadOnlyBufferException ();
|
||||
if ( (limit-pos) < 2)
|
||||
throw new BufferOverflowException();
|
||||
|
||||
if (endian == ByteOrder.LITTLE_ENDIAN)
|
||||
{
|
||||
backing_buffer [(pos++) + array_offset] = (byte)(value&0xFF);
|
||||
backing_buffer [(pos++) + array_offset] = (byte)(value>>8);
|
||||
}
|
||||
else
|
||||
{
|
||||
backing_buffer [(pos++) + array_offset] = (byte)(value>>8);
|
||||
backing_buffer [(pos++) + array_offset] = (byte)(value&0xFF);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public char getChar (int index)
|
||||
{
|
||||
return ByteBufferHelper.getChar(this, index, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putChar (int index, char value)
|
||||
{
|
||||
ByteBufferHelper.putChar(this, index, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public short getShort ()
|
||||
{
|
||||
return ByteBufferHelper.getShort(this, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putShort (short value)
|
||||
{
|
||||
ByteBufferHelper.putShort(this, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public short getShort (int index)
|
||||
{
|
||||
return ByteBufferHelper.getShort(this, index, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putShort (int index, short value)
|
||||
{
|
||||
ByteBufferHelper.putShort(this, index, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getInt ()
|
||||
{
|
||||
return ByteBufferHelper.getInt(this, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putInt (int value)
|
||||
{
|
||||
ByteBufferHelper.putInt(this, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getInt (int index)
|
||||
{
|
||||
return ByteBufferHelper.getInt(this, index, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putInt (int index, int value)
|
||||
{
|
||||
ByteBufferHelper.putInt(this, index, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public long getLong ()
|
||||
{
|
||||
return ByteBufferHelper.getLong(this, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putLong (long value)
|
||||
{
|
||||
ByteBufferHelper.putLong (this, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public long getLong (int index)
|
||||
{
|
||||
return ByteBufferHelper.getLong (this, index, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putLong (int index, long value)
|
||||
{
|
||||
ByteBufferHelper.putLong (this, index, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public float getFloat ()
|
||||
{
|
||||
return ByteBufferHelper.getFloat (this, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putFloat (float value)
|
||||
{
|
||||
ByteBufferHelper.putFloat (this, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public float getFloat (int index)
|
||||
{
|
||||
return ByteBufferHelper.getFloat (this, index, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putFloat (int index, float value)
|
||||
{
|
||||
ByteBufferHelper.putFloat (this, index, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public double getDouble ()
|
||||
{
|
||||
return ByteBufferHelper.getDouble (this, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putDouble (double value)
|
||||
{
|
||||
ByteBufferHelper.putDouble (this, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public double getDouble (int index)
|
||||
{
|
||||
return ByteBufferHelper.getDouble (this, index, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putDouble (int index, double value)
|
||||
{
|
||||
ByteBufferHelper.putDouble (this, index, value, order());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/* ByteOrder.java --
|
||||
Copyright (C) 2002, 2004 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;
|
||||
|
||||
/**
|
||||
* @author Michael Koch (konqueror@gmx.de)
|
||||
* @since 1.4
|
||||
*/
|
||||
public final class ByteOrder
|
||||
{
|
||||
/**
|
||||
* Constant indicating big endian byte order.
|
||||
*/
|
||||
public static final ByteOrder BIG_ENDIAN = new ByteOrder();
|
||||
|
||||
/**
|
||||
* Constant indicating little endian byte order.
|
||||
*/
|
||||
public static final ByteOrder LITTLE_ENDIAN = new ByteOrder();
|
||||
|
||||
/**
|
||||
* Returns the native byte order of the platform currently running.
|
||||
*
|
||||
* @return the native byte order
|
||||
*/
|
||||
public static ByteOrder nativeOrder()
|
||||
{
|
||||
return (System.getProperty ("gnu.cpu.endian").equals("big")
|
||||
? BIG_ENDIAN : LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the byte order.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return this == BIG_ENDIAN ? "BIG_ENDIAN" : "LITTLE_ENDIAN";
|
||||
}
|
||||
|
||||
// This class can only be instantiated here.
|
||||
private ByteOrder()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,508 @@
|
||||
/* CharBuffer.java --
|
||||
Copyright (C) 2002, 2003, 2004 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;
|
||||
|
||||
/**
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class CharBuffer extends Buffer
|
||||
implements Comparable, CharSequence
|
||||
{
|
||||
int array_offset;
|
||||
char[] backing_buffer;
|
||||
|
||||
CharBuffer (int capacity, int limit, int position, int mark)
|
||||
{
|
||||
super (capacity, limit, position, mark);
|
||||
array_offset = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a new <code>CharBuffer</code> object with a given capacity.
|
||||
*/
|
||||
public static CharBuffer allocate (int capacity)
|
||||
{
|
||||
return new CharBufferImpl (capacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a <code>char</code> array into a <code>CharBuffer</code>
|
||||
* object.
|
||||
*
|
||||
* @param array the array to wrap
|
||||
* @param offset the offset of the region in the array to wrap
|
||||
* @param length the length of the region in the array to wrap
|
||||
*
|
||||
* @return a new <code>CharBuffer</code> object
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold
|
||||
*/
|
||||
public static final CharBuffer wrap(char[] array, int offset, int length)
|
||||
{
|
||||
return new CharBufferImpl(array, 0, array.length, offset + length, offset, -1, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a character sequence into a <code>CharBuffer</code> object.
|
||||
*
|
||||
* @param seq the sequence to wrap
|
||||
*
|
||||
* @return a new <code>CharBuffer</code> object
|
||||
*/
|
||||
public static final CharBuffer wrap(CharSequence seq)
|
||||
{
|
||||
return wrap(seq, 0, seq.length());
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a character sequence into a <code>CharBuffer</code> object.
|
||||
*
|
||||
* @param seq the sequence to wrap
|
||||
* @param start the index of the first character to wrap
|
||||
* @param end the index of the first character not to wrap
|
||||
*
|
||||
* @return a new <code>CharBuffer</code> object
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold
|
||||
*/
|
||||
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.
|
||||
|
||||
if ((start < 0)
|
||||
|| (start > seq.length())
|
||||
|| (end < start)
|
||||
|| (end > (seq.length() - start)))
|
||||
throw new IndexOutOfBoundsException();
|
||||
|
||||
int len = end - start;
|
||||
char[] buffer = new char[len];
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
buffer[i] = seq.charAt(i + start);
|
||||
|
||||
return wrap(buffer, 0, len).asReadOnlyBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a <code>char</code> array into a <code>CharBuffer</code>
|
||||
* object.
|
||||
*
|
||||
* @param array the array to wrap
|
||||
*
|
||||
* @return a new <code>CharBuffer</code> object
|
||||
*/
|
||||
public static final CharBuffer wrap(char[] array)
|
||||
{
|
||||
return wrap(array, 0, array.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method transfers <code>char</code>s from this buffer into the given
|
||||
* destination array. Before the transfer, it checks if there are fewer than
|
||||
* length <code>char</code>s remaining in this buffer.
|
||||
*
|
||||
* @param dst The destination array
|
||||
* @param offset The offset within the array of the first <code>char</code>
|
||||
* to be written; must be non-negative and no larger than dst.length.
|
||||
* @param length The maximum number of bytes to be written to the given array;
|
||||
* must be non-negative and no larger than dst.length - offset.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are fewer than length
|
||||
* <code>char</code>s remaining in this buffer.
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold.
|
||||
*/
|
||||
public CharBuffer get (char[] dst, int offset, int length)
|
||||
{
|
||||
checkArraySize(dst.length, offset, length);
|
||||
checkForUnderflow(length);
|
||||
|
||||
for (int i = offset; i < offset + length; i++)
|
||||
{
|
||||
dst [i] = get ();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method transfers <code>char</code>s from this buffer into the given
|
||||
* destination array.
|
||||
*
|
||||
* @param dst The byte array to write into.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are fewer than dst.length
|
||||
* <code>char</code>s remaining in this buffer.
|
||||
*/
|
||||
public CharBuffer get (char[] dst)
|
||||
{
|
||||
return get (dst, 0, dst.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the the <code>CharBUFFER</code> src
|
||||
* into the buffer. Before the transfer, it checks if there is fewer than
|
||||
* <code>src.remaining()</code> space remaining in this buffer.
|
||||
*
|
||||
* @param src The source data.
|
||||
*
|
||||
* @exception BufferOverflowException If there is insufficient space in this
|
||||
* buffer for the remaining <code>char</code>s in the source buffer.
|
||||
* @exception IllegalArgumentException If the source buffer is this buffer.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public CharBuffer put (CharBuffer src)
|
||||
{
|
||||
if (src == this)
|
||||
throw new IllegalArgumentException ();
|
||||
|
||||
checkForOverflow(src.remaining());
|
||||
|
||||
if (src.remaining () > 0)
|
||||
{
|
||||
char[] toPut = new char [src.remaining ()];
|
||||
src.get (toPut);
|
||||
put (toPut);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the the <code>char array</code> src
|
||||
* into the buffer. Before the transfer, it checks if there is fewer than
|
||||
* length space remaining in this buffer.
|
||||
*
|
||||
* @param src The array to copy into the buffer.
|
||||
* @param offset The offset within the array of the first byte to be read;
|
||||
* must be non-negative and no larger than src.length.
|
||||
* @param length The number of bytes to be read from the given array;
|
||||
* must be non-negative and no larger than src.length - offset.
|
||||
*
|
||||
* @exception BufferOverflowException If there is insufficient space in this
|
||||
* buffer for the remaining <code>char</code>s in the source array.
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public CharBuffer put (char[] src, int offset, int length)
|
||||
{
|
||||
checkArraySize(src.length, offset, length);
|
||||
checkForOverflow(length);
|
||||
|
||||
for (int i = offset; i < offset + length; i++)
|
||||
put (src [i]);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the the <code>char array</code> src
|
||||
* into the buffer.
|
||||
*
|
||||
* @param src The array to copy into the buffer.
|
||||
*
|
||||
* @exception BufferOverflowException If there is insufficient space in this
|
||||
* buffer for the remaining <code>char</code>s in the source array.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public final CharBuffer put (char[] src)
|
||||
{
|
||||
return put (src, 0, src.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether ot not this buffer is backed by an accessible
|
||||
* <code>char</code> array.
|
||||
*/
|
||||
public final boolean hasArray ()
|
||||
{
|
||||
return (backing_buffer != null
|
||||
&& !isReadOnly ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <code>char</code> array that backs this buffer.
|
||||
*
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
* @exception UnsupportedOperationException If this buffer is not backed
|
||||
* by an accessible array.
|
||||
*/
|
||||
public final char[] array ()
|
||||
{
|
||||
if (backing_buffer == null)
|
||||
throw new UnsupportedOperationException ();
|
||||
|
||||
checkIfReadOnly();
|
||||
|
||||
return backing_buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the offset within this buffer's backing array of the first element.
|
||||
*
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
* @exception UnsupportedOperationException If this buffer is not backed
|
||||
* by an accessible array.
|
||||
*/
|
||||
public final int arrayOffset ()
|
||||
{
|
||||
if (backing_buffer == null)
|
||||
throw new UnsupportedOperationException ();
|
||||
|
||||
checkIfReadOnly();
|
||||
|
||||
return array_offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates a hash code for this buffer.
|
||||
*
|
||||
* This is done with int arithmetic,
|
||||
* where ** represents exponentiation, by this formula:<br>
|
||||
* <code>s[position()] + 31 + (s[position()+1] + 30)*31**1 + ... +
|
||||
* (s[limit()-1]+30)*31**(limit()-1)</code>.
|
||||
* Where s is the buffer data. Note that the hashcode is dependent
|
||||
* on buffer content, and therefore is not useful if the buffer
|
||||
* content may change.
|
||||
*/
|
||||
public int hashCode ()
|
||||
{
|
||||
int hashCode = get(position()) + 31;
|
||||
int multiplier = 1;
|
||||
for (int i = position() + 1; i < limit(); ++i)
|
||||
{
|
||||
multiplier *= 31;
|
||||
hashCode += (get(i) + 30)*multiplier;
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this buffer is equal to obj.
|
||||
*/
|
||||
public boolean equals (Object obj)
|
||||
{
|
||||
if (obj instanceof CharBuffer)
|
||||
{
|
||||
return compareTo (obj) == 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two <code>CharBuffer</code> objects.
|
||||
*
|
||||
* @exception ClassCastException If obj is not an object derived from
|
||||
* <code>CharBuffer</code>.
|
||||
*/
|
||||
public int compareTo (Object obj)
|
||||
{
|
||||
CharBuffer other = (CharBuffer) obj;
|
||||
|
||||
int num = Math.min(remaining(), other.remaining());
|
||||
int pos_this = position();
|
||||
int pos_other = other.position();
|
||||
|
||||
for (int count = 0; count < num; count++)
|
||||
{
|
||||
char a = get(pos_this++);
|
||||
char b = other.get(pos_other++);
|
||||
|
||||
if (a == b)
|
||||
continue;
|
||||
|
||||
if (a < b)
|
||||
return -1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return remaining() - other.remaining();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the byte order of this buffer.
|
||||
*/
|
||||
public abstract ByteOrder order ();
|
||||
|
||||
/**
|
||||
* Reads the <code>char</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are no remaining
|
||||
* <code>char</code>s in this buffer.
|
||||
*/
|
||||
public abstract char get ();
|
||||
|
||||
/**
|
||||
* Writes the <code>char</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferOverflowException If there no remaining
|
||||
* <code>char</code>s in this buffer.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public abstract CharBuffer put (char b);
|
||||
|
||||
/**
|
||||
* Absolute get method.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
*/
|
||||
public abstract char get (int index);
|
||||
|
||||
/**
|
||||
* Absolute put method.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public abstract CharBuffer put (int index, char b);
|
||||
|
||||
/**
|
||||
* Compacts this buffer.
|
||||
*
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public abstract CharBuffer compact ();
|
||||
|
||||
/**
|
||||
* Tells wether or not this buffer is direct.
|
||||
*/
|
||||
public abstract boolean isDirect ();
|
||||
|
||||
/**
|
||||
* Creates a new <code>CharBuffer</code> whose content is a shared
|
||||
* subsequence of this buffer's content.
|
||||
*/
|
||||
public abstract CharBuffer slice ();
|
||||
|
||||
/**
|
||||
* Creates a new <code>CharBuffer</code> that shares this buffer's
|
||||
* content.
|
||||
*/
|
||||
public abstract CharBuffer duplicate ();
|
||||
|
||||
/**
|
||||
* Creates a new read-only <code>CharBuffer</code> that shares this
|
||||
* buffer's content.
|
||||
*/
|
||||
public abstract CharBuffer asReadOnlyBuffer ();
|
||||
|
||||
/**
|
||||
* Returns the remaining content of the buffer as a string.
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
if (hasArray ())
|
||||
return new String (array (), position (), length ());
|
||||
|
||||
char[] buf = new char [length ()];
|
||||
int pos = position ();
|
||||
get (buf, 0, buf.length);
|
||||
position (pos);
|
||||
return new String (buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of the remaining chars in this buffer.
|
||||
*/
|
||||
public final int length ()
|
||||
{
|
||||
return remaining ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new character buffer that represents the specified subsequence
|
||||
* of this buffer, relative to the current position.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If the preconditions on start and
|
||||
* end do not hold.
|
||||
*/
|
||||
public abstract CharSequence subSequence (int start, int length);
|
||||
|
||||
/**
|
||||
* Relative put method.
|
||||
*
|
||||
* @exception BufferOverflowException If there is insufficient space in this
|
||||
* buffer.
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the start
|
||||
* and end parameters do not hold.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public CharBuffer put (String str, int start, int length)
|
||||
{
|
||||
return put (str.toCharArray (), start, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Relative put method.
|
||||
*
|
||||
* @exception BufferOverflowException If there is insufficient space in this
|
||||
* buffer.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public final CharBuffer put (String str)
|
||||
{
|
||||
return put (str.toCharArray (), 0, str.length ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the character at <code>position() + index</code>.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative not smaller than
|
||||
* <code>remaining()</code>.
|
||||
*/
|
||||
public final char charAt (int index)
|
||||
{
|
||||
if (index < 0
|
||||
|| index >= remaining ())
|
||||
throw new IndexOutOfBoundsException ();
|
||||
|
||||
return get (position () + index);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
/* CharBufferImpl.java --
|
||||
Copyright (C) 2002, 2003, 2004 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;
|
||||
|
||||
/**
|
||||
* This is a Heap memory implementation
|
||||
*/
|
||||
final class CharBufferImpl extends CharBuffer
|
||||
{
|
||||
private boolean readOnly;
|
||||
|
||||
CharBufferImpl (int capacity)
|
||||
{
|
||||
this (new char [capacity], 0, capacity, capacity, 0, -1, false);
|
||||
}
|
||||
|
||||
CharBufferImpl (char[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly)
|
||||
{
|
||||
super (capacity, limit, position, mark);
|
||||
this.backing_buffer = buffer;
|
||||
this.array_offset = offset;
|
||||
this.readOnly = readOnly;
|
||||
}
|
||||
|
||||
public CharBufferImpl (CharBufferImpl copy)
|
||||
{
|
||||
super (copy.capacity (), copy.limit (), copy.position (), 0);
|
||||
backing_buffer = copy.backing_buffer;
|
||||
array_offset = copy.array_offset;
|
||||
readOnly = copy.isReadOnly ();
|
||||
}
|
||||
|
||||
public boolean isReadOnly ()
|
||||
{
|
||||
return readOnly;
|
||||
}
|
||||
|
||||
public CharBuffer slice ()
|
||||
{
|
||||
return new CharBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ());
|
||||
}
|
||||
|
||||
public CharBuffer duplicate ()
|
||||
{
|
||||
return new CharBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ());
|
||||
}
|
||||
|
||||
public CharBuffer asReadOnlyBuffer ()
|
||||
{
|
||||
return new CharBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true);
|
||||
}
|
||||
|
||||
public CharBuffer compact ()
|
||||
{
|
||||
checkIfReadOnly();
|
||||
mark = -1;
|
||||
int copied = 0;
|
||||
|
||||
while (remaining () > 0)
|
||||
{
|
||||
put (copied, get ());
|
||||
copied++;
|
||||
}
|
||||
|
||||
position (copied);
|
||||
limit(capacity());
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isDirect ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public CharSequence subSequence (int start, int end)
|
||||
{
|
||||
if (start < 0
|
||||
|| start > length ()
|
||||
|| end < start
|
||||
|| end > length ())
|
||||
throw new IndexOutOfBoundsException ();
|
||||
|
||||
return new CharBufferImpl (backing_buffer, array_offset, capacity (), position () + end, position () + start, -1, isReadOnly ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the <code>char</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are no remaining
|
||||
* <code>char</code>s in this buffer.
|
||||
*/
|
||||
public char get ()
|
||||
{
|
||||
if (pos >= limit)
|
||||
throw new BufferUnderflowException();
|
||||
|
||||
return backing_buffer [(pos++) + array_offset];
|
||||
}
|
||||
|
||||
/**
|
||||
* Relative put method. Writes <code>value</code> to the next position
|
||||
* in the buffer.
|
||||
*
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public CharBuffer put (char value)
|
||||
{
|
||||
if (readOnly)
|
||||
throw new ReadOnlyBufferException();
|
||||
if (pos >= limit)
|
||||
throw new BufferOverflowException();
|
||||
|
||||
backing_buffer [(pos++) + array_offset] = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute get method. Reads the <code>char</code> at position
|
||||
* <code>index</code>.
|
||||
*
|
||||
* @param index Position to read the <code>char</code> from.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
*/
|
||||
public char get (int index)
|
||||
{
|
||||
checkIndex(index);
|
||||
|
||||
return backing_buffer [index + array_offset];
|
||||
}
|
||||
|
||||
/**
|
||||
* Bulk get, overloaded for speed.
|
||||
*/
|
||||
public CharBuffer get (char[] dst, int offset, int length)
|
||||
{
|
||||
checkArraySize(dst.length, offset, length);
|
||||
checkForUnderflow(length);
|
||||
|
||||
System.arraycopy(backing_buffer, pos + array_offset,
|
||||
dst, offset, length);
|
||||
pos += length;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bulk put, overloaded for speed.
|
||||
*/
|
||||
public CharBuffer put (char[] src, int offset, int length)
|
||||
{
|
||||
checkArraySize(src.length, offset, length);
|
||||
checkForOverflow(length);
|
||||
|
||||
System.arraycopy(src, offset,
|
||||
backing_buffer, pos + array_offset, length);
|
||||
pos += length;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute put method. Writes <code>value</code> to position
|
||||
* <code>index</code> in the buffer.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public CharBuffer put (int index, char value)
|
||||
{
|
||||
checkIndex(index);
|
||||
checkIfReadOnly();
|
||||
|
||||
backing_buffer [index + array_offset] = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ByteOrder order ()
|
||||
{
|
||||
return ByteOrder.nativeOrder ();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
/* CharViewBufferImpl.java --
|
||||
Copyright (C) 2003, 2004 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;
|
||||
|
||||
class CharViewBufferImpl extends CharBuffer
|
||||
{
|
||||
/** Position in bb (i.e. a byte offset) where this buffer starts. */
|
||||
private int offset;
|
||||
private ByteBuffer bb;
|
||||
private boolean readOnly;
|
||||
private ByteOrder endian;
|
||||
|
||||
CharViewBufferImpl (ByteBuffer bb, int capacity)
|
||||
{
|
||||
super (capacity, capacity, 0, -1);
|
||||
this.bb = bb;
|
||||
this.offset = bb.position();
|
||||
this.readOnly = bb.isReadOnly();
|
||||
this.endian = bb.order();
|
||||
if (bb.isDirect())
|
||||
this.address = VMDirectByteBuffer.adjustAddress(bb.address, offset);
|
||||
}
|
||||
|
||||
public CharViewBufferImpl (ByteBuffer bb, int offset, int capacity,
|
||||
int limit, int position, int mark,
|
||||
boolean readOnly, ByteOrder endian)
|
||||
{
|
||||
super (capacity, limit, position, mark);
|
||||
this.bb = bb;
|
||||
this.offset = offset;
|
||||
this.readOnly = readOnly;
|
||||
this.endian = endian;
|
||||
if (bb.isDirect())
|
||||
this.address = VMDirectByteBuffer.adjustAddress(bb.address, offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the <code>char</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are no remaining
|
||||
* <code>char</code>s in this buffer.
|
||||
*/
|
||||
public char get ()
|
||||
{
|
||||
int p = position();
|
||||
char result = ByteBufferHelper.getChar(bb, (p << 1) + offset, endian);
|
||||
position(p + 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute get method. Reads the <code>char</code> at position
|
||||
* <code>index</code>.
|
||||
*
|
||||
* @param index Position to read the <code>char</code> from.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
*/
|
||||
public char get (int index)
|
||||
{
|
||||
return ByteBufferHelper.getChar(bb, (index << 1) + offset, endian);
|
||||
}
|
||||
|
||||
public CharBuffer put (char value)
|
||||
{
|
||||
int p = position();
|
||||
ByteBufferHelper.putChar(bb, (p << 1) + offset, value, endian);
|
||||
position(p + 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CharBuffer put (int index, char value)
|
||||
{
|
||||
ByteBufferHelper.putChar(bb, (index << 1) + offset, value, endian);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CharBuffer compact ()
|
||||
{
|
||||
if (position () > 0)
|
||||
{
|
||||
int count = limit () - position ();
|
||||
bb.shiftDown(offset, offset + 2 * position(), 2 * count);
|
||||
position (count);
|
||||
limit (capacity ());
|
||||
}
|
||||
else
|
||||
{
|
||||
position(limit());
|
||||
limit(capacity());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public CharBuffer slice ()
|
||||
{
|
||||
// Create a sliced copy of this object that shares its content.
|
||||
return new CharViewBufferImpl (bb, (position () >> 1) + offset,
|
||||
remaining (), remaining (), 0, -1,
|
||||
isReadOnly (), endian);
|
||||
}
|
||||
|
||||
CharBuffer duplicate (boolean readOnly)
|
||||
{
|
||||
int pos = position();
|
||||
reset();
|
||||
int mark = position();
|
||||
position(pos);
|
||||
return new CharViewBufferImpl (bb, offset, capacity(), limit(),
|
||||
pos, mark, readOnly, endian);
|
||||
}
|
||||
|
||||
public CharBuffer duplicate ()
|
||||
{
|
||||
return duplicate(readOnly);
|
||||
}
|
||||
|
||||
public CharBuffer asReadOnlyBuffer ()
|
||||
{
|
||||
return duplicate(true);
|
||||
}
|
||||
|
||||
public CharSequence subSequence (int start, int end)
|
||||
{
|
||||
if (start < 0
|
||||
|| end < start
|
||||
|| end > length ())
|
||||
throw new IndexOutOfBoundsException ();
|
||||
|
||||
return new CharViewBufferImpl (bb, array_offset, capacity (),
|
||||
position () + end, position () + start,
|
||||
-1, isReadOnly (), endian);
|
||||
}
|
||||
|
||||
public boolean isReadOnly ()
|
||||
{
|
||||
return readOnly;
|
||||
}
|
||||
|
||||
public boolean isDirect ()
|
||||
{
|
||||
return bb.isDirect ();
|
||||
}
|
||||
|
||||
public ByteOrder order ()
|
||||
{
|
||||
return endian;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,419 @@
|
||||
/* DirectByteBufferImpl.java --
|
||||
Copyright (C) 2003, 2004 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;
|
||||
|
||||
import gnu.classpath.RawData;
|
||||
|
||||
abstract class DirectByteBufferImpl extends ByteBuffer
|
||||
{
|
||||
/**
|
||||
* The owner is used to keep alive the object that actually owns the
|
||||
* memory. There are three possibilities:
|
||||
* 1) owner == this: We allocated the memory and we should free it,
|
||||
* but *only* in finalize (if we've been sliced
|
||||
* other objects will also have access to the
|
||||
* memory).
|
||||
* 2) owner == null: The byte buffer was created thru
|
||||
* JNI.NewDirectByteBuffer. The JNI code is
|
||||
* responsible for freeing the memory.
|
||||
* 3) owner == some other object: The other object allocated the
|
||||
* memory and should free it.
|
||||
*/
|
||||
private final Object owner;
|
||||
|
||||
static final class ReadOnly extends DirectByteBufferImpl
|
||||
{
|
||||
ReadOnly(Object owner, RawData address,
|
||||
int capacity, int limit,
|
||||
int position)
|
||||
{
|
||||
super(owner, address, capacity, limit, position);
|
||||
}
|
||||
|
||||
public ByteBuffer put(byte value)
|
||||
{
|
||||
throw new ReadOnlyBufferException ();
|
||||
}
|
||||
|
||||
public ByteBuffer put(int index, byte value)
|
||||
{
|
||||
throw new ReadOnlyBufferException ();
|
||||
}
|
||||
|
||||
public boolean isReadOnly()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
static final class ReadWrite extends DirectByteBufferImpl
|
||||
{
|
||||
ReadWrite(int capacity)
|
||||
{
|
||||
super(capacity);
|
||||
}
|
||||
|
||||
ReadWrite(Object owner, RawData address,
|
||||
int capacity, int limit,
|
||||
int position)
|
||||
{
|
||||
super(owner, address, capacity, limit, position);
|
||||
}
|
||||
|
||||
public boolean isReadOnly()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
DirectByteBufferImpl(int capacity)
|
||||
{
|
||||
super(capacity, capacity, 0, -1);
|
||||
this.owner = this;
|
||||
this.address = VMDirectByteBuffer.allocate(capacity);
|
||||
}
|
||||
|
||||
DirectByteBufferImpl(Object owner, RawData address,
|
||||
int capacity, int limit,
|
||||
int position)
|
||||
{
|
||||
super(capacity, limit, position, -1);
|
||||
this.owner = owner;
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a new direct byte buffer.
|
||||
*/
|
||||
public static ByteBuffer allocate(int capacity)
|
||||
{
|
||||
return new DirectByteBufferImpl.ReadWrite(capacity);
|
||||
}
|
||||
|
||||
protected void finalize() throws Throwable
|
||||
{
|
||||
if (owner == this)
|
||||
VMDirectByteBuffer.free(address);
|
||||
}
|
||||
|
||||
public byte get()
|
||||
{
|
||||
checkForUnderflow();
|
||||
|
||||
int pos = position();
|
||||
byte result = VMDirectByteBuffer.get(address, pos);
|
||||
position(pos + 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
public byte get(int index)
|
||||
{
|
||||
checkIndex(index);
|
||||
|
||||
return VMDirectByteBuffer.get(address, index);
|
||||
}
|
||||
|
||||
public ByteBuffer get(byte[] dst, int offset, int length)
|
||||
{
|
||||
checkArraySize(dst.length, offset, length);
|
||||
checkForUnderflow(length);
|
||||
|
||||
int index = position();
|
||||
VMDirectByteBuffer.get(address, index, dst, offset, length);
|
||||
position(index+length);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ByteBuffer put(byte value)
|
||||
{
|
||||
checkForOverflow();
|
||||
|
||||
int pos = position();
|
||||
VMDirectByteBuffer.put(address, pos, value);
|
||||
position(pos + 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ByteBuffer put(int index, byte value)
|
||||
{
|
||||
checkIndex(index);
|
||||
|
||||
VMDirectByteBuffer.put(address, index, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
void shiftDown(int dst_offset, int src_offset, int count)
|
||||
{
|
||||
VMDirectByteBuffer.shiftDown(address, dst_offset, src_offset, count);
|
||||
}
|
||||
|
||||
public ByteBuffer compact()
|
||||
{
|
||||
checkIfReadOnly();
|
||||
mark = -1;
|
||||
int pos = position();
|
||||
if (pos > 0)
|
||||
{
|
||||
int count = remaining();
|
||||
VMDirectByteBuffer.shiftDown(address, 0, pos, count);
|
||||
position(count);
|
||||
limit(capacity());
|
||||
}
|
||||
else
|
||||
{
|
||||
position(limit());
|
||||
limit(capacity());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ByteBuffer slice()
|
||||
{
|
||||
int rem = remaining();
|
||||
if (isReadOnly())
|
||||
return new DirectByteBufferImpl.ReadOnly
|
||||
(owner, VMDirectByteBuffer.adjustAddress(address, position()),
|
||||
rem, rem, 0);
|
||||
else
|
||||
return new DirectByteBufferImpl.ReadWrite
|
||||
(owner, VMDirectByteBuffer.adjustAddress(address, position()),
|
||||
rem, rem, 0);
|
||||
}
|
||||
|
||||
private ByteBuffer duplicate(boolean readOnly)
|
||||
{
|
||||
int pos = position();
|
||||
reset();
|
||||
int mark = position();
|
||||
position(pos);
|
||||
DirectByteBufferImpl result;
|
||||
if (readOnly)
|
||||
result = new DirectByteBufferImpl.ReadOnly(owner, address, capacity(),
|
||||
limit(), pos);
|
||||
else
|
||||
result = new DirectByteBufferImpl.ReadWrite(owner, address, capacity(),
|
||||
limit(), pos);
|
||||
|
||||
if (mark != pos)
|
||||
{
|
||||
result.position(mark);
|
||||
result.mark();
|
||||
result.position(pos);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public ByteBuffer duplicate()
|
||||
{
|
||||
return duplicate(isReadOnly());
|
||||
}
|
||||
|
||||
public ByteBuffer asReadOnlyBuffer()
|
||||
{
|
||||
return duplicate(true);
|
||||
}
|
||||
|
||||
public boolean isDirect()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public CharBuffer asCharBuffer()
|
||||
{
|
||||
return new CharViewBufferImpl(this, remaining() >> 1);
|
||||
}
|
||||
|
||||
public ShortBuffer asShortBuffer()
|
||||
{
|
||||
return new ShortViewBufferImpl(this, remaining() >> 1);
|
||||
}
|
||||
|
||||
public IntBuffer asIntBuffer()
|
||||
{
|
||||
return new IntViewBufferImpl(this, remaining() >> 2);
|
||||
}
|
||||
|
||||
public LongBuffer asLongBuffer()
|
||||
{
|
||||
return new LongViewBufferImpl(this, remaining() >> 3);
|
||||
}
|
||||
|
||||
public FloatBuffer asFloatBuffer()
|
||||
{
|
||||
return new FloatViewBufferImpl(this, remaining() >> 2);
|
||||
}
|
||||
|
||||
public DoubleBuffer asDoubleBuffer()
|
||||
{
|
||||
return new DoubleViewBufferImpl(this, remaining() >> 3);
|
||||
}
|
||||
|
||||
public char getChar()
|
||||
{
|
||||
return ByteBufferHelper.getChar(this, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putChar(char value)
|
||||
{
|
||||
ByteBufferHelper.putChar(this, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public char getChar(int index)
|
||||
{
|
||||
return ByteBufferHelper.getChar(this, index, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putChar(int index, char value)
|
||||
{
|
||||
ByteBufferHelper.putChar(this, index, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public short getShort()
|
||||
{
|
||||
return ByteBufferHelper.getShort(this, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putShort(short value)
|
||||
{
|
||||
ByteBufferHelper.putShort(this, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public short getShort(int index)
|
||||
{
|
||||
return ByteBufferHelper.getShort(this, index, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putShort(int index, short value)
|
||||
{
|
||||
ByteBufferHelper.putShort(this, index, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getInt()
|
||||
{
|
||||
return ByteBufferHelper.getInt(this, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putInt(int value)
|
||||
{
|
||||
ByteBufferHelper.putInt(this, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getInt(int index)
|
||||
{
|
||||
return ByteBufferHelper.getInt(this, index, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putInt(int index, int value)
|
||||
{
|
||||
ByteBufferHelper.putInt(this, index, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public long getLong()
|
||||
{
|
||||
return ByteBufferHelper.getLong(this, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putLong(long value)
|
||||
{
|
||||
ByteBufferHelper.putLong(this, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public long getLong(int index)
|
||||
{
|
||||
return ByteBufferHelper.getLong(this, index, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putLong(int index, long value)
|
||||
{
|
||||
ByteBufferHelper.putLong(this, index, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public float getFloat()
|
||||
{
|
||||
return ByteBufferHelper.getFloat(this, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putFloat(float value)
|
||||
{
|
||||
ByteBufferHelper.putFloat(this, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public float getFloat(int index)
|
||||
{
|
||||
return ByteBufferHelper.getFloat(this, index, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putFloat(int index, float value)
|
||||
{
|
||||
ByteBufferHelper.putFloat(this, index, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public double getDouble()
|
||||
{
|
||||
return ByteBufferHelper.getDouble(this, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putDouble(double value)
|
||||
{
|
||||
ByteBufferHelper.putDouble(this, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public double getDouble(int index)
|
||||
{
|
||||
return ByteBufferHelper.getDouble(this, index, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putDouble(int index, double value)
|
||||
{
|
||||
ByteBufferHelper.putDouble(this, index, value, order());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,383 @@
|
||||
/* DoubleBuffer.java --
|
||||
Copyright (C) 2002, 2003, 2004 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;
|
||||
|
||||
/**
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class DoubleBuffer extends Buffer
|
||||
implements Comparable
|
||||
{
|
||||
int array_offset;
|
||||
double[] backing_buffer;
|
||||
|
||||
DoubleBuffer (int capacity, int limit, int position, int mark)
|
||||
{
|
||||
super (capacity, limit, position, mark);
|
||||
array_offset = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a new <code>DoubleBuffer</code> object with a given capacity.
|
||||
*/
|
||||
public static DoubleBuffer allocate (int capacity)
|
||||
{
|
||||
return new DoubleBufferImpl (capacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a <code>double</code> array into a <code>DoubleBuffer</code>
|
||||
* object.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold
|
||||
*/
|
||||
public static final DoubleBuffer wrap (double[] array, int offset, int length)
|
||||
{
|
||||
return new DoubleBufferImpl (array, 0, array.length, offset + length, offset, -1, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a <code>double</code> array into a <code>DoubleBuffer</code>
|
||||
* object.
|
||||
*/
|
||||
public static final DoubleBuffer wrap (double[] array)
|
||||
{
|
||||
return wrap (array, 0, array.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method transfers <code>double</code>s from this buffer into the given
|
||||
* destination array. Before the transfer, it checks if there are fewer than
|
||||
* length <code>double</code>s remaining in this buffer.
|
||||
*
|
||||
* @param dst The destination array
|
||||
* @param offset The offset within the array of the first <code>double</code>
|
||||
* to be written; must be non-negative and no larger than dst.length.
|
||||
* @param length The maximum number of bytes to be written to the given array;
|
||||
* must be non-negative and no larger than dst.length - offset.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are fewer than length
|
||||
* <code>double</code>s remaining in this buffer.
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold.
|
||||
*/
|
||||
public DoubleBuffer get (double[] dst, int offset, int length)
|
||||
{
|
||||
checkArraySize(dst.length, offset, length);
|
||||
checkForUnderflow(length);
|
||||
|
||||
for (int i = offset; i < offset + length; i++)
|
||||
{
|
||||
dst [i] = get ();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method transfers <code>double</code>s from this buffer into the given
|
||||
* destination array.
|
||||
*
|
||||
* @param dst The byte array to write into.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are fewer than dst.length
|
||||
* <code>double</code>s remaining in this buffer.
|
||||
*/
|
||||
public DoubleBuffer get (double[] dst)
|
||||
{
|
||||
return get (dst, 0, dst.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the the <code>DoubleBUFFER</code> src
|
||||
* into the buffer. Before the transfer, it checks if there is fewer than
|
||||
* <code>src.remaining()</code> space remaining in this buffer.
|
||||
*
|
||||
* @param src The source data.
|
||||
*
|
||||
* @exception BufferOverflowException If there is insufficient space in this
|
||||
* buffer for the remaining <code>double</code>s in the source buffer.
|
||||
* @exception IllegalArgumentException If the source buffer is this buffer.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public DoubleBuffer put (DoubleBuffer src)
|
||||
{
|
||||
if (src == this)
|
||||
throw new IllegalArgumentException ();
|
||||
|
||||
checkForOverflow(src.remaining ());
|
||||
|
||||
if (src.remaining () > 0)
|
||||
{
|
||||
double[] toPut = new double [src.remaining ()];
|
||||
src.get (toPut);
|
||||
put (toPut);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the the <code>double array</code> src
|
||||
* into the buffer. Before the transfer, it checks if there is fewer than
|
||||
* length space remaining in this buffer.
|
||||
*
|
||||
* @param src The array to copy into the buffer.
|
||||
* @param offset The offset within the array of the first byte to be read;
|
||||
* must be non-negative and no larger than src.length.
|
||||
* @param length The number of bytes to be read from the given array;
|
||||
* must be non-negative and no larger than src.length - offset.
|
||||
*
|
||||
* @exception BufferOverflowException If there is insufficient space in this
|
||||
* buffer for the remaining <code>double</code>s in the source array.
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public DoubleBuffer put (double[] src, int offset, int length)
|
||||
{
|
||||
checkArraySize(src.length, offset, length);
|
||||
checkForOverflow(length);
|
||||
|
||||
for (int i = offset; i < offset + length; i++)
|
||||
put (src [i]);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the the <code>double array</code> src
|
||||
* into the buffer.
|
||||
*
|
||||
* @param src The array to copy into the buffer.
|
||||
*
|
||||
* @exception BufferOverflowException If there is insufficient space in this
|
||||
* buffer for the remaining <code>double</code>s in the source array.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public final DoubleBuffer put (double[] src)
|
||||
{
|
||||
return put (src, 0, src.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether ot not this buffer is backed by an accessible
|
||||
* <code>double</code> array.
|
||||
*/
|
||||
public final boolean hasArray ()
|
||||
{
|
||||
return (backing_buffer != null
|
||||
&& !isReadOnly ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <code>double</code> array that backs this buffer.
|
||||
*
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
* @exception UnsupportedOperationException If this buffer is not backed
|
||||
* by an accessible array.
|
||||
*/
|
||||
public final double[] array ()
|
||||
{
|
||||
if (backing_buffer == null)
|
||||
throw new UnsupportedOperationException ();
|
||||
|
||||
checkIfReadOnly();
|
||||
|
||||
return backing_buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the offset within this buffer's backing array of the first element.
|
||||
*
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
* @exception UnsupportedOperationException If this buffer is not backed
|
||||
* by an accessible array.
|
||||
*/
|
||||
public final int arrayOffset ()
|
||||
{
|
||||
if (backing_buffer == null)
|
||||
throw new UnsupportedOperationException ();
|
||||
|
||||
checkIfReadOnly();
|
||||
|
||||
return array_offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates a hash code for this buffer.
|
||||
*
|
||||
* This is done with <code>long</code> arithmetic,
|
||||
* where ** represents exponentiation, by this formula:<br>
|
||||
* <code>s[position()] + 31 + (s[position()+1] + 30)*31**1 + ... +
|
||||
* (s[limit()-1]+30)*31**(limit()-1)</code>.
|
||||
* Where s is the buffer data, in Double.doubleToLongBits() form
|
||||
* Note that the hashcode is dependent on buffer content,
|
||||
* and therefore is not useful if the buffer content may change.
|
||||
*
|
||||
* @return the hash code (casted to int)
|
||||
*/
|
||||
public int hashCode ()
|
||||
{
|
||||
long hashCode = Double.doubleToLongBits(get(position())) + 31;
|
||||
long multiplier = 1;
|
||||
for (int i = position() + 1; i < limit(); ++i)
|
||||
{
|
||||
multiplier *= 31;
|
||||
hashCode += (Double.doubleToLongBits(get(i)) + 30)*multiplier;
|
||||
}
|
||||
return ((int)hashCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this buffer is equal to obj.
|
||||
*/
|
||||
public boolean equals (Object obj)
|
||||
{
|
||||
if (obj instanceof DoubleBuffer)
|
||||
{
|
||||
return compareTo (obj) == 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two <code>DoubleBuffer</code> objects.
|
||||
*
|
||||
* @exception ClassCastException If obj is not an object derived from
|
||||
* <code>DoubleBuffer</code>.
|
||||
*/
|
||||
public int compareTo (Object obj)
|
||||
{
|
||||
DoubleBuffer other = (DoubleBuffer) obj;
|
||||
|
||||
int num = Math.min(remaining(), other.remaining());
|
||||
int pos_this = position();
|
||||
int pos_other = other.position();
|
||||
|
||||
for (int count = 0; count < num; count++)
|
||||
{
|
||||
double a = get(pos_this++);
|
||||
double b = other.get(pos_other++);
|
||||
|
||||
if (a == b)
|
||||
continue;
|
||||
|
||||
if (a < b)
|
||||
return -1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return remaining() - other.remaining();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the byte order of this buffer.
|
||||
*/
|
||||
public abstract ByteOrder order ();
|
||||
|
||||
/**
|
||||
* Reads the <code>double</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are no remaining
|
||||
* <code>double</code>s in this buffer.
|
||||
*/
|
||||
public abstract double get ();
|
||||
|
||||
/**
|
||||
* Writes the <code>double</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferOverflowException If there no remaining
|
||||
* <code>double</code>s in this buffer.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public abstract DoubleBuffer put (double b);
|
||||
|
||||
/**
|
||||
* Absolute get method.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
*/
|
||||
public abstract double get (int index);
|
||||
|
||||
/**
|
||||
* Absolute put method.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public abstract DoubleBuffer put (int index, double b);
|
||||
|
||||
/**
|
||||
* Compacts this buffer.
|
||||
*
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public abstract DoubleBuffer compact ();
|
||||
|
||||
/**
|
||||
* Tells wether or not this buffer is direct.
|
||||
*/
|
||||
public abstract boolean isDirect ();
|
||||
|
||||
/**
|
||||
* Creates a new <code>DoubleBuffer</code> whose content is a shared
|
||||
* subsequence of this buffer's content.
|
||||
*/
|
||||
public abstract DoubleBuffer slice ();
|
||||
|
||||
/**
|
||||
* Creates a new <code>DoubleBuffer</code> that shares this buffer's
|
||||
* content.
|
||||
*/
|
||||
public abstract DoubleBuffer duplicate ();
|
||||
|
||||
/**
|
||||
* Creates a new read-only <code>DoubleBuffer</code> that shares this
|
||||
* buffer's content.
|
||||
*/
|
||||
public abstract DoubleBuffer asReadOnlyBuffer ();
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
/* DoubleBufferImpl.java --
|
||||
Copyright (C) 2002, 2003, 2004, 2005 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;
|
||||
|
||||
/**
|
||||
* This is a Heap memory implementation
|
||||
*/
|
||||
final class DoubleBufferImpl extends DoubleBuffer
|
||||
{
|
||||
private boolean readOnly;
|
||||
|
||||
DoubleBufferImpl (int capacity)
|
||||
{
|
||||
this (new double [capacity], 0, capacity, capacity, 0, -1, false);
|
||||
}
|
||||
|
||||
DoubleBufferImpl (double[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly)
|
||||
{
|
||||
super (capacity, limit, position, mark);
|
||||
this.backing_buffer = buffer;
|
||||
this.array_offset = offset;
|
||||
this.readOnly = readOnly;
|
||||
}
|
||||
|
||||
public boolean isReadOnly ()
|
||||
{
|
||||
return readOnly;
|
||||
}
|
||||
|
||||
public DoubleBuffer slice ()
|
||||
{
|
||||
return new DoubleBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ());
|
||||
}
|
||||
|
||||
public DoubleBuffer duplicate ()
|
||||
{
|
||||
return new DoubleBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ());
|
||||
}
|
||||
|
||||
public DoubleBuffer asReadOnlyBuffer ()
|
||||
{
|
||||
return new DoubleBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true);
|
||||
}
|
||||
|
||||
public DoubleBuffer compact ()
|
||||
{
|
||||
checkIfReadOnly();
|
||||
mark = -1;
|
||||
int copied = 0;
|
||||
|
||||
while (remaining () > 0)
|
||||
{
|
||||
put (copied, get ());
|
||||
copied++;
|
||||
}
|
||||
|
||||
position (copied);
|
||||
limit(capacity());
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isDirect ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the <code>double</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are no remaining
|
||||
* <code>double</code>s in this buffer.
|
||||
*/
|
||||
public double get ()
|
||||
{
|
||||
checkForUnderflow();
|
||||
|
||||
double result = backing_buffer [position ()];
|
||||
position (position () + 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Relative put method. Writes <code>value</code> to the next position
|
||||
* in the buffer.
|
||||
*
|
||||
* @exception BufferOverflowException If there no remaining
|
||||
* space in this buffer.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public DoubleBuffer put (double value)
|
||||
{
|
||||
checkIfReadOnly();
|
||||
checkForOverflow();
|
||||
|
||||
backing_buffer [position ()] = value;
|
||||
position (position () + 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute get method. Reads the <code>double</code> at position
|
||||
* <code>index</code>.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
*/
|
||||
public double get (int index)
|
||||
{
|
||||
checkIndex(index);
|
||||
|
||||
return backing_buffer [index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute put method. Writes <code>value</code> to position
|
||||
* <code>index</code> in the buffer.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public DoubleBuffer put (int index, double value)
|
||||
{
|
||||
checkIfReadOnly();
|
||||
checkIndex(index);
|
||||
|
||||
backing_buffer [index] = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ByteOrder order ()
|
||||
{
|
||||
return ByteOrder.nativeOrder ();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
/* DoubleViewBufferImpl.java --
|
||||
Copyright (C) 2003, 2004 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;
|
||||
|
||||
final class DoubleViewBufferImpl extends DoubleBuffer
|
||||
{
|
||||
/** Position in bb (i.e. a byte offset) where this buffer starts. */
|
||||
private int offset;
|
||||
private ByteBuffer bb;
|
||||
private boolean readOnly;
|
||||
private ByteOrder endian;
|
||||
|
||||
DoubleViewBufferImpl (ByteBuffer bb, int capacity)
|
||||
{
|
||||
super (capacity, capacity, 0, -1);
|
||||
this.bb = bb;
|
||||
this.offset = bb.position();
|
||||
this.readOnly = bb.isReadOnly();
|
||||
this.endian = bb.order();
|
||||
if (bb.isDirect())
|
||||
this.address = VMDirectByteBuffer.adjustAddress(bb.address, offset);
|
||||
}
|
||||
|
||||
public DoubleViewBufferImpl (ByteBuffer bb, int offset, int capacity,
|
||||
int limit, int position, int mark,
|
||||
boolean readOnly, ByteOrder endian)
|
||||
{
|
||||
super (capacity, limit, position, mark);
|
||||
this.bb = bb;
|
||||
this.offset = offset;
|
||||
this.readOnly = readOnly;
|
||||
this.endian = endian;
|
||||
if (bb.isDirect())
|
||||
this.address = VMDirectByteBuffer.adjustAddress(bb.address, offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the <code>double</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are no remaining
|
||||
* <code>double</code>s in this buffer.
|
||||
*/
|
||||
public double get ()
|
||||
{
|
||||
int p = position();
|
||||
double result = ByteBufferHelper.getDouble(bb, (p << 3) + offset, endian);
|
||||
position(p + 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute get method. Reads the <code>double</code> at position
|
||||
* <code>index</code>.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
*/
|
||||
public double get (int index)
|
||||
{
|
||||
return ByteBufferHelper.getDouble(bb, (index << 3) + offset, endian);
|
||||
}
|
||||
|
||||
public DoubleBuffer put (double value)
|
||||
{
|
||||
int p = position();
|
||||
ByteBufferHelper.putDouble(bb, (p << 3) + offset, value, endian);
|
||||
position(p + 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DoubleBuffer put (int index, double value)
|
||||
{
|
||||
ByteBufferHelper.putDouble(bb, (index << 3) + offset, value, endian);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DoubleBuffer compact ()
|
||||
{
|
||||
if (position () > 0)
|
||||
{
|
||||
int count = limit () - position ();
|
||||
bb.shiftDown(offset, offset + 8 * position(), 8 * count);
|
||||
position (count);
|
||||
limit (capacity ());
|
||||
}
|
||||
else
|
||||
{
|
||||
position(limit());
|
||||
limit(capacity());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public DoubleBuffer slice ()
|
||||
{
|
||||
return new DoubleViewBufferImpl (bb, (position () >> 3) + offset,
|
||||
remaining(), remaining(), 0, -1,
|
||||
readOnly, endian);
|
||||
}
|
||||
|
||||
DoubleBuffer duplicate (boolean readOnly)
|
||||
{
|
||||
int pos = position();
|
||||
reset();
|
||||
int mark = position();
|
||||
position(pos);
|
||||
return new DoubleViewBufferImpl (bb, offset, capacity(), limit(),
|
||||
pos, mark, readOnly, endian);
|
||||
}
|
||||
|
||||
public DoubleBuffer duplicate ()
|
||||
{
|
||||
return duplicate(readOnly);
|
||||
}
|
||||
|
||||
public DoubleBuffer asReadOnlyBuffer ()
|
||||
{
|
||||
return duplicate(true);
|
||||
}
|
||||
|
||||
public boolean isReadOnly ()
|
||||
{
|
||||
return readOnly;
|
||||
}
|
||||
|
||||
public boolean isDirect ()
|
||||
{
|
||||
return bb.isDirect ();
|
||||
}
|
||||
|
||||
public ByteOrder order ()
|
||||
{
|
||||
return endian;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,383 @@
|
||||
/* FloatBuffer.java --
|
||||
Copyright (C) 2002, 2003, 2004 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;
|
||||
|
||||
/**
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class FloatBuffer extends Buffer
|
||||
implements Comparable
|
||||
{
|
||||
int array_offset;
|
||||
float[] backing_buffer;
|
||||
|
||||
FloatBuffer (int capacity, int limit, int position, int mark)
|
||||
{
|
||||
super (capacity, limit, position, mark);
|
||||
array_offset = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a new <code>FloatBuffer</code> object with a given capacity.
|
||||
*/
|
||||
public static FloatBuffer allocate (int capacity)
|
||||
{
|
||||
return new FloatBufferImpl (capacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a <code>float</code> array into a <code>FloatBuffer</code>
|
||||
* object.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold
|
||||
*/
|
||||
public static final FloatBuffer wrap (float[] array, int offset, int length)
|
||||
{
|
||||
return new FloatBufferImpl (array, 0, array.length, offset + length, offset, -1, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a <code>float</code> array into a <code>FloatBuffer</code>
|
||||
* object.
|
||||
*/
|
||||
public static final FloatBuffer wrap (float[] array)
|
||||
{
|
||||
return wrap (array, 0, array.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method transfers <code>float</code>s from this buffer into the given
|
||||
* destination array. Before the transfer, it checks if there are fewer than
|
||||
* length <code>float</code>s remaining in this buffer.
|
||||
*
|
||||
* @param dst The destination array
|
||||
* @param offset The offset within the array of the first <code>float</code>
|
||||
* to be written; must be non-negative and no larger than dst.length.
|
||||
* @param length The maximum number of bytes to be written to the given array;
|
||||
* must be non-negative and no larger than dst.length - offset.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are fewer than length
|
||||
* <code>float</code>s remaining in this buffer.
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold.
|
||||
*/
|
||||
public FloatBuffer get (float[] dst, int offset, int length)
|
||||
{
|
||||
checkArraySize(dst.length, offset, length);
|
||||
checkForUnderflow(length);
|
||||
|
||||
for (int i = offset; i < offset + length; i++)
|
||||
{
|
||||
dst [i] = get ();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method transfers <code>float</code>s from this buffer into the given
|
||||
* destination array.
|
||||
*
|
||||
* @param dst The byte array to write into.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are fewer than dst.length
|
||||
* <code>float</code>s remaining in this buffer.
|
||||
*/
|
||||
public FloatBuffer get (float[] dst)
|
||||
{
|
||||
return get (dst, 0, dst.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the the <code>FloatBUFFER</code> src
|
||||
* into the buffer. Before the transfer, it checks if there is fewer than
|
||||
* <code>src.remaining()</code> space remaining in this buffer.
|
||||
*
|
||||
* @param src The source data.
|
||||
*
|
||||
* @exception BufferOverflowException If there is insufficient space in this
|
||||
* buffer for the remaining <code>float</code>s in the source buffer.
|
||||
* @exception IllegalArgumentException If the source buffer is this buffer.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public FloatBuffer put (FloatBuffer src)
|
||||
{
|
||||
if (src == this)
|
||||
throw new IllegalArgumentException ();
|
||||
|
||||
checkForOverflow(src.remaining());
|
||||
|
||||
if (src.remaining () > 0)
|
||||
{
|
||||
float[] toPut = new float [src.remaining ()];
|
||||
src.get (toPut);
|
||||
put (toPut);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the the <code>float array</code> src
|
||||
* into the buffer. Before the transfer, it checks if there is fewer than
|
||||
* length space remaining in this buffer.
|
||||
*
|
||||
* @param src The array to copy into the buffer.
|
||||
* @param offset The offset within the array of the first byte to be read;
|
||||
* must be non-negative and no larger than src.length.
|
||||
* @param length The number of bytes to be read from the given array;
|
||||
* must be non-negative and no larger than src.length - offset.
|
||||
*
|
||||
* @exception BufferOverflowException If there is insufficient space in this
|
||||
* buffer for the remaining <code>float</code>s in the source array.
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public FloatBuffer put (float[] src, int offset, int length)
|
||||
{
|
||||
checkArraySize(src.length, offset, length);
|
||||
checkForOverflow(length);
|
||||
|
||||
for (int i = offset; i < offset + length; i++)
|
||||
put (src [i]);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the the <code>float array</code> src
|
||||
* into the buffer.
|
||||
*
|
||||
* @param src The array to copy into the buffer.
|
||||
*
|
||||
* @exception BufferOverflowException If there is insufficient space in this
|
||||
* buffer for the remaining <code>float</code>s in the source array.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public final FloatBuffer put (float[] src)
|
||||
{
|
||||
return put (src, 0, src.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether ot not this buffer is backed by an accessible
|
||||
* <code>float</code> array.
|
||||
*/
|
||||
public final boolean hasArray ()
|
||||
{
|
||||
return (backing_buffer != null
|
||||
&& !isReadOnly ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <code>float</code> array that backs this buffer.
|
||||
*
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
* @exception UnsupportedOperationException If this buffer is not backed
|
||||
* by an accessible array.
|
||||
*/
|
||||
public final float[] array ()
|
||||
{
|
||||
if (backing_buffer == null)
|
||||
throw new UnsupportedOperationException ();
|
||||
|
||||
checkIfReadOnly();
|
||||
|
||||
return backing_buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the offset within this buffer's backing array of the first element.
|
||||
*
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
* @exception UnsupportedOperationException If this buffer is not backed
|
||||
* by an accessible array.
|
||||
*/
|
||||
public final int arrayOffset ()
|
||||
{
|
||||
if (backing_buffer == null)
|
||||
throw new UnsupportedOperationException ();
|
||||
|
||||
checkIfReadOnly();
|
||||
|
||||
return array_offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates a hash code for this buffer.
|
||||
*
|
||||
* This is done with <code>int</code> arithmetic,
|
||||
* where ** represents exponentiation, by this formula:<br>
|
||||
* <code>s[position()] + 31 + (s[position()+1] + 30)*31**1 + ... +
|
||||
* (s[limit()-1]+30)*31**(limit()-1)</code>.
|
||||
* Where s is the buffer data, in Float.floatToIntBits() form
|
||||
* Note that the hashcode is dependent on buffer content,
|
||||
* and therefore is not useful if the buffer content may change.
|
||||
*
|
||||
* @return the hash code
|
||||
*/
|
||||
public int hashCode ()
|
||||
{
|
||||
int hashCode = Float.floatToIntBits(get(position())) + 31;
|
||||
int multiplier = 1;
|
||||
for (int i = position() + 1; i < limit(); ++i)
|
||||
{
|
||||
multiplier *= 31;
|
||||
hashCode += (Float.floatToIntBits(get(i)) + 30)*multiplier;
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this buffer is equal to obj.
|
||||
*/
|
||||
public boolean equals (Object obj)
|
||||
{
|
||||
if (obj instanceof FloatBuffer)
|
||||
{
|
||||
return compareTo (obj) == 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two <code>FloatBuffer</code> objects.
|
||||
*
|
||||
* @exception ClassCastException If obj is not an object derived from
|
||||
* <code>FloatBuffer</code>.
|
||||
*/
|
||||
public int compareTo (Object obj)
|
||||
{
|
||||
FloatBuffer other = (FloatBuffer) obj;
|
||||
|
||||
int num = Math.min(remaining(), other.remaining());
|
||||
int pos_this = position();
|
||||
int pos_other = other.position();
|
||||
|
||||
for (int count = 0; count < num; count++)
|
||||
{
|
||||
float a = get(pos_this++);
|
||||
float b = other.get(pos_other++);
|
||||
|
||||
if (a == b)
|
||||
continue;
|
||||
|
||||
if (a < b)
|
||||
return -1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return remaining() - other.remaining();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the byte order of this buffer.
|
||||
*/
|
||||
public abstract ByteOrder order ();
|
||||
|
||||
/**
|
||||
* Reads the <code>float</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are no remaining
|
||||
* <code>float</code>s in this buffer.
|
||||
*/
|
||||
public abstract float get ();
|
||||
|
||||
/**
|
||||
* Writes the <code>float</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferOverflowException If there no remaining
|
||||
* <code>float</code>s in this buffer.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public abstract FloatBuffer put (float b);
|
||||
|
||||
/**
|
||||
* Absolute get method.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
*/
|
||||
public abstract float get (int index);
|
||||
|
||||
/**
|
||||
* Absolute put method.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public abstract FloatBuffer put (int index, float b);
|
||||
|
||||
/**
|
||||
* Compacts this buffer.
|
||||
*
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public abstract FloatBuffer compact ();
|
||||
|
||||
/**
|
||||
* Tells wether or not this buffer is direct.
|
||||
*/
|
||||
public abstract boolean isDirect ();
|
||||
|
||||
/**
|
||||
* Creates a new <code>FloatBuffer</code> whose content is a shared
|
||||
* subsequence of this buffer's content.
|
||||
*/
|
||||
public abstract FloatBuffer slice ();
|
||||
|
||||
/**
|
||||
* Creates a new <code>FloatBuffer</code> that shares this buffer's
|
||||
* content.
|
||||
*/
|
||||
public abstract FloatBuffer duplicate ();
|
||||
|
||||
/**
|
||||
* Creates a new read-only <code>FloatBuffer</code> that shares this
|
||||
* buffer's content.
|
||||
*/
|
||||
public abstract FloatBuffer asReadOnlyBuffer ();
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
/* FloatBufferImpl.java --
|
||||
Copyright (C) 2002, 2003, 2004, 2005 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;
|
||||
|
||||
/**
|
||||
* This is a Heap memory implementation
|
||||
*/
|
||||
final class FloatBufferImpl extends FloatBuffer
|
||||
{
|
||||
private boolean readOnly;
|
||||
|
||||
FloatBufferImpl (int capacity)
|
||||
{
|
||||
this (new float [capacity], 0, capacity, capacity, 0, -1, false);
|
||||
}
|
||||
|
||||
FloatBufferImpl (float[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly)
|
||||
{
|
||||
super (capacity, limit, position, mark);
|
||||
this.backing_buffer = buffer;
|
||||
this.array_offset = offset;
|
||||
this.readOnly = readOnly;
|
||||
}
|
||||
|
||||
public boolean isReadOnly ()
|
||||
{
|
||||
return readOnly;
|
||||
}
|
||||
|
||||
public FloatBuffer slice ()
|
||||
{
|
||||
return new FloatBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ());
|
||||
}
|
||||
|
||||
public FloatBuffer duplicate ()
|
||||
{
|
||||
return new FloatBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ());
|
||||
}
|
||||
|
||||
public FloatBuffer asReadOnlyBuffer ()
|
||||
{
|
||||
return new FloatBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true);
|
||||
}
|
||||
|
||||
public FloatBuffer compact ()
|
||||
{
|
||||
checkIfReadOnly();
|
||||
mark = -1;
|
||||
int copied = 0;
|
||||
|
||||
while (remaining () > 0)
|
||||
{
|
||||
put (copied, get ());
|
||||
copied++;
|
||||
}
|
||||
|
||||
position (copied);
|
||||
limit(capacity());
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isDirect ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the <code>float</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are no remaining
|
||||
* <code>floats</code> in this buffer.
|
||||
*/
|
||||
public float get ()
|
||||
{
|
||||
checkForUnderflow();
|
||||
|
||||
float result = backing_buffer [position ()];
|
||||
position (position () + 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Relative put method. Writes <code>value</code> to the next position
|
||||
* in the buffer.
|
||||
*
|
||||
* @exception BufferOverflowException If there no remaining
|
||||
* space in this buffer.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public FloatBuffer put (float value)
|
||||
{
|
||||
checkIfReadOnly();
|
||||
checkForOverflow();
|
||||
|
||||
backing_buffer [position ()] = value;
|
||||
position (position () + 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute get method. Reads the <code>float</code> at position
|
||||
* <code>index</code>.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
*/
|
||||
public float get (int index)
|
||||
{
|
||||
checkIndex(index);
|
||||
|
||||
return backing_buffer [index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute put method. Writes <code>value</code> to position
|
||||
* <code>index</code> in the buffer.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public FloatBuffer put (int index, float value)
|
||||
{
|
||||
checkIfReadOnly();
|
||||
checkIndex(index);
|
||||
|
||||
backing_buffer [index] = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ByteOrder order ()
|
||||
{
|
||||
return ByteOrder.nativeOrder ();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
/* FloatViewBufferImpl.java --
|
||||
Copyright (C) 2003, 2004 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;
|
||||
|
||||
final class FloatViewBufferImpl extends FloatBuffer
|
||||
{
|
||||
/** Position in bb (i.e. a byte offset) where this buffer starts. */
|
||||
private int offset;
|
||||
private ByteBuffer bb;
|
||||
private boolean readOnly;
|
||||
private ByteOrder endian;
|
||||
|
||||
FloatViewBufferImpl (ByteBuffer bb, int capacity)
|
||||
{
|
||||
super (capacity, capacity, 0, -1);
|
||||
this.bb = bb;
|
||||
this.offset = bb.position();
|
||||
this.readOnly = bb.isReadOnly();
|
||||
this.endian = bb.order();
|
||||
if (bb.isDirect())
|
||||
this.address = VMDirectByteBuffer.adjustAddress(bb.address, offset);
|
||||
}
|
||||
|
||||
public FloatViewBufferImpl (ByteBuffer bb, int offset, int capacity,
|
||||
int limit, int position, int mark,
|
||||
boolean readOnly, ByteOrder endian)
|
||||
{
|
||||
super (capacity, limit, position, mark);
|
||||
this.bb = bb;
|
||||
this.offset = offset;
|
||||
this.readOnly = readOnly;
|
||||
this.endian = endian;
|
||||
if (bb.isDirect())
|
||||
this.address = VMDirectByteBuffer.adjustAddress(bb.address, offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the <code>float</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are no remaining
|
||||
* <code>floats</code> in this buffer.
|
||||
*/
|
||||
public float get ()
|
||||
{
|
||||
int p = position();
|
||||
float result = ByteBufferHelper.getFloat(bb, (p << 2) + offset, endian);
|
||||
position(p + 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute get method. Reads the <code>float</code> at position
|
||||
* <code>index</code>.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
*/
|
||||
public float get (int index)
|
||||
{
|
||||
return ByteBufferHelper.getFloat(bb, (index << 2) + offset, endian);
|
||||
}
|
||||
|
||||
public FloatBuffer put (float value)
|
||||
{
|
||||
int p = position();
|
||||
ByteBufferHelper.putFloat(bb, (p << 2) + offset, value, endian);
|
||||
position(p + 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FloatBuffer put (int index, float value)
|
||||
{
|
||||
ByteBufferHelper.putFloat(bb, (index << 2) + offset, value, endian);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FloatBuffer compact ()
|
||||
{
|
||||
if (position () > 0)
|
||||
{
|
||||
int count = limit () - position ();
|
||||
bb.shiftDown(offset, offset + 4 * position(), 4 * count);
|
||||
position (count);
|
||||
limit (capacity ());
|
||||
}
|
||||
else
|
||||
{
|
||||
position(limit());
|
||||
limit(capacity());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public FloatBuffer slice ()
|
||||
{
|
||||
// Create a sliced copy of this object that shares its content.
|
||||
return new FloatViewBufferImpl (bb, (position () >> 2) + offset,
|
||||
remaining(), remaining(), 0, -1,
|
||||
readOnly, endian);
|
||||
}
|
||||
|
||||
FloatBuffer duplicate (boolean readOnly)
|
||||
{
|
||||
int pos = position();
|
||||
reset();
|
||||
int mark = position();
|
||||
position(pos);
|
||||
return new FloatViewBufferImpl (bb, offset, capacity(), limit(),
|
||||
pos, mark, readOnly, endian);
|
||||
}
|
||||
|
||||
public FloatBuffer duplicate ()
|
||||
{
|
||||
return duplicate(readOnly);
|
||||
}
|
||||
|
||||
public FloatBuffer asReadOnlyBuffer ()
|
||||
{
|
||||
return duplicate(true);
|
||||
}
|
||||
|
||||
public boolean isReadOnly ()
|
||||
{
|
||||
return readOnly;
|
||||
}
|
||||
|
||||
public boolean isDirect ()
|
||||
{
|
||||
return bb.isDirect ();
|
||||
}
|
||||
|
||||
public ByteOrder order ()
|
||||
{
|
||||
return endian;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,383 @@
|
||||
/* IntBuffer.java --
|
||||
Copyright (C) 2002, 2003, 2004 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;
|
||||
|
||||
/**
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class IntBuffer extends Buffer
|
||||
implements Comparable
|
||||
{
|
||||
int array_offset;
|
||||
int[] backing_buffer;
|
||||
|
||||
IntBuffer (int capacity, int limit, int position, int mark)
|
||||
{
|
||||
super (capacity, limit, position, mark);
|
||||
array_offset = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a new <code>IntBuffer</code> object with a given capacity.
|
||||
*/
|
||||
public static IntBuffer allocate (int capacity)
|
||||
{
|
||||
return new IntBufferImpl (capacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a <code>int</code> array into a <code>IntBuffer</code>
|
||||
* object.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold
|
||||
*/
|
||||
public static final IntBuffer wrap (int[] array, int offset, int length)
|
||||
{
|
||||
return new IntBufferImpl (array, 0, array.length, offset + length, offset, -1, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a <code>int</code> array into a <code>IntBuffer</code>
|
||||
* object.
|
||||
*/
|
||||
public static final IntBuffer wrap (int[] array)
|
||||
{
|
||||
return wrap (array, 0, array.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method transfers <code>int</code>s from this buffer into the given
|
||||
* destination array. Before the transfer, it checks if there are fewer than
|
||||
* length <code>int</code>s remaining in this buffer.
|
||||
*
|
||||
* @param dst The destination array
|
||||
* @param offset The offset within the array of the first <code>int</code>
|
||||
* to be written; must be non-negative and no larger than dst.length.
|
||||
* @param length The maximum number of bytes to be written to the given array;
|
||||
* must be non-negative and no larger than dst.length - offset.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are fewer than length
|
||||
* <code>int</code>s remaining in this buffer.
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold.
|
||||
*/
|
||||
public IntBuffer get (int[] dst, int offset, int length)
|
||||
{
|
||||
checkArraySize(dst.length, offset, length);
|
||||
checkForUnderflow(length);
|
||||
|
||||
for (int i = offset; i < offset + length; i++)
|
||||
{
|
||||
dst [i] = get ();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method transfers <code>int</code>s from this buffer into the given
|
||||
* destination array.
|
||||
*
|
||||
* @param dst The byte array to write into.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are fewer than dst.length
|
||||
* <code>int</code>s remaining in this buffer.
|
||||
*/
|
||||
public IntBuffer get (int[] dst)
|
||||
{
|
||||
return get (dst, 0, dst.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the the <code>IntBUFFER</code> src
|
||||
* into the buffer. Before the transfer, it checks if there is fewer than
|
||||
* <code>src.remaining()</code> space remaining in this buffer.
|
||||
*
|
||||
* @param src The source data.
|
||||
*
|
||||
* @exception BufferOverflowException If there is insufficient space in this
|
||||
* buffer for the remaining <code>int</code>s in the source buffer.
|
||||
* @exception IllegalArgumentException If the source buffer is this buffer.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public IntBuffer put (IntBuffer src)
|
||||
{
|
||||
if (src == this)
|
||||
throw new IllegalArgumentException ();
|
||||
|
||||
checkForOverflow(src.remaining ());
|
||||
|
||||
if (src.remaining () > 0)
|
||||
{
|
||||
int[] toPut = new int [src.remaining ()];
|
||||
src.get (toPut);
|
||||
put (toPut);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the the <code>int array</code> src
|
||||
* into the buffer. Before the transfer, it checks if there is fewer than
|
||||
* length space remaining in this buffer.
|
||||
*
|
||||
* @param src The array to copy into the buffer.
|
||||
* @param offset The offset within the array of the first byte to be read;
|
||||
* must be non-negative and no larger than src.length.
|
||||
* @param length The number of bytes to be read from the given array;
|
||||
* must be non-negative and no larger than src.length - offset.
|
||||
*
|
||||
* @exception BufferOverflowException If there is insufficient space in this
|
||||
* buffer for the remaining <code>int</code>s in the source array.
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public IntBuffer put (int[] src, int offset, int length)
|
||||
{
|
||||
checkArraySize(src.length, offset, length);
|
||||
checkForOverflow(length);
|
||||
|
||||
for (int i = offset; i < offset + length; i++)
|
||||
put (src [i]);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the the <code>int array</code> src
|
||||
* into the buffer.
|
||||
*
|
||||
* @param src The array to copy into the buffer.
|
||||
*
|
||||
* @exception BufferOverflowException If there is insufficient space in this
|
||||
* buffer for the remaining <code>int</code>s in the source array.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public final IntBuffer put (int[] src)
|
||||
{
|
||||
return put (src, 0, src.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether ot not this buffer is backed by an accessible
|
||||
* <code>int</code> array.
|
||||
*/
|
||||
public final boolean hasArray ()
|
||||
{
|
||||
return (backing_buffer != null
|
||||
&& !isReadOnly ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <code>int</code> array that backs this buffer.
|
||||
*
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
* @exception UnsupportedOperationException If this buffer is not backed
|
||||
* by an accessible array.
|
||||
*/
|
||||
public final int[] array ()
|
||||
{
|
||||
if (backing_buffer == null)
|
||||
throw new UnsupportedOperationException ();
|
||||
|
||||
checkIfReadOnly();
|
||||
|
||||
return backing_buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the offset within this buffer's backing array of the first element.
|
||||
*
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
* @exception UnsupportedOperationException If this buffer is not backed
|
||||
* by an accessible array.
|
||||
*/
|
||||
public final int arrayOffset ()
|
||||
{
|
||||
if (backing_buffer == null)
|
||||
throw new UnsupportedOperationException ();
|
||||
|
||||
checkIfReadOnly();
|
||||
|
||||
return array_offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates a hash code for this buffer.
|
||||
*
|
||||
* This is done with <code>int</code> arithmetic,
|
||||
* where ** represents exponentiation, by this formula:<br>
|
||||
* <code>s[position()] + 31 + (s[position()+1] + 30)*31**1 + ... +
|
||||
* (s[limit()-1]+30)*31**(limit()-1)</code>.
|
||||
* Where s is the buffer data. Note that the hashcode is dependent
|
||||
* on buffer content, and therefore is not useful if the buffer
|
||||
* content may change.
|
||||
*
|
||||
* @return the hash code
|
||||
*/
|
||||
public int hashCode ()
|
||||
{
|
||||
int hashCode = get(position()) + 31;
|
||||
int multiplier = 1;
|
||||
for (int i = position() + 1; i < limit(); ++i)
|
||||
{
|
||||
multiplier *= 31;
|
||||
hashCode += (get(i) + 30)*multiplier;
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this buffer is equal to obj.
|
||||
*/
|
||||
public boolean equals (Object obj)
|
||||
{
|
||||
if (obj instanceof IntBuffer)
|
||||
{
|
||||
return compareTo (obj) == 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two <code>IntBuffer</code> objects.
|
||||
*
|
||||
* @exception ClassCastException If obj is not an object derived from
|
||||
* <code>IntBuffer</code>.
|
||||
*/
|
||||
public int compareTo (Object obj)
|
||||
{
|
||||
IntBuffer other = (IntBuffer) obj;
|
||||
|
||||
int num = Math.min(remaining(), other.remaining());
|
||||
int pos_this = position();
|
||||
int pos_other = other.position();
|
||||
|
||||
for (int count = 0; count < num; count++)
|
||||
{
|
||||
int a = get(pos_this++);
|
||||
int b = other.get(pos_other++);
|
||||
|
||||
if (a == b)
|
||||
continue;
|
||||
|
||||
if (a < b)
|
||||
return -1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return remaining() - other.remaining();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the byte order of this buffer.
|
||||
*/
|
||||
public abstract ByteOrder order ();
|
||||
|
||||
/**
|
||||
* Reads the <code>int</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are no remaining
|
||||
* <code>int</code>s in this buffer.
|
||||
*/
|
||||
public abstract int get ();
|
||||
|
||||
/**
|
||||
* Writes the <code>int</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferOverflowException If there no remaining
|
||||
* <code>int</code>s in this buffer.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public abstract IntBuffer put (int b);
|
||||
|
||||
/**
|
||||
* Absolute get method.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
*/
|
||||
public abstract int get (int index);
|
||||
|
||||
/**
|
||||
* Absolute put method.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public abstract IntBuffer put (int index, int b);
|
||||
|
||||
/**
|
||||
* Compacts this buffer.
|
||||
*
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public abstract IntBuffer compact ();
|
||||
|
||||
/**
|
||||
* Tells wether or not this buffer is direct.
|
||||
*/
|
||||
public abstract boolean isDirect ();
|
||||
|
||||
/**
|
||||
* Creates a new <code>IntBuffer</code> whose content is a shared
|
||||
* subsequence of this buffer's content.
|
||||
*/
|
||||
public abstract IntBuffer slice ();
|
||||
|
||||
/**
|
||||
* Creates a new <code>IntBuffer</code> that shares this buffer's
|
||||
* content.
|
||||
*/
|
||||
public abstract IntBuffer duplicate ();
|
||||
|
||||
/**
|
||||
* Creates a new read-only <code>IntBuffer</code> that shares this
|
||||
* buffer's content.
|
||||
*/
|
||||
public abstract IntBuffer asReadOnlyBuffer ();
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
/* IntBufferImpl.java --
|
||||
Copyright (C) 2002, 2003, 2004, 2005 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;
|
||||
|
||||
/**
|
||||
* This is a Heap memory implementation
|
||||
*/
|
||||
final class IntBufferImpl extends IntBuffer
|
||||
{
|
||||
private boolean readOnly;
|
||||
|
||||
IntBufferImpl (int capacity)
|
||||
{
|
||||
this (new int [capacity], 0, capacity, capacity, 0, -1, false);
|
||||
}
|
||||
|
||||
IntBufferImpl (int[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly)
|
||||
{
|
||||
super (capacity, limit, position, mark);
|
||||
this.backing_buffer = buffer;
|
||||
this.array_offset = offset;
|
||||
this.readOnly = readOnly;
|
||||
}
|
||||
|
||||
public boolean isReadOnly ()
|
||||
{
|
||||
return readOnly;
|
||||
}
|
||||
|
||||
public IntBuffer slice ()
|
||||
{
|
||||
return new IntBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ());
|
||||
}
|
||||
|
||||
public IntBuffer duplicate ()
|
||||
{
|
||||
return new IntBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ());
|
||||
}
|
||||
|
||||
public IntBuffer asReadOnlyBuffer ()
|
||||
{
|
||||
return new IntBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true);
|
||||
}
|
||||
|
||||
public IntBuffer compact ()
|
||||
{
|
||||
checkIfReadOnly();
|
||||
mark = -1;
|
||||
int copied = 0;
|
||||
|
||||
while (remaining () > 0)
|
||||
{
|
||||
put (copied, get ());
|
||||
copied++;
|
||||
}
|
||||
|
||||
position (copied);
|
||||
limit(capacity());
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isDirect ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the <code>int</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are no remaining
|
||||
* <code>ints</code> in this buffer.
|
||||
*/
|
||||
public int get ()
|
||||
{
|
||||
checkForUnderflow();
|
||||
|
||||
int result = backing_buffer [position ()];
|
||||
position (position () + 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Relative put method. Writes <code>value</code> to the next position
|
||||
* in the buffer.
|
||||
*
|
||||
* @exception BufferOverflowException If there no remaining
|
||||
* space in this buffer.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public IntBuffer put (int value)
|
||||
{
|
||||
checkIfReadOnly();
|
||||
checkForOverflow();
|
||||
|
||||
backing_buffer [position ()] = value;
|
||||
position (position () + 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute get method. Reads the <code>int</code> at position
|
||||
* <code>index</code>.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
*/
|
||||
public int get (int index)
|
||||
{
|
||||
checkIndex(index);
|
||||
|
||||
return backing_buffer [index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute put method. Writes <code>value</code> to position
|
||||
* <code>index</code> in the buffer.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public IntBuffer put (int index, int value)
|
||||
{
|
||||
checkIfReadOnly();
|
||||
checkIndex(index);
|
||||
|
||||
backing_buffer [index] = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ByteOrder order ()
|
||||
{
|
||||
return ByteOrder.nativeOrder ();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
/* IntViewBufferImpl.java --
|
||||
Copyright (C) 2003, 2004 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;
|
||||
|
||||
final class IntViewBufferImpl extends IntBuffer
|
||||
{
|
||||
/** Position in bb (i.e. a byte offset) where this buffer starts. */
|
||||
private int offset;
|
||||
private ByteBuffer bb;
|
||||
private boolean readOnly;
|
||||
private ByteOrder endian;
|
||||
|
||||
IntViewBufferImpl (ByteBuffer bb, int capacity)
|
||||
{
|
||||
super (capacity, capacity, 0, -1);
|
||||
this.bb = bb;
|
||||
this.offset = bb.position();
|
||||
this.readOnly = bb.isReadOnly();
|
||||
this.endian = bb.order();
|
||||
if (bb.isDirect())
|
||||
this.address = VMDirectByteBuffer.adjustAddress(bb.address, offset);
|
||||
}
|
||||
|
||||
public IntViewBufferImpl (ByteBuffer bb, int offset, int capacity,
|
||||
int limit, int position, int mark,
|
||||
boolean readOnly, ByteOrder endian)
|
||||
{
|
||||
super (capacity, limit, position, mark);
|
||||
this.bb = bb;
|
||||
this.offset = offset;
|
||||
this.readOnly = readOnly;
|
||||
this.endian = endian;
|
||||
if (bb.isDirect())
|
||||
this.address = VMDirectByteBuffer.adjustAddress(bb.address, offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the <code>int</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are no remaining
|
||||
* <code>ints</code> in this buffer.
|
||||
*/
|
||||
public int get ()
|
||||
{
|
||||
int p = position();
|
||||
int result = ByteBufferHelper.getInt(bb, (p << 2) + offset, endian);
|
||||
position(p + 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute get method. Reads the <code>int</code> at position
|
||||
* <code>index</code>.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
*/
|
||||
public int get (int index)
|
||||
{
|
||||
return ByteBufferHelper.getInt(bb, (index << 2) + offset, endian);
|
||||
}
|
||||
|
||||
public IntBuffer put (int value)
|
||||
{
|
||||
int p = position();
|
||||
ByteBufferHelper.putInt(bb, (p << 2) + offset, value, endian);
|
||||
position(p + 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
public IntBuffer put (int index, int value)
|
||||
{
|
||||
ByteBufferHelper.putInt(bb, (index << 2) + offset, value, endian);
|
||||
return this;
|
||||
}
|
||||
|
||||
public IntBuffer compact ()
|
||||
{
|
||||
if (position () > 0)
|
||||
{
|
||||
int count = limit () - position ();
|
||||
bb.shiftDown(offset, offset + 4 * position(), 4 * count);
|
||||
position (count);
|
||||
limit (capacity ());
|
||||
}
|
||||
else
|
||||
{
|
||||
position(limit());
|
||||
limit(capacity());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public IntBuffer slice ()
|
||||
{
|
||||
// Create a sliced copy of this object that shares its content.
|
||||
return new IntViewBufferImpl (bb, (position () >> 2) + offset,
|
||||
remaining(), remaining(), 0, -1,
|
||||
readOnly, endian);
|
||||
}
|
||||
|
||||
IntBuffer duplicate (boolean readOnly)
|
||||
{
|
||||
int pos = position();
|
||||
reset();
|
||||
int mark = position();
|
||||
position(pos);
|
||||
return new IntViewBufferImpl (bb, offset, capacity(), limit(),
|
||||
pos, mark, readOnly, endian);
|
||||
}
|
||||
|
||||
public IntBuffer duplicate ()
|
||||
{
|
||||
return duplicate(readOnly);
|
||||
}
|
||||
|
||||
public IntBuffer asReadOnlyBuffer ()
|
||||
{
|
||||
return duplicate(true);
|
||||
}
|
||||
|
||||
public boolean isReadOnly ()
|
||||
{
|
||||
return readOnly;
|
||||
}
|
||||
|
||||
public boolean isDirect ()
|
||||
{
|
||||
return bb.isDirect ();
|
||||
}
|
||||
|
||||
public ByteOrder order ()
|
||||
{
|
||||
return endian;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/* InvalidMarkException.java --
|
||||
Copyright (C) 2002 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;
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public class InvalidMarkException extends IllegalStateException
|
||||
{
|
||||
/**
|
||||
* Creates the exception
|
||||
*/
|
||||
public InvalidMarkException ()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,383 @@
|
||||
/* LongBuffer.java --
|
||||
Copyright (C) 2002, 2003, 2004 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;
|
||||
|
||||
/**
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class LongBuffer extends Buffer
|
||||
implements Comparable
|
||||
{
|
||||
int array_offset;
|
||||
long[] backing_buffer;
|
||||
|
||||
LongBuffer (int capacity, int limit, int position, int mark)
|
||||
{
|
||||
super (capacity, limit, position, mark);
|
||||
array_offset = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a new <code>LongBuffer</code> object with a given capacity.
|
||||
*/
|
||||
public static LongBuffer allocate (int capacity)
|
||||
{
|
||||
return new LongBufferImpl (capacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a <code>long</code> array into a <code>LongBuffer</code>
|
||||
* object.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold
|
||||
*/
|
||||
public static final LongBuffer wrap (long[] array, int offset, int length)
|
||||
{
|
||||
return new LongBufferImpl (array, 0, array.length, offset + length, offset, -1, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a <code>long</code> array into a <code>LongBuffer</code>
|
||||
* object.
|
||||
*/
|
||||
public static final LongBuffer wrap (long[] array)
|
||||
{
|
||||
return wrap (array, 0, array.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method transfers <code>long</code>s from this buffer into the given
|
||||
* destination array. Before the transfer, it checks if there are fewer than
|
||||
* length <code>long</code>s remaining in this buffer.
|
||||
*
|
||||
* @param dst The destination array
|
||||
* @param offset The offset within the array of the first <code>long</code>
|
||||
* to be written; must be non-negative and no larger than dst.length.
|
||||
* @param length The maximum number of bytes to be written to the given array;
|
||||
* must be non-negative and no larger than dst.length - offset.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are fewer than length
|
||||
* <code>long</code>s remaining in this buffer.
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold.
|
||||
*/
|
||||
public LongBuffer get (long[] dst, int offset, int length)
|
||||
{
|
||||
checkArraySize(dst.length, offset, length);
|
||||
checkForUnderflow(length);
|
||||
|
||||
for (int i = offset; i < offset + length; i++)
|
||||
{
|
||||
dst [i] = get ();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method transfers <code>long</code>s from this buffer into the given
|
||||
* destination array.
|
||||
*
|
||||
* @param dst The byte array to write into.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are fewer than dst.length
|
||||
* <code>long</code>s remaining in this buffer.
|
||||
*/
|
||||
public LongBuffer get (long[] dst)
|
||||
{
|
||||
return get (dst, 0, dst.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the the <code>LongBUFFER</code> src
|
||||
* into the buffer. Before the transfer, it checks if there is fewer than
|
||||
* <code>src.remaining()</code> space remaining in this buffer.
|
||||
*
|
||||
* @param src The source data.
|
||||
*
|
||||
* @exception BufferOverflowException If there is insufficient space in this
|
||||
* buffer for the remaining <code>long</code>s in the source buffer.
|
||||
* @exception IllegalArgumentException If the source buffer is this buffer.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public LongBuffer put (LongBuffer src)
|
||||
{
|
||||
if (src == this)
|
||||
throw new IllegalArgumentException ();
|
||||
|
||||
checkForOverflow(src.remaining ());
|
||||
|
||||
if (src.remaining () > 0)
|
||||
{
|
||||
long[] toPut = new long [src.remaining ()];
|
||||
src.get (toPut);
|
||||
put (toPut);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the the <code>long array</code> src
|
||||
* into the buffer. Before the transfer, it checks if there is fewer than
|
||||
* length space remaining in this buffer.
|
||||
*
|
||||
* @param src The array to copy into the buffer.
|
||||
* @param offset The offset within the array of the first byte to be read;
|
||||
* must be non-negative and no larger than src.length.
|
||||
* @param length The number of bytes to be read from the given array;
|
||||
* must be non-negative and no larger than src.length - offset.
|
||||
*
|
||||
* @exception BufferOverflowException If there is insufficient space in this
|
||||
* buffer for the remaining <code>long</code>s in the source array.
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public LongBuffer put (long[] src, int offset, int length)
|
||||
{
|
||||
checkArraySize(src.length, offset, length);
|
||||
checkForOverflow(length);
|
||||
|
||||
for (int i = offset; i < offset + length; i++)
|
||||
put (src [i]);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the the <code>long array</code> src
|
||||
* into the buffer.
|
||||
*
|
||||
* @param src The array to copy into the buffer.
|
||||
*
|
||||
* @exception BufferOverflowException If there is insufficient space in this
|
||||
* buffer for the remaining <code>long</code>s in the source array.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public final LongBuffer put (long[] src)
|
||||
{
|
||||
return put (src, 0, src.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether ot not this buffer is backed by an accessible
|
||||
* <code>long</code> array.
|
||||
*/
|
||||
public final boolean hasArray ()
|
||||
{
|
||||
return (backing_buffer != null
|
||||
&& !isReadOnly ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <code>long</code> array that backs this buffer.
|
||||
*
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
* @exception UnsupportedOperationException If this buffer is not backed
|
||||
* by an accessible array.
|
||||
*/
|
||||
public final long[] array ()
|
||||
{
|
||||
if (backing_buffer == null)
|
||||
throw new UnsupportedOperationException ();
|
||||
|
||||
checkIfReadOnly();
|
||||
|
||||
return backing_buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the offset within this buffer's backing array of the first element.
|
||||
*
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
* @exception UnsupportedOperationException If this buffer is not backed
|
||||
* by an accessible array.
|
||||
*/
|
||||
public final int arrayOffset ()
|
||||
{
|
||||
if (backing_buffer == null)
|
||||
throw new UnsupportedOperationException ();
|
||||
|
||||
checkIfReadOnly();
|
||||
|
||||
return array_offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates a hash code for this buffer.
|
||||
*
|
||||
* This is done with <code>long</code> arithmetic,
|
||||
* where ** represents exponentiation, by this formula:<br>
|
||||
* <code>s[position()] + 31 + (s[position()+1] + 30)*31**1 + ... +
|
||||
* (s[limit()-1]+30)*31**(limit()-1)</code>.
|
||||
* Where s is the buffer data. Note that the hashcode is dependent
|
||||
* on buffer content, and therefore is not useful if the buffer
|
||||
* content may change.
|
||||
*
|
||||
* @return the hash code (casted to int)
|
||||
*/
|
||||
public int hashCode ()
|
||||
{
|
||||
long hashCode = get(position()) + 31;
|
||||
long multiplier = 1;
|
||||
for (int i = position() + 1; i < limit(); ++i)
|
||||
{
|
||||
multiplier *= 31;
|
||||
hashCode += (get(i) + 30)*multiplier;
|
||||
}
|
||||
return ((int)hashCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this buffer is equal to obj.
|
||||
*/
|
||||
public boolean equals (Object obj)
|
||||
{
|
||||
if (obj instanceof LongBuffer)
|
||||
{
|
||||
return compareTo (obj) == 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two <code>LongBuffer</code> objects.
|
||||
*
|
||||
* @exception ClassCastException If obj is not an object derived from
|
||||
* <code>LongBuffer</code>.
|
||||
*/
|
||||
public int compareTo (Object obj)
|
||||
{
|
||||
LongBuffer other = (LongBuffer) obj;
|
||||
|
||||
int num = Math.min(remaining(), other.remaining());
|
||||
int pos_this = position();
|
||||
int pos_other = other.position();
|
||||
|
||||
for (int count = 0; count < num; count++)
|
||||
{
|
||||
long a = get(pos_this++);
|
||||
long b = other.get(pos_other++);
|
||||
|
||||
if (a == b)
|
||||
continue;
|
||||
|
||||
if (a < b)
|
||||
return -1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return remaining() - other.remaining();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the byte order of this buffer.
|
||||
*/
|
||||
public abstract ByteOrder order ();
|
||||
|
||||
/**
|
||||
* Reads the <code>long</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are no remaining
|
||||
* <code>long</code>s in this buffer.
|
||||
*/
|
||||
public abstract long get ();
|
||||
|
||||
/**
|
||||
* Writes the <code>long</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferOverflowException If there no remaining
|
||||
* <code>long</code>s in this buffer.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public abstract LongBuffer put (long b);
|
||||
|
||||
/**
|
||||
* Absolute get method.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
*/
|
||||
public abstract long get (int index);
|
||||
|
||||
/**
|
||||
* Absolute put method.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public abstract LongBuffer put (int index, long b);
|
||||
|
||||
/**
|
||||
* Compacts this buffer.
|
||||
*
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public abstract LongBuffer compact ();
|
||||
|
||||
/**
|
||||
* Tells wether or not this buffer is direct.
|
||||
*/
|
||||
public abstract boolean isDirect ();
|
||||
|
||||
/**
|
||||
* Creates a new <code>LongBuffer</code> whose content is a shared
|
||||
* subsequence of this buffer's content.
|
||||
*/
|
||||
public abstract LongBuffer slice ();
|
||||
|
||||
/**
|
||||
* Creates a new <code>LongBuffer</code> that shares this buffer's
|
||||
* content.
|
||||
*/
|
||||
public abstract LongBuffer duplicate ();
|
||||
|
||||
/**
|
||||
* Creates a new read-only <code>LongBuffer</code> that shares this
|
||||
* buffer's content.
|
||||
*/
|
||||
public abstract LongBuffer asReadOnlyBuffer ();
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
/* LongBufferImpl.java --
|
||||
Copyright (C) 2002, 2003, 2004, 2005 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;
|
||||
|
||||
/**
|
||||
* This is a Heap memory implementation
|
||||
*/
|
||||
final class LongBufferImpl extends LongBuffer
|
||||
{
|
||||
private boolean readOnly;
|
||||
|
||||
LongBufferImpl (int capacity)
|
||||
{
|
||||
this (new long [capacity], 0, capacity, capacity, 0, -1, false);
|
||||
}
|
||||
|
||||
LongBufferImpl (long[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly)
|
||||
{
|
||||
super (capacity, limit, position, mark);
|
||||
this.backing_buffer = buffer;
|
||||
this.array_offset = offset;
|
||||
this.readOnly = readOnly;
|
||||
}
|
||||
|
||||
public boolean isReadOnly ()
|
||||
{
|
||||
return readOnly;
|
||||
}
|
||||
|
||||
public LongBuffer slice ()
|
||||
{
|
||||
return new LongBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ());
|
||||
}
|
||||
|
||||
public LongBuffer duplicate ()
|
||||
{
|
||||
return new LongBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ());
|
||||
}
|
||||
|
||||
public LongBuffer asReadOnlyBuffer ()
|
||||
{
|
||||
return new LongBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true);
|
||||
}
|
||||
|
||||
public LongBuffer compact ()
|
||||
{
|
||||
checkIfReadOnly();
|
||||
mark = -1;
|
||||
int copied = 0;
|
||||
|
||||
while (remaining () > 0)
|
||||
{
|
||||
put (copied, get ());
|
||||
copied++;
|
||||
}
|
||||
|
||||
position (copied);
|
||||
limit(capacity());
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isDirect ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the <code>long</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are no remaining
|
||||
* <code>longs</code> in this buffer.
|
||||
*/
|
||||
public long get ()
|
||||
{
|
||||
checkForUnderflow();
|
||||
|
||||
long result = backing_buffer [position ()];
|
||||
position (position () + 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Relative put method. Writes <code>value</code> to the next position
|
||||
* in the buffer.
|
||||
*
|
||||
* @exception BufferOverflowException If there is insufficient space in this
|
||||
* buffer.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public LongBuffer put (long value)
|
||||
{
|
||||
checkIfReadOnly();
|
||||
checkForOverflow();
|
||||
|
||||
backing_buffer [position ()] = value;
|
||||
position (position () + 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute get method. Reads the <code>long</code> at position
|
||||
* <code>index</code>.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
*/
|
||||
public long get (int index)
|
||||
{
|
||||
checkIndex(index);
|
||||
|
||||
return backing_buffer [index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute put method. Writes <code>value</code> to position
|
||||
* <code>index</code> in the buffer.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public LongBuffer put (int index, long value)
|
||||
{
|
||||
checkIfReadOnly();
|
||||
checkIndex(index);
|
||||
|
||||
backing_buffer [index] = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ByteOrder order ()
|
||||
{
|
||||
return ByteOrder.nativeOrder ();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
/* LongViewBufferImpl.java --
|
||||
Copyright (C) 2003, 2004 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;
|
||||
|
||||
final class LongViewBufferImpl extends LongBuffer
|
||||
{
|
||||
/** Position in bb (i.e. a byte offset) where this buffer starts. */
|
||||
private int offset;
|
||||
private ByteBuffer bb;
|
||||
private boolean readOnly;
|
||||
private ByteOrder endian;
|
||||
|
||||
LongViewBufferImpl (ByteBuffer bb, int capacity)
|
||||
{
|
||||
super (capacity, capacity, 0, -1);
|
||||
this.bb = bb;
|
||||
this.offset = bb.position();
|
||||
this.readOnly = bb.isReadOnly();
|
||||
this.endian = bb.order();
|
||||
if (bb.isDirect())
|
||||
this.address = VMDirectByteBuffer.adjustAddress(bb.address, offset);
|
||||
}
|
||||
|
||||
public LongViewBufferImpl (ByteBuffer bb, int offset, int capacity,
|
||||
int limit, int position, int mark,
|
||||
boolean readOnly, ByteOrder endian)
|
||||
{
|
||||
super (capacity, limit, position, mark);
|
||||
this.bb = bb;
|
||||
this.offset = offset;
|
||||
this.readOnly = readOnly;
|
||||
this.endian = endian;
|
||||
if (bb.isDirect())
|
||||
this.address = VMDirectByteBuffer.adjustAddress(bb.address, offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the <code>long</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are no remaining
|
||||
* <code>longs</code> in this buffer.
|
||||
*/
|
||||
public long get ()
|
||||
{
|
||||
int p = position();
|
||||
long result = ByteBufferHelper.getLong(bb, (p << 3) + offset, endian);
|
||||
position(p + 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute get method. Reads the <code>long</code> at position
|
||||
* <code>index</code>.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
*/
|
||||
public long get (int index)
|
||||
{
|
||||
return ByteBufferHelper.getLong(bb, (index << 3) + offset, endian);
|
||||
}
|
||||
|
||||
public LongBuffer put (long value)
|
||||
{
|
||||
int p = position();
|
||||
ByteBufferHelper.putLong(bb, (p << 3) + offset, value, endian);
|
||||
position(p + 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LongBuffer put (int index, long value)
|
||||
{
|
||||
ByteBufferHelper.putLong(bb, (index << 3) + offset, value, endian);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LongBuffer compact ()
|
||||
{
|
||||
if (position () > 0)
|
||||
{
|
||||
int count = limit () - position ();
|
||||
bb.shiftDown(offset, offset + 8 * position(), 8 * count);
|
||||
position (count);
|
||||
limit (capacity ());
|
||||
}
|
||||
else
|
||||
{
|
||||
position(limit());
|
||||
limit(capacity());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public LongBuffer slice ()
|
||||
{
|
||||
// Create a sliced copy of this object that shares its content.
|
||||
return new LongViewBufferImpl (bb, (position () >> 3) + offset,
|
||||
remaining(), remaining(), 0, -1,
|
||||
readOnly, endian);
|
||||
}
|
||||
|
||||
LongBuffer duplicate (boolean readOnly)
|
||||
{
|
||||
int pos = position();
|
||||
reset();
|
||||
int mark = position();
|
||||
position(pos);
|
||||
return new LongViewBufferImpl (bb, offset, capacity(), limit(),
|
||||
pos, mark, readOnly, endian);
|
||||
}
|
||||
|
||||
public LongBuffer duplicate ()
|
||||
{
|
||||
return duplicate(readOnly);
|
||||
}
|
||||
|
||||
public LongBuffer asReadOnlyBuffer ()
|
||||
{
|
||||
return duplicate(true);
|
||||
}
|
||||
|
||||
public boolean isReadOnly ()
|
||||
{
|
||||
return readOnly;
|
||||
}
|
||||
|
||||
public boolean isDirect ()
|
||||
{
|
||||
return bb.isDirect ();
|
||||
}
|
||||
|
||||
public ByteOrder order ()
|
||||
{
|
||||
return endian;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/* MappedByteBuffer.java --
|
||||
Copyright (C) 2002, 2004 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;
|
||||
|
||||
/**
|
||||
* @author Michael Koch (konqueror@gmx.de)
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class MappedByteBuffer extends ByteBuffer
|
||||
{
|
||||
MappedByteBuffer (int capacity, int limit, int position, int mark)
|
||||
{
|
||||
super (capacity, limit, position, mark);
|
||||
}
|
||||
|
||||
void forceImpl()
|
||||
{
|
||||
}
|
||||
|
||||
public final MappedByteBuffer force ()
|
||||
{
|
||||
forceImpl();
|
||||
return this;
|
||||
}
|
||||
|
||||
boolean isLoadedImpl()
|
||||
{
|
||||
load();
|
||||
return true;
|
||||
}
|
||||
|
||||
public final boolean isLoaded ()
|
||||
{
|
||||
return isLoadedImpl();
|
||||
}
|
||||
|
||||
void loadImpl()
|
||||
{
|
||||
}
|
||||
|
||||
public final MappedByteBuffer load ()
|
||||
{
|
||||
loadImpl();
|
||||
return this;
|
||||
}
|
||||
|
||||
void unmapImpl ()
|
||||
{
|
||||
forceImpl();
|
||||
}
|
||||
|
||||
public void finalize()
|
||||
throws Throwable
|
||||
{
|
||||
unmapImpl();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,360 @@
|
||||
/* MappedByteBufferImpl.java --
|
||||
Copyright (C) 2002, 2003, 2004 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;
|
||||
|
||||
import gnu.classpath.RawData;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
final class MappedByteBufferImpl extends MappedByteBuffer
|
||||
{
|
||||
boolean readOnly;
|
||||
|
||||
/** Posix uses this for the pointer returned by mmap;
|
||||
* Win32 uses it for the pointer returned by MapViewOfFile. */
|
||||
public RawData implPtr;
|
||||
/** Posix uses this for the actual length passed to mmap;
|
||||
* Win32 uses it for the pointer returned by CreateFileMapping. */
|
||||
public long implLen;
|
||||
|
||||
public MappedByteBufferImpl(RawData address, int size, boolean readOnly)
|
||||
throws IOException
|
||||
{
|
||||
super(size, size, 0, -1);
|
||||
this.address = address;
|
||||
this.readOnly = readOnly;
|
||||
}
|
||||
|
||||
public boolean isReadOnly()
|
||||
{
|
||||
return readOnly;
|
||||
}
|
||||
|
||||
public byte get()
|
||||
{
|
||||
checkForUnderflow();
|
||||
|
||||
int pos = position();
|
||||
byte result = VMDirectByteBuffer.get(address, pos);
|
||||
position(pos + 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
public ByteBuffer put(byte value)
|
||||
{
|
||||
checkIfReadOnly();
|
||||
checkForOverflow();
|
||||
|
||||
int pos = position();
|
||||
VMDirectByteBuffer.put(address, pos, value);
|
||||
position(pos + 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
public byte get(int index)
|
||||
{
|
||||
checkIndex(index);
|
||||
|
||||
return VMDirectByteBuffer.get(address, index);
|
||||
}
|
||||
|
||||
public ByteBuffer get(byte[] dst, int offset, int length)
|
||||
{
|
||||
checkArraySize(dst.length, offset, length);
|
||||
checkForUnderflow(length);
|
||||
|
||||
int index = position();
|
||||
VMDirectByteBuffer.get(address, index, dst, offset, length);
|
||||
position(index+length);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ByteBuffer put(int index, byte value)
|
||||
{
|
||||
checkIfReadOnly();
|
||||
checkIndex(index);
|
||||
|
||||
VMDirectByteBuffer.put(address, index, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ByteBuffer compact()
|
||||
{
|
||||
checkIfReadOnly();
|
||||
mark = -1;
|
||||
int pos = position();
|
||||
if (pos > 0)
|
||||
{
|
||||
int count = remaining();
|
||||
// Call shiftDown method optimized for direct buffers.
|
||||
VMDirectByteBuffer.shiftDown(address, 0, pos, count);
|
||||
position(count);
|
||||
limit(capacity());
|
||||
}
|
||||
else
|
||||
{
|
||||
position(limit());
|
||||
limit(capacity());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isDirect()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public ByteBuffer slice()
|
||||
{
|
||||
int rem = remaining();
|
||||
if (isReadOnly())
|
||||
return new DirectByteBufferImpl.ReadOnly
|
||||
(this, VMDirectByteBuffer.adjustAddress(address, position()),
|
||||
rem, rem, 0);
|
||||
else
|
||||
return new DirectByteBufferImpl.ReadWrite
|
||||
(this, VMDirectByteBuffer.adjustAddress(address, position()),
|
||||
rem, rem, 0);
|
||||
}
|
||||
|
||||
private ByteBuffer duplicate(boolean readOnly)
|
||||
{
|
||||
int pos = position();
|
||||
reset();
|
||||
int mark = position();
|
||||
position(pos);
|
||||
DirectByteBufferImpl result;
|
||||
if (readOnly)
|
||||
result = new DirectByteBufferImpl.ReadOnly(this, address, capacity(),
|
||||
limit(), pos);
|
||||
else
|
||||
result = new DirectByteBufferImpl.ReadWrite(this, address, capacity(),
|
||||
limit(), pos);
|
||||
|
||||
if (mark != pos)
|
||||
{
|
||||
result.position(mark);
|
||||
result.mark();
|
||||
result.position(pos);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public ByteBuffer duplicate()
|
||||
{
|
||||
return duplicate(isReadOnly());
|
||||
}
|
||||
|
||||
public ByteBuffer asReadOnlyBuffer()
|
||||
{
|
||||
return duplicate(true);
|
||||
}
|
||||
|
||||
public CharBuffer asCharBuffer()
|
||||
{
|
||||
return new CharViewBufferImpl(this, remaining() >> 1);
|
||||
}
|
||||
|
||||
public ShortBuffer asShortBuffer()
|
||||
{
|
||||
return new ShortViewBufferImpl(this, remaining() >> 1);
|
||||
}
|
||||
|
||||
public IntBuffer asIntBuffer()
|
||||
{
|
||||
return new IntViewBufferImpl(this, remaining() >> 2);
|
||||
}
|
||||
|
||||
public LongBuffer asLongBuffer()
|
||||
{
|
||||
return new LongViewBufferImpl(this, remaining() >> 3);
|
||||
}
|
||||
|
||||
public FloatBuffer asFloatBuffer()
|
||||
{
|
||||
return new FloatViewBufferImpl(this, remaining() >> 2);
|
||||
}
|
||||
|
||||
public DoubleBuffer asDoubleBuffer()
|
||||
{
|
||||
return new DoubleViewBufferImpl(this, remaining() >> 3);
|
||||
}
|
||||
|
||||
public char getChar()
|
||||
{
|
||||
return ByteBufferHelper.getChar(this, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putChar(char value)
|
||||
{
|
||||
ByteBufferHelper.putChar(this, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public char getChar(int index)
|
||||
{
|
||||
return ByteBufferHelper.getChar(this, index, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putChar(int index, char value)
|
||||
{
|
||||
ByteBufferHelper.putChar(this, index, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public short getShort()
|
||||
{
|
||||
return ByteBufferHelper.getShort(this, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putShort(short value)
|
||||
{
|
||||
ByteBufferHelper.putShort(this, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public short getShort(int index)
|
||||
{
|
||||
return ByteBufferHelper.getShort(this, index, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putShort(int index, short value)
|
||||
{
|
||||
ByteBufferHelper.putShort(this, index, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getInt()
|
||||
{
|
||||
return ByteBufferHelper.getInt(this, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putInt(int value)
|
||||
{
|
||||
ByteBufferHelper.putInt(this, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getInt(int index)
|
||||
{
|
||||
return ByteBufferHelper.getInt(this, index, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putInt(int index, int value)
|
||||
{
|
||||
ByteBufferHelper.putInt(this, index, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public long getLong()
|
||||
{
|
||||
return ByteBufferHelper.getLong(this, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putLong(long value)
|
||||
{
|
||||
ByteBufferHelper.putLong(this, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public long getLong(int index)
|
||||
{
|
||||
return ByteBufferHelper.getLong(this, index, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putLong(int index, long value)
|
||||
{
|
||||
ByteBufferHelper.putLong(this, index, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public float getFloat()
|
||||
{
|
||||
return ByteBufferHelper.getFloat(this, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putFloat(float value)
|
||||
{
|
||||
ByteBufferHelper.putFloat(this, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public float getFloat(int index)
|
||||
{
|
||||
return ByteBufferHelper.getFloat(this, index, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putFloat(int index, float value)
|
||||
{
|
||||
ByteBufferHelper.putFloat(this, index, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public double getDouble()
|
||||
{
|
||||
return ByteBufferHelper.getDouble(this, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putDouble(double value)
|
||||
{
|
||||
ByteBufferHelper.putDouble(this, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
public double getDouble(int index)
|
||||
{
|
||||
return ByteBufferHelper.getDouble(this, index, order());
|
||||
}
|
||||
|
||||
public ByteBuffer putDouble(int index, double value)
|
||||
{
|
||||
ByteBufferHelper.putDouble(this, index, value, order());
|
||||
return this;
|
||||
}
|
||||
|
||||
// NOTE: In libgcj these methods are implemented in natFileChannelXxx.cc,
|
||||
// because they're small, and to put them next to FileChannelImpl::mapImpl.
|
||||
native void unmapImpl();
|
||||
native boolean isLoadedImpl();
|
||||
// FIXME: Try to load all pages into memory.
|
||||
native void loadImpl();
|
||||
|
||||
native void forceImpl();
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/* ReadOnlyBufferException.java --
|
||||
Copyright (C) 2002 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;
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public class ReadOnlyBufferException extends UnsupportedOperationException
|
||||
{
|
||||
/**
|
||||
* Creates the exception
|
||||
*/
|
||||
public ReadOnlyBufferException ()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,383 @@
|
||||
/* ShortBuffer.java --
|
||||
Copyright (C) 2002, 2003, 2004 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;
|
||||
|
||||
/**
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class ShortBuffer extends Buffer
|
||||
implements Comparable
|
||||
{
|
||||
int array_offset;
|
||||
short[] backing_buffer;
|
||||
|
||||
ShortBuffer (int capacity, int limit, int position, int mark)
|
||||
{
|
||||
super (capacity, limit, position, mark);
|
||||
array_offset = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a new <code>ShortBuffer</code> object with a given capacity.
|
||||
*/
|
||||
public static ShortBuffer allocate (int capacity)
|
||||
{
|
||||
return new ShortBufferImpl (capacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a <code>short</code> array into a <code>ShortBuffer</code>
|
||||
* object.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold
|
||||
*/
|
||||
public static final ShortBuffer wrap (short[] array, int offset, int length)
|
||||
{
|
||||
return new ShortBufferImpl (array, 0, array.length, offset + length, offset, -1, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a <code>short</code> array into a <code>ShortBuffer</code>
|
||||
* object.
|
||||
*/
|
||||
public static final ShortBuffer wrap (short[] array)
|
||||
{
|
||||
return wrap (array, 0, array.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method transfers <code>short</code>s from this buffer into the given
|
||||
* destination array. Before the transfer, it checks if there are fewer than
|
||||
* length <code>short</code>s remaining in this buffer.
|
||||
*
|
||||
* @param dst The destination array
|
||||
* @param offset The offset within the array of the first <code>short</code>
|
||||
* to be written; must be non-negative and no larger than dst.length.
|
||||
* @param length The maximum number of bytes to be written to the given array;
|
||||
* must be non-negative and no larger than dst.length - offset.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are fewer than length
|
||||
* <code>short</code>s remaining in this buffer.
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold.
|
||||
*/
|
||||
public ShortBuffer get (short[] dst, int offset, int length)
|
||||
{
|
||||
checkArraySize(dst.length, offset, length);
|
||||
checkForUnderflow(length);
|
||||
|
||||
for (int i = offset; i < offset + length; i++)
|
||||
{
|
||||
dst [i] = get ();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method transfers <code>short</code>s from this buffer into the given
|
||||
* destination array.
|
||||
*
|
||||
* @param dst The byte array to write into.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are fewer than dst.length
|
||||
* <code>short</code>s remaining in this buffer.
|
||||
*/
|
||||
public ShortBuffer get (short[] dst)
|
||||
{
|
||||
return get (dst, 0, dst.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the the <code>ShortBUFFER</code> src
|
||||
* into the buffer. Before the transfer, it checks if there is fewer than
|
||||
* <code>src.remaining()</code> space remaining in this buffer.
|
||||
*
|
||||
* @param src The source data.
|
||||
*
|
||||
* @exception BufferOverflowException If there is insufficient space in this
|
||||
* buffer for the remaining <code>short</code>s in the source buffer.
|
||||
* @exception IllegalArgumentException If the source buffer is this buffer.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public ShortBuffer put (ShortBuffer src)
|
||||
{
|
||||
if (src == this)
|
||||
throw new IllegalArgumentException ();
|
||||
|
||||
checkForOverflow(src.remaining ());
|
||||
|
||||
if (src.remaining () > 0)
|
||||
{
|
||||
short[] toPut = new short [src.remaining ()];
|
||||
src.get (toPut);
|
||||
put (toPut);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the the <code>short array</code> src
|
||||
* into the buffer. Before the transfer, it checks if there is fewer than
|
||||
* length space remaining in this buffer.
|
||||
*
|
||||
* @param src The array to copy into the buffer.
|
||||
* @param offset The offset within the array of the first byte to be read;
|
||||
* must be non-negative and no larger than src.length.
|
||||
* @param length The number of bytes to be read from the given array;
|
||||
* must be non-negative and no larger than src.length - offset.
|
||||
*
|
||||
* @exception BufferOverflowException If there is insufficient space in this
|
||||
* buffer for the remaining <code>short</code>s in the source array.
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public ShortBuffer put (short[] src, int offset, int length)
|
||||
{
|
||||
checkArraySize(src.length, offset, length);
|
||||
checkForOverflow(length);
|
||||
|
||||
for (int i = offset; i < offset + length; i++)
|
||||
put (src [i]);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the the <code>short array</code> src
|
||||
* into the buffer.
|
||||
*
|
||||
* @param src The array to copy into the buffer.
|
||||
*
|
||||
* @exception BufferOverflowException If there is insufficient space in this
|
||||
* buffer for the remaining <code>short</code>s in the source array.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public final ShortBuffer put (short[] src)
|
||||
{
|
||||
return put (src, 0, src.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether ot not this buffer is backed by an accessible
|
||||
* <code>short</code> array.
|
||||
*/
|
||||
public final boolean hasArray ()
|
||||
{
|
||||
return (backing_buffer != null
|
||||
&& !isReadOnly ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <code>short</code> array that backs this buffer.
|
||||
*
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
* @exception UnsupportedOperationException If this buffer is not backed
|
||||
* by an accessible array.
|
||||
*/
|
||||
public final short[] array ()
|
||||
{
|
||||
if (backing_buffer == null)
|
||||
throw new UnsupportedOperationException ();
|
||||
|
||||
checkIfReadOnly();
|
||||
|
||||
return backing_buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the offset within this buffer's backing array of the first element.
|
||||
*
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
* @exception UnsupportedOperationException If this buffer is not backed
|
||||
* by an accessible array.
|
||||
*/
|
||||
public final int arrayOffset ()
|
||||
{
|
||||
if (backing_buffer == null)
|
||||
throw new UnsupportedOperationException ();
|
||||
|
||||
checkIfReadOnly();
|
||||
|
||||
return array_offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates a hash code for this buffer.
|
||||
*
|
||||
* This is done with <code>int</code> arithmetic,
|
||||
* where ** represents exponentiation, by this formula:<br>
|
||||
* <code>s[position()] + 31 + (s[position()+1] + 30)*31**1 + ... +
|
||||
* (s[limit()-1]+30)*31**(limit()-1)</code>.
|
||||
* Where s is the buffer data. Note that the hashcode is dependent
|
||||
* on buffer content, and therefore is not useful if the buffer
|
||||
* content may change.
|
||||
*
|
||||
* @return the hash code
|
||||
*/
|
||||
public int hashCode ()
|
||||
{
|
||||
int hashCode = get(position()) + 31;
|
||||
int multiplier = 1;
|
||||
for (int i = position() + 1; i < limit(); ++i)
|
||||
{
|
||||
multiplier *= 31;
|
||||
hashCode += (get(i) + 30)*multiplier;
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this buffer is equal to obj.
|
||||
*/
|
||||
public boolean equals (Object obj)
|
||||
{
|
||||
if (obj instanceof ShortBuffer)
|
||||
{
|
||||
return compareTo (obj) == 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two <code>ShortBuffer</code> objects.
|
||||
*
|
||||
* @exception ClassCastException If obj is not an object derived from
|
||||
* <code>ShortBuffer</code>.
|
||||
*/
|
||||
public int compareTo (Object obj)
|
||||
{
|
||||
ShortBuffer other = (ShortBuffer) obj;
|
||||
|
||||
int num = Math.min(remaining(), other.remaining());
|
||||
int pos_this = position();
|
||||
int pos_other = other.position();
|
||||
|
||||
for (int count = 0; count < num; count++)
|
||||
{
|
||||
short a = get(pos_this++);
|
||||
short b = other.get(pos_other++);
|
||||
|
||||
if (a == b)
|
||||
continue;
|
||||
|
||||
if (a < b)
|
||||
return -1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return remaining() - other.remaining();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the byte order of this buffer.
|
||||
*/
|
||||
public abstract ByteOrder order ();
|
||||
|
||||
/**
|
||||
* Reads the <code>short</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are no remaining
|
||||
* <code>short</code>s in this buffer.
|
||||
*/
|
||||
public abstract short get ();
|
||||
|
||||
/**
|
||||
* Writes the <code>short</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferOverflowException If there no remaining
|
||||
* <code>short</code>s in this buffer.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public abstract ShortBuffer put (short b);
|
||||
|
||||
/**
|
||||
* Absolute get method.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
*/
|
||||
public abstract short get (int index);
|
||||
|
||||
/**
|
||||
* Absolute put method.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public abstract ShortBuffer put (int index, short b);
|
||||
|
||||
/**
|
||||
* Compacts this buffer.
|
||||
*
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public abstract ShortBuffer compact ();
|
||||
|
||||
/**
|
||||
* Tells wether or not this buffer is direct.
|
||||
*/
|
||||
public abstract boolean isDirect ();
|
||||
|
||||
/**
|
||||
* Creates a new <code>ShortBuffer</code> whose content is a shared
|
||||
* subsequence of this buffer's content.
|
||||
*/
|
||||
public abstract ShortBuffer slice ();
|
||||
|
||||
/**
|
||||
* Creates a new <code>ShortBuffer</code> that shares this buffer's
|
||||
* content.
|
||||
*/
|
||||
public abstract ShortBuffer duplicate ();
|
||||
|
||||
/**
|
||||
* Creates a new read-only <code>ShortBuffer</code> that shares this
|
||||
* buffer's content.
|
||||
*/
|
||||
public abstract ShortBuffer asReadOnlyBuffer ();
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
/* ShortBufferImpl.java --
|
||||
Copyright (C) 2002, 2003, 2004, 2005 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;
|
||||
|
||||
/**
|
||||
* This is a Heap memory implementation
|
||||
*/
|
||||
final class ShortBufferImpl extends ShortBuffer
|
||||
{
|
||||
private boolean readOnly;
|
||||
|
||||
ShortBufferImpl (int capacity)
|
||||
{
|
||||
this (new short [capacity], 0, capacity, capacity, 0, -1, false);
|
||||
}
|
||||
|
||||
ShortBufferImpl (short[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly)
|
||||
{
|
||||
super (capacity, limit, position, mark);
|
||||
this.backing_buffer = buffer;
|
||||
this.array_offset = offset;
|
||||
this.readOnly = readOnly;
|
||||
}
|
||||
|
||||
public boolean isReadOnly ()
|
||||
{
|
||||
return readOnly;
|
||||
}
|
||||
|
||||
public ShortBuffer slice ()
|
||||
{
|
||||
return new ShortBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ());
|
||||
}
|
||||
|
||||
public ShortBuffer duplicate ()
|
||||
{
|
||||
return new ShortBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ());
|
||||
}
|
||||
|
||||
public ShortBuffer asReadOnlyBuffer ()
|
||||
{
|
||||
return new ShortBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true);
|
||||
}
|
||||
|
||||
public ShortBuffer compact ()
|
||||
{
|
||||
checkIfReadOnly();
|
||||
mark = -1;
|
||||
int copied = 0;
|
||||
|
||||
while (remaining () > 0)
|
||||
{
|
||||
put (copied, get ());
|
||||
copied++;
|
||||
}
|
||||
|
||||
position (copied);
|
||||
limit(capacity());
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isDirect ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the <code>short</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are no remaining
|
||||
* <code>short</code>s in this buffer.
|
||||
*/
|
||||
public short get ()
|
||||
{
|
||||
checkForUnderflow();
|
||||
|
||||
short result = backing_buffer [position ()];
|
||||
position (position () + 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Relative put method. Writes <code>value</code> to the next position
|
||||
* in the buffer.
|
||||
*
|
||||
* @exception BufferOverflowException If there no remaining
|
||||
* space in this buffer.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public ShortBuffer put (short value)
|
||||
{
|
||||
checkIfReadOnly();
|
||||
checkForOverflow();
|
||||
|
||||
backing_buffer [position ()] = value;
|
||||
position (position () + 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute get method. Reads the <code>short</code> at position
|
||||
* <code>index</code>.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
*/
|
||||
public short get (int index)
|
||||
{
|
||||
checkIndex(index);
|
||||
|
||||
return backing_buffer [index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute put method. Writes <code>value</code> to position
|
||||
* <code>index</code> in the buffer.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public ShortBuffer put (int index, short value)
|
||||
{
|
||||
checkIfReadOnly();
|
||||
checkIndex(index);
|
||||
|
||||
backing_buffer [index] = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ByteOrder order ()
|
||||
{
|
||||
return ByteOrder.nativeOrder ();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
/* ShortViewBufferImpl.java --
|
||||
Copyright (C) 2003, 2004 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;
|
||||
|
||||
final class ShortViewBufferImpl extends ShortBuffer
|
||||
{
|
||||
/** Position in bb (i.e. a byte offset) where this buffer starts. */
|
||||
private int offset;
|
||||
private ByteBuffer bb;
|
||||
private boolean readOnly;
|
||||
private ByteOrder endian;
|
||||
|
||||
ShortViewBufferImpl (ByteBuffer bb, int capacity)
|
||||
{
|
||||
super (capacity, capacity, 0, -1);
|
||||
this.bb = bb;
|
||||
this.offset = bb.position();
|
||||
this.readOnly = bb.isReadOnly();
|
||||
this.endian = bb.order();
|
||||
if (bb.isDirect())
|
||||
this.address = VMDirectByteBuffer.adjustAddress(bb.address, offset);
|
||||
}
|
||||
|
||||
public ShortViewBufferImpl (ByteBuffer bb, int offset, int capacity,
|
||||
int limit, int position, int mark,
|
||||
boolean readOnly, ByteOrder endian)
|
||||
{
|
||||
super (capacity, limit, position, mark);
|
||||
this.bb = bb;
|
||||
this.offset = offset;
|
||||
this.readOnly = readOnly;
|
||||
this.endian = endian;
|
||||
if (bb.isDirect())
|
||||
this.address = VMDirectByteBuffer.adjustAddress(bb.address, offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the <code>short</code> at this buffer's current position,
|
||||
* and then increments the position.
|
||||
*
|
||||
* @exception BufferUnderflowException If there are no remaining
|
||||
* <code>short</code>s in this buffer.
|
||||
*/
|
||||
public short get ()
|
||||
{
|
||||
int p = position();
|
||||
short result = ByteBufferHelper.getShort(bb, (p << 1) + offset, endian);
|
||||
position(p + 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolute get method. Reads the <code>short</code> at position
|
||||
* <code>index</code>.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If index is negative or not smaller
|
||||
* than the buffer's limit.
|
||||
*/
|
||||
public short get (int index)
|
||||
{
|
||||
return ByteBufferHelper.getShort(bb, (index << 1) + offset, endian);
|
||||
}
|
||||
|
||||
public ShortBuffer put (short value)
|
||||
{
|
||||
int p = position();
|
||||
ByteBufferHelper.putShort(bb, (p << 1) + offset, value, endian);
|
||||
position(p + 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ShortBuffer put (int index, short value)
|
||||
{
|
||||
ByteBufferHelper.putShort(bb, (index << 1) + offset, value, endian);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ShortBuffer compact ()
|
||||
{
|
||||
if (position () > 0)
|
||||
{
|
||||
int count = limit () - position ();
|
||||
bb.shiftDown(offset, offset + 2 * position(), 2 * count);
|
||||
position (count);
|
||||
limit (capacity ());
|
||||
}
|
||||
else
|
||||
{
|
||||
position(limit());
|
||||
limit(capacity());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ShortBuffer slice ()
|
||||
{
|
||||
// Create a sliced copy of this object that shares its content.
|
||||
return new ShortViewBufferImpl (bb, (position () >> 1) + offset,
|
||||
remaining(), remaining(), 0, -1,
|
||||
readOnly, endian);
|
||||
}
|
||||
|
||||
ShortBuffer duplicate (boolean readOnly)
|
||||
{
|
||||
int pos = position();
|
||||
reset();
|
||||
int mark = position();
|
||||
position(pos);
|
||||
return new ShortViewBufferImpl (bb, offset, capacity(), limit(),
|
||||
pos, mark, readOnly, endian);
|
||||
}
|
||||
|
||||
public ShortBuffer duplicate ()
|
||||
{
|
||||
return duplicate(readOnly);
|
||||
}
|
||||
|
||||
public ShortBuffer asReadOnlyBuffer ()
|
||||
{
|
||||
return duplicate(true);
|
||||
}
|
||||
|
||||
public boolean isReadOnly ()
|
||||
{
|
||||
return readOnly;
|
||||
}
|
||||
|
||||
public boolean isDirect ()
|
||||
{
|
||||
return bb.isDirect ();
|
||||
}
|
||||
|
||||
public ByteOrder order ()
|
||||
{
|
||||
return endian;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/* AlreadyConnectedException.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
public class AlreadyConnectedException extends IllegalStateException
|
||||
{
|
||||
/**
|
||||
* Creates the exception
|
||||
*/
|
||||
public AlreadyConnectedException()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/* AsynchronousCloseException.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public class AsynchronousCloseException extends ClosedChannelException
|
||||
{
|
||||
/**
|
||||
* Creates the exception
|
||||
*/
|
||||
public AsynchronousCloseException()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/* ByteChannel.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
public interface ByteChannel extends ReadableByteChannel,
|
||||
WritableByteChannel
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/* CancelledKeyException.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public class CancelledKeyException extends IllegalStateException
|
||||
{
|
||||
/**
|
||||
* Creates the exception
|
||||
*/
|
||||
public CancelledKeyException()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/* Channel.java --
|
||||
Copyright (C) 2002, 2004, 2005 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.channels;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface Channel
|
||||
{
|
||||
/**
|
||||
* Tells whether this channel is open or not
|
||||
*
|
||||
* @return <code>true</code>if channel is open,
|
||||
* <code>false</code> otherwise
|
||||
*/
|
||||
boolean isOpen();
|
||||
|
||||
/**
|
||||
* Closes this channel
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
*/
|
||||
void close() throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
/* Channels.java --
|
||||
Copyright (C) 2002, 2003, 2004, 2005 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.channels;
|
||||
|
||||
import gnu.java.nio.ChannelReader;
|
||||
import gnu.java.nio.InputStreamChannel;
|
||||
import gnu.java.nio.OutputStreamChannel;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.CharsetDecoder;
|
||||
import java.nio.charset.CharsetEncoder;
|
||||
|
||||
|
||||
/**
|
||||
* @since 1.4
|
||||
*/
|
||||
public final class Channels
|
||||
{
|
||||
/**
|
||||
* This class isn't intended to be instantiated.
|
||||
*/
|
||||
private Channels()
|
||||
{
|
||||
// Do nothing here.
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a stream that reads bytes from the given channel.
|
||||
*/
|
||||
public static InputStream newInputStream(ReadableByteChannel ch)
|
||||
{
|
||||
return VMChannels.newInputStream(ch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a stream that writes bytes to the given channel.
|
||||
*/
|
||||
public static OutputStream newOutputStream(WritableByteChannel ch)
|
||||
{
|
||||
return VMChannels.newOutputStream(ch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a channel that reads bytes from the given stream.
|
||||
*/
|
||||
public static ReadableByteChannel newChannel(InputStream in)
|
||||
{
|
||||
return new InputStreamChannel(in);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a channel that writes bytes to the given stream.
|
||||
*/
|
||||
public static WritableByteChannel newChannel(OutputStream out)
|
||||
{
|
||||
return new OutputStreamChannel(out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a reader that decodes bytes from the given channel using the
|
||||
* given decoder.
|
||||
*/
|
||||
public static Reader newReader(ReadableByteChannel ch, CharsetDecoder dec,
|
||||
int minBufferCap)
|
||||
{
|
||||
return new ChannelReader(ch, dec, minBufferCap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a reader that decodes bytes from the given channel according to
|
||||
* the named charset.
|
||||
*
|
||||
* @exception UnsupportedCharsetException If no support for the named charset
|
||||
* is available in this instance of the Java virtual machine.
|
||||
*/
|
||||
public static Reader newReader(ReadableByteChannel ch, String csName)
|
||||
{
|
||||
return newReader(ch, Charset.forName(csName).newDecoder(), -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a writer that encodes characters using the given encoder and
|
||||
* writes the resulting bytes to the given channel.
|
||||
*/
|
||||
public static Writer newWriter(WritableByteChannel ch, CharsetEncoder enc,
|
||||
int minBufferCap)
|
||||
{
|
||||
// FIXME: implement java.nio.channels.Channel.newWriter(WritableByteChannel, CharsetEncoder, int)
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a writer that encodes characters according to the named charset
|
||||
* and writes the resulting bytes to the given channel.
|
||||
*
|
||||
* @exception UnsupportedCharsetException If no support for the named charset
|
||||
* is available in this instance of the Java virtual machine.
|
||||
*/
|
||||
public static Writer newWriter(WritableByteChannel ch, String csName)
|
||||
{
|
||||
return newWriter(ch, Charset.forName(csName).newEncoder(), -1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/* ClosedByInterruptException.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public class ClosedByInterruptException extends AsynchronousCloseException
|
||||
{
|
||||
/**
|
||||
* Creates the exception
|
||||
*/
|
||||
public ClosedByInterruptException()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/* ClosedChannelException.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public class ClosedChannelException extends IOException
|
||||
{
|
||||
/**
|
||||
* Creates the exception
|
||||
*/
|
||||
public ClosedChannelException()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/* ClosedSelectorException.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public class ClosedSelectorException extends IllegalStateException
|
||||
{
|
||||
/**
|
||||
* Creates the exception
|
||||
*/
|
||||
public ClosedSelectorException()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/* ConnectionPendingException.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public class ConnectionPendingException extends IllegalStateException
|
||||
{
|
||||
/**
|
||||
* Creates the exception
|
||||
*/
|
||||
public ConnectionPendingException()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
/* DatagramChannel.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.spi.AbstractSelectableChannel;
|
||||
import java.nio.channels.spi.SelectorProvider;
|
||||
|
||||
|
||||
/**
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class DatagramChannel extends AbstractSelectableChannel
|
||||
implements ByteChannel, ScatteringByteChannel, GatheringByteChannel
|
||||
{
|
||||
/**
|
||||
* Initializes the channel.
|
||||
*/
|
||||
protected DatagramChannel(SelectorProvider provider)
|
||||
{
|
||||
super(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a datagram channel.
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
*/
|
||||
public static DatagramChannel open() throws IOException
|
||||
{
|
||||
return SelectorProvider.provider().openDatagramChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads data from this channel.
|
||||
*/
|
||||
public final long read(ByteBuffer[] dsts) throws IOException
|
||||
{
|
||||
long b = 0;
|
||||
|
||||
for (int i = 0; i < dsts.length; i++)
|
||||
b += read(dsts[i]);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes data to this channel.
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
* @exception NotYetConnectedException The channel's socket is not connected.
|
||||
*/
|
||||
public final long write(ByteBuffer[] srcs) throws IOException
|
||||
{
|
||||
long b = 0;
|
||||
|
||||
for (int i = 0; i < srcs.length; i++)
|
||||
b += write(srcs[i]);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects this channel's socket.
|
||||
*
|
||||
* @exception AsynchronousCloseException If another thread closes this channel
|
||||
* while the connect operation is in progress.
|
||||
* @exception ClosedByInterruptException If another thread interrupts the
|
||||
* current thread while the read operation is in progress, thereby closing the
|
||||
* channel and setting the current thread's interrupt status.
|
||||
* @exception ClosedChannelException If this channel is closed.
|
||||
* @exception IOException If an error occurs.
|
||||
* @exception SecurityException If a security manager has been installed and
|
||||
* it does not permit datagrams to be sent to the given address.
|
||||
*/
|
||||
public abstract DatagramChannel connect(SocketAddress remote)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Disonnects this channel's socket.
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
*/
|
||||
public abstract DatagramChannel disconnect() throws IOException;
|
||||
|
||||
/**
|
||||
* Tells whether or not this channel's socket is connected.
|
||||
*
|
||||
* @exception IOException If an error occurs.
|
||||
* @exception NotYetConnectedException The channel's socket is not connected.
|
||||
*/
|
||||
public abstract boolean isConnected();
|
||||
|
||||
/**
|
||||
* Reads data from this channel.
|
||||
*/
|
||||
public abstract int read(ByteBuffer dst) throws IOException;
|
||||
|
||||
/**
|
||||
* Reads data from this channel.
|
||||
*
|
||||
* @exception IOException If an error occurs.
|
||||
* @exception NotYetConnectedException The channel's socket is not connected.
|
||||
*/
|
||||
public abstract long read(ByteBuffer[] dsts, int offset, int length)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Receives a datagram via this channel.
|
||||
*
|
||||
* @exception AsynchronousCloseException If another thread closes this channel
|
||||
* while the connect operation is in progress.
|
||||
* @exception ClosedByInterruptException If another thread interrupts the
|
||||
* current thread while the read operation is in progress, thereby closing the
|
||||
* channel and setting the current thread's interrupt status.
|
||||
* @exception ClosedChannelException If this channel is closed.
|
||||
* @exception IOException If an error occurs
|
||||
* @exception SecurityException If a security manager has been installed and
|
||||
* it does not permit datagrams to be sent to the given address.
|
||||
*/
|
||||
public abstract SocketAddress receive(ByteBuffer dst)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Sends a datagram via this channel.
|
||||
*
|
||||
* @exception AsynchronousCloseException If another thread closes this channel
|
||||
* while the connect operation is in progress.
|
||||
* @exception ClosedByInterruptException If another thread interrupts the
|
||||
* current thread while the read operation is in progress, thereby closing the
|
||||
* channel and setting the current thread's interrupt status.
|
||||
* @exception ClosedChannelException If this channel is closed.
|
||||
* @exception IOException If an error occurs
|
||||
* @exception SecurityException If a security manager has been installed and
|
||||
* it does not permit datagrams to be sent to the given address.
|
||||
*/
|
||||
public abstract int send(ByteBuffer src, SocketAddress target)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Retrieves the channel's socket.
|
||||
*/
|
||||
public abstract DatagramSocket socket();
|
||||
|
||||
/**
|
||||
* Writes data to this channel.
|
||||
*
|
||||
* @exception IOException If an error occurs.
|
||||
* @exception NotYetConnectedException The channel's socket is not connected.
|
||||
*/
|
||||
public abstract int write(ByteBuffer src) throws IOException;
|
||||
|
||||
/**
|
||||
* Writes data to this channel.
|
||||
*
|
||||
* @exception IOException If an error occurs.
|
||||
* @exception NotYetConnectedException The channel's socket is not connected.
|
||||
*/
|
||||
public abstract long write(ByteBuffer[] srcs, int offset, int length)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Retrieves the valid operations for this channel.
|
||||
*
|
||||
* @exception IOException If an error occurs.
|
||||
* @exception NotYetConnectedException The channel's socket is not connected.
|
||||
*/
|
||||
public final int validOps()
|
||||
{
|
||||
return SelectionKey.OP_READ | SelectionKey.OP_WRITE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,367 @@
|
||||
/* FileChannel.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.MappedByteBuffer;
|
||||
import java.nio.channels.spi.AbstractInterruptibleChannel;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class FileChannel extends AbstractInterruptibleChannel
|
||||
implements ByteChannel, GatheringByteChannel, ScatteringByteChannel
|
||||
{
|
||||
public static class MapMode
|
||||
{
|
||||
int m;
|
||||
public static final MapMode READ_ONLY = new MapMode(0);
|
||||
public static final MapMode READ_WRITE = new MapMode(1);
|
||||
public static final MapMode PRIVATE = new MapMode(2);
|
||||
|
||||
/**
|
||||
* Initializes the MapMode.
|
||||
*/
|
||||
MapMode(int a)
|
||||
{
|
||||
m = a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the <code>MapMode</code> object.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
if (this == READ_ONLY)
|
||||
return "READ_ONLY";
|
||||
else if (this == READ_WRITE)
|
||||
return "READ_WRITE";
|
||||
|
||||
return "PRIVATE";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the channel.
|
||||
*/
|
||||
protected FileChannel()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps the file into the memory.
|
||||
*
|
||||
* @exception IllegalArgumentException If the preconditions on the parameters
|
||||
* do not hold.
|
||||
* @exception IOException If an I/O error occurs.
|
||||
* @exception NonReadableChannelException If mode is READ_ONLY but this channel was
|
||||
* not opened for reading.
|
||||
* @exception NonWritableChannelException If mode is READ_WRITE or PRIVATE but this
|
||||
* channel was not opened for writing.
|
||||
*/
|
||||
public abstract MappedByteBuffer map(MapMode mode, long position, long size)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Return the size of the file thus far
|
||||
*
|
||||
* @exception ClosedChannelException If this channel is closed.
|
||||
*/
|
||||
public abstract long size() throws IOException;
|
||||
|
||||
/**
|
||||
* Writes data to the channel.
|
||||
*
|
||||
* @exception IOException If an I/O error occurs.
|
||||
*/
|
||||
public final long write(ByteBuffer[] srcs) throws IOException
|
||||
{
|
||||
long result = 0;
|
||||
|
||||
for (int i = 0; i < srcs.length; i++)
|
||||
result += write(srcs[i]);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes data to the channel.
|
||||
*
|
||||
* @exception IOException If an I/O error occurs.
|
||||
*/
|
||||
public abstract int write(ByteBuffer src) throws IOException;
|
||||
|
||||
/**
|
||||
* Writes data to the channel.
|
||||
*
|
||||
* @exception AsynchronousCloseException If another thread closes this channel
|
||||
* while the transfer is in progress.
|
||||
* @exception ClosedByInterruptException If another thread interrupts the
|
||||
* current thread while the transfer is in progress, thereby closing both
|
||||
* channels and setting the current thread's interrupt status.
|
||||
* @exception ClosedChannelException If this channel is closed.
|
||||
* @exception IllegalArgumentException If position is negative.
|
||||
* @exception IOException If an I/O error occurs.
|
||||
* @exception NonWritableChannelException If this channel was not opened for
|
||||
* writing.
|
||||
*/
|
||||
public abstract int write(ByteBuffer srcs, long position)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Writes data to the channel.
|
||||
*
|
||||
* @exception IOException If an I/O error occurs.
|
||||
*/
|
||||
public abstract long write(ByteBuffer[] srcs, int offset, int length)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Reads data from the channel.
|
||||
*
|
||||
* @exception IOException If an I/O error occurs.
|
||||
*/
|
||||
public abstract long read(ByteBuffer[] dsts, int offset, int length)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Reads data from the channel.
|
||||
*
|
||||
* @exception IOException If an I/O error occurs.
|
||||
*/
|
||||
public final long read(ByteBuffer[] dsts) throws IOException
|
||||
{
|
||||
long result = 0;
|
||||
|
||||
for (int i = 0; i < dsts.length; i++)
|
||||
read(dsts[i]);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads data from the channel.
|
||||
*
|
||||
* @exception IOException If an I/O error occurs.
|
||||
*/
|
||||
public abstract int read(ByteBuffer dst) throws IOException;
|
||||
|
||||
/**
|
||||
* Reads data from the channel.
|
||||
*
|
||||
* @exception AsynchronousCloseException If another thread closes this channel
|
||||
* while the transfer is in progress.
|
||||
* @exception ClosedByInterruptException If another thread interrupts the
|
||||
* current thread while the transfer is in progress, thereby closing both
|
||||
* channels and setting the current thread's interrupt status.
|
||||
* @exception ClosedChannelException If this channel is closed.
|
||||
* @exception IllegalArgumentException If position is negative.
|
||||
* @exception IOException If an I/O error occurs.
|
||||
* @exception NonReadableChannelException If this channel was not opened for
|
||||
* reading.
|
||||
*/
|
||||
public abstract int read(ByteBuffer dst, long position)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Closes the channel.
|
||||
*
|
||||
* This is called from @see close.
|
||||
*
|
||||
* @exception IOException If an I/O error occurs.
|
||||
*/
|
||||
protected abstract void implCloseChannel() throws IOException;
|
||||
|
||||
/**
|
||||
* msync with the disk
|
||||
*
|
||||
* @exception ClosedChannelException If this channel is closed.
|
||||
* @exception IOException If an I/O error occurs.
|
||||
*/
|
||||
public abstract void force(boolean metaData) throws IOException;
|
||||
|
||||
/**
|
||||
* Creates a file lock for the whole assoziated file.
|
||||
*
|
||||
* @exception AsynchronousCloseException If another thread closes this channel
|
||||
* while the transfer is in progress.
|
||||
* @exception ClosedChannelException If this channel is closed.
|
||||
* @exception FileLockInterruptionException If the invoking thread is
|
||||
* interrupted while blocked in this method.
|
||||
* @exception IOException If an I/O error occurs.
|
||||
* @exception NonReadableChannelException If shared is true and this channel
|
||||
* was not opened for reading.
|
||||
* @exception NonWritableChannelException If shared is false and this channel
|
||||
* was not opened for writing.
|
||||
* @exception OverlappingFileLockException If a lock that overlaps the
|
||||
* requested region is already held by this Java virtual machine, or if
|
||||
* another thread is already blocked in this method and is attempting to lock
|
||||
* an overlapping region.
|
||||
*/
|
||||
public final FileLock lock() throws IOException
|
||||
{
|
||||
return lock(0, Long.MAX_VALUE, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a file lock for a region of the assoziated file.
|
||||
*
|
||||
* @exception AsynchronousCloseException If another thread closes this channel
|
||||
* while the transfer is in progress.
|
||||
* @exception ClosedChannelException If this channel is closed.
|
||||
* @exception FileLockInterruptionException If the invoking thread is
|
||||
* interrupted while blocked in this method.
|
||||
* @exception IllegalArgumentException If the preconditions on the parameters
|
||||
* do not hold.
|
||||
* @exception IOException If an I/O error occurs.
|
||||
* @exception OverlappingFileLockException If a lock that overlaps the
|
||||
* requested region is already held by this Java virtual machine, or if
|
||||
* another thread is already blocked in this method and is attempting to lock
|
||||
* an overlapping region.
|
||||
* @exception NonReadableChannelException If shared is true and this channel
|
||||
* was not opened for reading.
|
||||
* @exception NonWritableChannelException If shared is false and this channel
|
||||
* was not opened for writing.
|
||||
*/
|
||||
public abstract FileLock lock(long position, long size, boolean shared)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Tries to aqquire alock on the whole assoziated file.
|
||||
*
|
||||
* @exception ClosedChannelException If this channel is closed.
|
||||
* @exception IOException If an I/O error occurs.
|
||||
* @exception OverlappingFileLockException If a lock that overlaps the
|
||||
* requested region is already held by this Java virtual machine, or if
|
||||
* another thread is already blocked in this method and is attempting to lock
|
||||
* an overlapping region.
|
||||
*/
|
||||
public final FileLock tryLock() throws IOException
|
||||
{
|
||||
return tryLock(0, Long.MAX_VALUE, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to aqquire a lock on a region of the assoziated file.
|
||||
*
|
||||
* @exception ClosedChannelException If this channel is closed.
|
||||
* @exception IllegalArgumentException If the preconditions on the parameters
|
||||
* do not hold.
|
||||
* @exception IOException If an I/O error occurs.
|
||||
* @exception OverlappingFileLockException If a lock that overlaps the
|
||||
* requested region is already held by this Java virtual machine, or if
|
||||
* another thread is already blocked in this method and is attempting to lock
|
||||
* an overlapping region.
|
||||
*/
|
||||
public abstract FileLock tryLock(long position, long size, boolean shared)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the current position on the file.
|
||||
*
|
||||
* @exception ClosedChannelException If this channel is closed.
|
||||
* @exception IOException If an I/O error occurs.
|
||||
*/
|
||||
public abstract long position() throws IOException;
|
||||
|
||||
/**
|
||||
* Sets the position of the channel on the assoziated file.
|
||||
*
|
||||
* @exception ClosedChannelException If this channel is closed.
|
||||
* @exception IllegalArgumentException If newPosition is negative.
|
||||
* @exception IOException If an I/O error occurs.
|
||||
*/
|
||||
public abstract FileChannel position(long newPosition)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Transfers bytes from this channel's file to the given writable byte
|
||||
* channel.
|
||||
*
|
||||
* @exception AsynchronousCloseException If another thread closes this channel
|
||||
* while the transfer is in progress.
|
||||
* @exception ClosedByInterruptException If another thread interrupts the
|
||||
* current thread while the transfer is in progress, thereby closing both
|
||||
* channels and setting the current thread's interrupt status.
|
||||
* @exception ClosedChannelException If this channel is closed.
|
||||
* @exception IllegalArgumentException If the preconditions on the parameters
|
||||
* do not hold.
|
||||
* @exception IOException If an I/O error occurs.
|
||||
* @exception NonReadableChannelException If this channel was not opened for
|
||||
* reading.
|
||||
* @exception NonWritableChannelException If the target channel was not
|
||||
* opened for writing.
|
||||
*/
|
||||
public abstract long transferTo(long position, long count,
|
||||
WritableByteChannel target)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Transfers bytes from the given readable channel into this channel.
|
||||
*
|
||||
* @exception AsynchronousCloseException If another thread closes this channel
|
||||
* while the transfer is in progress.
|
||||
* @exception ClosedByInterruptException If another thread interrupts the
|
||||
* current thread while the transfer is in progress, thereby closing both
|
||||
* channels and setting the current thread's interrupt status.
|
||||
* @exception ClosedChannelException If this channel is closed.
|
||||
* @exception IllegalArgumentException If the preconditions on the parameters
|
||||
* do not hold.
|
||||
* @exception IOException If an I/O error occurs.
|
||||
* @exception NonReadableChannelException If the source channel was not
|
||||
* opened for reading.
|
||||
* @exception NonWritableChannelException If this channel was not opened for
|
||||
* writing.
|
||||
*/
|
||||
public abstract long transferFrom(ReadableByteChannel src, long position,
|
||||
long count) throws IOException;
|
||||
|
||||
/**
|
||||
* Truncates the channel's file at <code>size</code>.
|
||||
*
|
||||
* @exception ClosedChannelException If this channel is closed.
|
||||
* @exception IllegalArgumentException If size is negative.
|
||||
* @exception IOException If an I/O error occurs.
|
||||
* @exception NonWritableChannelException If this channel was not opened for
|
||||
* writing.
|
||||
*/
|
||||
public abstract FileChannel truncate(long size) throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
/* FileLock.java --
|
||||
Copyright (C) 2002, 2005 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.channels;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/**
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class FileLock
|
||||
{
|
||||
FileChannel channel;
|
||||
long position;
|
||||
long size;
|
||||
boolean shared;
|
||||
|
||||
/**
|
||||
* Initializes the file lock.
|
||||
*
|
||||
* @exception IllegalArgumentException If the preconditions on the parameters do not hold
|
||||
*/
|
||||
protected FileLock(FileChannel channel, long position, long size,
|
||||
boolean shared)
|
||||
{
|
||||
if (position < 0 || size < 0)
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
this.channel = channel;
|
||||
this.position = position;
|
||||
this.size = size;
|
||||
this.shared = shared;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether or not this lock is valid.
|
||||
*/
|
||||
public abstract boolean isValid();
|
||||
|
||||
/**
|
||||
* Releases this lock.
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
* @exception ClosedChannelException If the locked channel is no longer open.
|
||||
*/
|
||||
public abstract void release() throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the file channel upon whose file this lock is held.
|
||||
*/
|
||||
public final FileChannel channel()
|
||||
{
|
||||
return channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether this lock is shared.
|
||||
*/
|
||||
public final boolean isShared()
|
||||
{
|
||||
return shared;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether or not this lock overlaps the given lock range.
|
||||
*/
|
||||
public final boolean overlaps(long position, long size)
|
||||
{
|
||||
if (position > this.position + this.size)
|
||||
return false;
|
||||
|
||||
if (position + size < this.position)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the position within the file of the first byte of the
|
||||
* locked region.
|
||||
*/
|
||||
public final long position()
|
||||
{
|
||||
return position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of the locked region in bytes.
|
||||
*/
|
||||
public final long size()
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string describing the range, type, and validity of this lock.
|
||||
*/
|
||||
public final String toString()
|
||||
{
|
||||
StringBuffer buf = new StringBuffer(getClass().getName());
|
||||
buf.append("[");
|
||||
buf.append(position);
|
||||
buf.append(":");
|
||||
buf.append(size);
|
||||
if (shared)
|
||||
buf.append(" shared");
|
||||
else
|
||||
buf.append(" exclusive");
|
||||
if (isValid())
|
||||
buf.append(" valid]");
|
||||
else
|
||||
buf.append(" invalid]");
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/* FileLockInterruptionException.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public class FileLockInterruptionException extends IOException
|
||||
{
|
||||
/**
|
||||
* Creates the exception
|
||||
*/
|
||||
public FileLockInterruptionException()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/* GatheringByteChannel.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
|
||||
public interface GatheringByteChannel extends WritableByteChannel
|
||||
{
|
||||
/**
|
||||
* Writes a sequence of bytes to this channel from a subsequence of
|
||||
* the given buffers
|
||||
*
|
||||
* @exception AsynchronousCloseException If another thread closes this
|
||||
* channel while the write operation is in progress
|
||||
* @exception ClosedByInterruptException If another thread interrupts the
|
||||
* current thread while the write operation is in progress, thereby closing
|
||||
* the channel and setting the current thread's interrupt status
|
||||
* @exception ClosedChannelException If this channel is closed
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold
|
||||
* @exception IOException If an error occurs
|
||||
* @exception NonWritableChannelException If this channel was not opened for
|
||||
* writing
|
||||
*/
|
||||
long write(ByteBuffer[] srcs, int offset, int length)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Writes a sequence of bytes to this channel from the given buffers
|
||||
*
|
||||
* @exception AsynchronousCloseException If another thread closes this
|
||||
* channel while the write operation is in progress
|
||||
* @exception ClosedByInterruptException If another thread interrupts the
|
||||
* current thread while the write operation is in progress, thereby closing
|
||||
* the channel and setting the current thread's interrupt status
|
||||
* @exception ClosedChannelException If this channel is closed
|
||||
* @exception IOException If an error occurs
|
||||
* @exception NonWritableChannelException If this channel was not opened for
|
||||
* writing
|
||||
*/
|
||||
long write(ByteBuffer[] srcs) throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/* IllegalBlockingModeException.java --
|
||||
Copyright (C) 2002, 2005 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.channels;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch (konqueror@gmx.de)
|
||||
* @since 1.4
|
||||
*
|
||||
* Written using JDK 1.4.1 Online API from Sun
|
||||
* Status: JDK 1.4 complete
|
||||
*/
|
||||
public class IllegalBlockingModeException extends IllegalStateException
|
||||
{
|
||||
/**
|
||||
* Creates the exception
|
||||
*/
|
||||
public IllegalBlockingModeException()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/* IllegalSelectorException.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public class IllegalSelectorException extends IllegalArgumentException
|
||||
{
|
||||
/**
|
||||
* Creates the exception
|
||||
*/
|
||||
public IllegalSelectorException()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/* InterruptibleChannel.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public interface InterruptibleChannel extends Channel
|
||||
{
|
||||
/**
|
||||
* Closes this channel
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
*/
|
||||
void close() throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/* NoConnectionPendingException.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public class NoConnectionPendingException extends IllegalStateException
|
||||
{
|
||||
/**
|
||||
* Creates the exception
|
||||
*/
|
||||
public NoConnectionPendingException()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/* NonReadableChannelException.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public class NonReadableChannelException extends IllegalStateException
|
||||
{
|
||||
/**
|
||||
* Creates the exception
|
||||
*/
|
||||
public NonReadableChannelException()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/* NonWritableChannelException.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public class NonWritableChannelException extends IllegalStateException
|
||||
{
|
||||
/**
|
||||
* Creates the exception
|
||||
*/
|
||||
public NonWritableChannelException()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/* NotYetBoundException.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public class NotYetBoundException extends IllegalStateException
|
||||
{
|
||||
/**
|
||||
* Creates the exception
|
||||
*/
|
||||
public NotYetBoundException()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/* NotYetConnectedException.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public class NotYetConnectedException extends IllegalStateException
|
||||
{
|
||||
/**
|
||||
* Creates the exception
|
||||
*/
|
||||
public NotYetConnectedException()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/* OverlappingFileLockException.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public class OverlappingFileLockException extends IllegalStateException
|
||||
{
|
||||
/**
|
||||
* Creates the exception
|
||||
*/
|
||||
public OverlappingFileLockException()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/* Pipe.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.spi.AbstractSelectableChannel;
|
||||
import java.nio.channels.spi.SelectorProvider;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class Pipe
|
||||
{
|
||||
public abstract static class SinkChannel extends AbstractSelectableChannel
|
||||
implements WritableByteChannel, GatheringByteChannel
|
||||
{
|
||||
/**
|
||||
* Initializes the channel.
|
||||
*/
|
||||
protected SinkChannel(SelectorProvider provider)
|
||||
{
|
||||
super(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an operation set that is valid on this channel.
|
||||
*
|
||||
* The only valid operation on this channel is @see SelectionKey.OP_WRITE.
|
||||
*/
|
||||
public final int validOps()
|
||||
{
|
||||
return SelectionKey.OP_WRITE;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract static class SourceChannel extends AbstractSelectableChannel
|
||||
implements ReadableByteChannel, ScatteringByteChannel
|
||||
{
|
||||
/**
|
||||
* Initializes the channel.
|
||||
*/
|
||||
protected SourceChannel(SelectorProvider provider)
|
||||
{
|
||||
super(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an operation set that is valid on this channel.
|
||||
*
|
||||
* The only valid operation on this channel is @see SelectionKey.OP_READ.
|
||||
*/
|
||||
public final int validOps()
|
||||
{
|
||||
return SelectionKey.OP_READ;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the pipe.
|
||||
*/
|
||||
protected Pipe()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a pipe.
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
*/
|
||||
public static Pipe open() throws IOException
|
||||
{
|
||||
return SelectorProvider.provider().openPipe();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a pipe's sink channel.
|
||||
*/
|
||||
public abstract Pipe.SinkChannel sink();
|
||||
|
||||
/**
|
||||
* Returns a pipe's source channel
|
||||
*/
|
||||
public abstract Pipe.SourceChannel source();
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/* ReadableByteChannel.java --
|
||||
Copyright (C) 2002, 2004 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.channels;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
|
||||
public interface ReadableByteChannel extends Channel
|
||||
{
|
||||
/**
|
||||
* Reads a sequence of bytes from this channel into the given buffer
|
||||
*
|
||||
* @param dst the buffer to put the read data into
|
||||
*
|
||||
* @return the numer of bytes read
|
||||
*
|
||||
* @exception AsynchronousCloseException If another thread closes this
|
||||
* channel while the read operation is in progress
|
||||
* @exception ClosedByInterruptException If another thread interrupts the
|
||||
* current thread while the read operation is in progress, thereby closing
|
||||
* the channel and setting the current thread's interrupt status
|
||||
* @exception ClosedChannelException If this channel is closed
|
||||
* @exception IOException If an error occurs
|
||||
* @exception NonReadableChannelException If this channel was not opened for
|
||||
* reading
|
||||
*/
|
||||
int read(ByteBuffer dst) throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/* ScatteringByteChannel.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
|
||||
public interface ScatteringByteChannel extends ReadableByteChannel
|
||||
{
|
||||
/**
|
||||
* Reads a sequence of bytes from this channel into a subsequence of the
|
||||
* given buffers
|
||||
*
|
||||
* @exception AsynchronousCloseException If another thread closes this
|
||||
* channel while the write operation is in progress
|
||||
* @exception ClosedByInterruptException If another thread interrupts the
|
||||
* current thread while the write operation is in progress, thereby closing
|
||||
* the channel and setting the current thread's interrupt status
|
||||
* @exception ClosedChannelException If this channel is closed
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold
|
||||
* @exception IOException If an error occurs
|
||||
* @exception NonReadableChannelException If this channel was not opened for
|
||||
* reading
|
||||
*/
|
||||
long read(ByteBuffer[] srcs, int offset, int length)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Reads a sequence of bytes from this channel into the given buffers
|
||||
*
|
||||
* @exception AsynchronousCloseException If another thread closes this
|
||||
* channel while the write operation is in progress
|
||||
* @exception ClosedByInterruptException If another thread interrupts the
|
||||
* current thread while the write operation is in progress, thereby closing
|
||||
* the channel and setting the current thread's interrupt status
|
||||
* @exception ClosedChannelException If this channel is closed
|
||||
* @exception IOException If an error occurs
|
||||
* @exception NonReadableChannelException If this channel was not opened for
|
||||
* reading
|
||||
*/
|
||||
long read(ByteBuffer[] srcs) throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/* SelectableChannel.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.spi.AbstractInterruptibleChannel;
|
||||
import java.nio.channels.spi.SelectorProvider;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class SelectableChannel extends AbstractInterruptibleChannel
|
||||
{
|
||||
/**
|
||||
* Initializes the channel.
|
||||
*/
|
||||
protected SelectableChannel()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the lock of this channel.
|
||||
*/
|
||||
public abstract Object blockingLock();
|
||||
|
||||
/**
|
||||
* Adjusts this channel's blocking mode.
|
||||
*
|
||||
* @exception ClosedChannelException If this channel is closed.
|
||||
* @exception IllegalBlockingModeException If block is true and this channel
|
||||
* is registered with one or more selectors.
|
||||
* @exception IOException If an error occurs.
|
||||
*/
|
||||
public abstract SelectableChannel configureBlocking(boolean block)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Tells whether this channel is blocking or not.
|
||||
*/
|
||||
public abstract boolean isBlocking();
|
||||
|
||||
/**
|
||||
* Tells whether or not this channel is currently registered with
|
||||
* any selectors.
|
||||
*/
|
||||
public abstract boolean isRegistered();
|
||||
|
||||
/**
|
||||
* Retrieves the key representing the channel's registration with
|
||||
* the given selector.
|
||||
*/
|
||||
public abstract SelectionKey keyFor(Selector sel);
|
||||
|
||||
/**
|
||||
* Returns the provider that created this channel.
|
||||
*/
|
||||
public abstract SelectorProvider provider();
|
||||
|
||||
/**
|
||||
* Registers this channel with the given selector,
|
||||
* returning a selection key.
|
||||
*
|
||||
* @exception CancelledKeyException If this channel is currently registered
|
||||
* with the given selector but the corresponding key has already been cancelled
|
||||
* @exception ClosedChannelException If this channel is closed.
|
||||
* @exception IllegalArgumentException If a bit in ops does not correspond
|
||||
* to an operation that is supported by this channel, that is, if
|
||||
* set & ~validOps() != 0.
|
||||
* @exception IllegalBlockingModeException If block is true and this channel
|
||||
* is registered with one or more selectors.
|
||||
* @exception IllegalSelectorException If this channel was not created by
|
||||
* the same provider as the given selector.
|
||||
*/
|
||||
public final SelectionKey register(Selector sel, int ops)
|
||||
throws ClosedChannelException
|
||||
{
|
||||
return register(sel, ops, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers this channel with the given selector,
|
||||
* returning a selection key.
|
||||
*
|
||||
* @exception CancelledKeyException If this channel is currently registered
|
||||
* with the given selector but the corresponding key has already been
|
||||
* cancelled.
|
||||
* @exception ClosedChannelException If this channel is closed.
|
||||
* @exception IllegalArgumentException If a bit in ops does not correspond
|
||||
* to an operation that is supported by this channel, that is, if
|
||||
* set & ~validOps() != 0.
|
||||
* @exception IllegalBlockingModeException If block is true and this channel
|
||||
* is registered with one or more selectors.
|
||||
* @exception IllegalSelectorException If this channel was not created by
|
||||
* the same provider as the given selector.
|
||||
*/
|
||||
public abstract SelectionKey register(Selector sel, int ops, Object att)
|
||||
throws ClosedChannelException;
|
||||
|
||||
/**
|
||||
* Returns a set of valid operations on this channel.
|
||||
*/
|
||||
public abstract int validOps();
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
/* SelectionKey.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class SelectionKey
|
||||
{
|
||||
public static final int OP_ACCEPT = 16;
|
||||
public static final int OP_CONNECT = 8;
|
||||
public static final int OP_READ = 1;
|
||||
public static final int OP_WRITE = 4;
|
||||
Object attached;
|
||||
|
||||
/**
|
||||
* Initializes the selection key.
|
||||
*/
|
||||
protected SelectionKey()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Attaches obj to the key and returns the old attached object.
|
||||
*/
|
||||
public final Object attach(Object obj)
|
||||
{
|
||||
Object old = attached;
|
||||
attached = obj;
|
||||
return old;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object attached to the key.
|
||||
*/
|
||||
public final Object attachment()
|
||||
{
|
||||
return attached;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if the channel attached to this key is ready to accept
|
||||
* a new socket connection.
|
||||
*
|
||||
* @exception CancelledKeyException If this key has been cancelled
|
||||
*/
|
||||
public final boolean isAcceptable()
|
||||
{
|
||||
return (readyOps() & OP_ACCEPT) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether this key's channel has either finished,
|
||||
* or failed to finish, its socket-connection operation.
|
||||
*
|
||||
* @exception CancelledKeyException If this key has been cancelled
|
||||
*/
|
||||
public final boolean isConnectable()
|
||||
{
|
||||
return (readyOps() & OP_CONNECT) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if the channel attached to the key is readable.
|
||||
*
|
||||
* @exception CancelledKeyException If this key has been cancelled
|
||||
*/
|
||||
public final boolean isReadable()
|
||||
{
|
||||
return (readyOps() & OP_READ) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if the channel attached to the key is writable.
|
||||
*
|
||||
* @exception CancelledKeyException If this key has been cancelled
|
||||
*/
|
||||
public final boolean isWritable()
|
||||
{
|
||||
return (readyOps() & OP_WRITE) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the registration of this key's channel with
|
||||
* its selector be cancelled.
|
||||
*/
|
||||
public abstract void cancel();
|
||||
|
||||
/**
|
||||
* return the channel attached to the key.
|
||||
*/
|
||||
public abstract SelectableChannel channel();
|
||||
|
||||
/**
|
||||
* Returns the key's interest set.
|
||||
*
|
||||
* @exception CancelledKeyException If this key has been cancelled
|
||||
*/
|
||||
public abstract int interestOps();
|
||||
|
||||
/**
|
||||
* Sets this key's interest set to the given value.
|
||||
*
|
||||
* @exception CancelledKeyException If this key has been cancelled
|
||||
* @exception IllegalArgumentException If a bit in the set does not
|
||||
* correspond to an operation that is supported by this key's channel,
|
||||
* that is, if set & ~(channel().validOps()) != 0
|
||||
*/
|
||||
public abstract SelectionKey interestOps(int ops);
|
||||
|
||||
/**
|
||||
* Tells whether or not this key is valid.
|
||||
*/
|
||||
public abstract boolean isValid();
|
||||
|
||||
/**
|
||||
* Retrieves this key's ready-operation set.
|
||||
*
|
||||
* @exception CancelledKeyException If this key has been cancelled
|
||||
*/
|
||||
public abstract int readyOps();
|
||||
|
||||
/**
|
||||
* Returns the selector for which this key was created.
|
||||
*/
|
||||
public abstract Selector selector();
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
/* Selector.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.spi.SelectorProvider;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class Selector
|
||||
{
|
||||
/**
|
||||
* Initializes the selector.
|
||||
*/
|
||||
protected Selector()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a selector.
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
*/
|
||||
public static Selector open() throws IOException
|
||||
{
|
||||
return SelectorProvider.provider().openSelector();
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the selector.
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
*/
|
||||
public abstract void close() throws IOException;
|
||||
|
||||
/**
|
||||
* Tells whether the selector is open or not.
|
||||
*/
|
||||
public abstract boolean isOpen();
|
||||
|
||||
/**
|
||||
* Returns this selector's key set.
|
||||
*
|
||||
* @exception ClosedSelectorException If this selector is closed.
|
||||
*/
|
||||
public abstract Set keys();
|
||||
|
||||
/**
|
||||
* Returns the SelectorProvider that created the selector.
|
||||
*/
|
||||
public abstract SelectorProvider provider();
|
||||
|
||||
/**
|
||||
* Selects a set of keys whose corresponding channels are ready
|
||||
* for I/O operations.
|
||||
*
|
||||
* @exception ClosedSelectorException If this selector is closed.
|
||||
* @exception IOException If an error occurs
|
||||
*/
|
||||
public abstract int select() throws IOException;
|
||||
|
||||
/**
|
||||
* Selects a set of keys whose corresponding channels are ready
|
||||
* for I/O operations.
|
||||
*
|
||||
* @param timeout The timeout to use.
|
||||
*
|
||||
* @exception ClosedSelectorException If this selector is closed.
|
||||
* @exception IllegalArgumentException If the timeout value is negative.
|
||||
* @exception IOException If an error occurs
|
||||
*/
|
||||
public abstract int select(long timeout) throws IOException;
|
||||
|
||||
/**
|
||||
* Returns this selector's selected-key set.
|
||||
*
|
||||
* @exception ClosedSelectorException If this selector is closed.
|
||||
*/
|
||||
public abstract Set selectedKeys();
|
||||
|
||||
/**
|
||||
* Selects a set of keys whose corresponding channels are ready
|
||||
* for I/O operations.
|
||||
*
|
||||
* @exception ClosedSelectorException If this selector is closed.
|
||||
* @exception IOException If an error occurs
|
||||
*/
|
||||
public abstract int selectNow() throws IOException;
|
||||
|
||||
/**
|
||||
* Causes the first selection operation that has not yet returned to
|
||||
* return immediately.
|
||||
*/
|
||||
public abstract Selector wakeup();
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/* ServerSocketChannel.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.nio.channels.spi.AbstractSelectableChannel;
|
||||
import java.nio.channels.spi.SelectorProvider;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class ServerSocketChannel extends AbstractSelectableChannel
|
||||
{
|
||||
/**
|
||||
* Initializes this channel.
|
||||
*/
|
||||
protected ServerSocketChannel(SelectorProvider provider)
|
||||
{
|
||||
super(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a connection made to this channel's socket.
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
* @exception AsynchronousCloseException If another thread closes this
|
||||
* channel while the accept operation is in progress.
|
||||
* @exception ClosedByInterruptException If another thread interrupts the
|
||||
* current thread while the accept operation is in progress, thereby closing
|
||||
* the channel and setting the current thread's interrupt status.
|
||||
* @exception ClosedChannelException If the channel is closed.
|
||||
* @exception NotYetBoundException If the channel's socket is not yet bound.
|
||||
* @exception SecurityException If a security manager has been installed and
|
||||
* it does not permit access to the remote endpoint of the new connection.
|
||||
*/
|
||||
public abstract SocketChannel accept() throws IOException;
|
||||
|
||||
/**
|
||||
* Retrieves the channels socket.
|
||||
*/
|
||||
public abstract ServerSocket socket();
|
||||
|
||||
/**
|
||||
* Opens a server socket channel.
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
*/
|
||||
public static ServerSocketChannel open() throws IOException
|
||||
{
|
||||
return SelectorProvider.provider().openServerSocketChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the valid operations for this channel.
|
||||
*/
|
||||
public final int validOps()
|
||||
{
|
||||
return SelectionKey.OP_ACCEPT;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
/* SocketChannel.java --
|
||||
Copyright (C) 2002, 2004 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.channels;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.spi.AbstractSelectableChannel;
|
||||
import java.nio.channels.spi.SelectorProvider;
|
||||
|
||||
/**
|
||||
* @author Michael Koch (konqueror@gmx.de)
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class SocketChannel extends AbstractSelectableChannel
|
||||
implements ByteChannel, ScatteringByteChannel, GatheringByteChannel
|
||||
{
|
||||
/**
|
||||
* Initializes this socket channel.
|
||||
*/
|
||||
protected SocketChannel(SelectorProvider provider)
|
||||
{
|
||||
super(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a socket channel.
|
||||
*
|
||||
* @return the new <code>SocketChannel</code> object
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
*/
|
||||
public static SocketChannel open() throws IOException
|
||||
{
|
||||
return SelectorProvider.provider().openSocketChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a channel and connects it to a remote address.
|
||||
*
|
||||
* @return the new <code>SocketChannel</code> object
|
||||
*
|
||||
* @exception AsynchronousCloseException If this channel is already connected.
|
||||
* @exception ClosedByInterruptException If another thread interrupts the
|
||||
* current thread while the connect operation is in progress, thereby closing
|
||||
* the channel and setting the current thread's interrupt status.
|
||||
* @exception IOException If an error occurs
|
||||
* @exception SecurityException If a security manager has been installed and
|
||||
* it does not permit access to the given remote endpoint.
|
||||
* @exception UnresolvedAddressException If the given remote address is not
|
||||
* fully resolved.
|
||||
* @exception UnsupportedAddressTypeException If the type of the given remote
|
||||
* address is not supported.
|
||||
*/
|
||||
public static SocketChannel open(SocketAddress remote)
|
||||
throws IOException
|
||||
{
|
||||
SocketChannel ch = open();
|
||||
ch.connect(remote);
|
||||
return ch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads data from the channel.
|
||||
*
|
||||
* @return the number of bytes read, zero is valid too, -1 if end of stream
|
||||
* is reached
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
* @exception NotYetConnectedException If this channel is not yet connected.
|
||||
*/
|
||||
public final long read(ByteBuffer[] dsts) throws IOException
|
||||
{
|
||||
long b = 0;
|
||||
|
||||
for (int i = 0; i < dsts.length; i++)
|
||||
b += read(dsts[i]);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes data to the channel.
|
||||
*
|
||||
* @return the number of bytes written, zero is valid too
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
* @exception NotYetConnectedException If this channel is not yet connected.
|
||||
*/
|
||||
public final long write(ByteBuffer[] dsts) throws IOException
|
||||
{
|
||||
long b = 0;
|
||||
|
||||
for (int i = 0; i < dsts.length; i++)
|
||||
b += write(dsts[i]);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the valid operations for this channel.
|
||||
*
|
||||
* @return the valid operations
|
||||
*/
|
||||
public final int validOps()
|
||||
{
|
||||
return SelectionKey.OP_CONNECT | SelectionKey.OP_READ
|
||||
| SelectionKey.OP_WRITE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads data from the channel.
|
||||
*
|
||||
* @return the number of bytes read, zero is valid too, -1 if end of stream
|
||||
* is reached
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
* @exception NotYetConnectedException If this channel is not yet connected.
|
||||
*/
|
||||
public abstract int read(ByteBuffer dst) throws IOException;
|
||||
|
||||
/**
|
||||
* Connects the channel's socket to the remote address.
|
||||
*
|
||||
* @return <code>true</code> if the channel got successfully connected,
|
||||
* <code>false</code> if the channel is in non-blocking mode and connection
|
||||
* operation is still in progress.
|
||||
*
|
||||
* @exception AlreadyConnectedException If this channel is already connected.
|
||||
* @exception AsynchronousCloseException If this channel is already connected.
|
||||
* @exception ClosedByInterruptException If another thread interrupts the
|
||||
* current thread while the connect operation is in progress, thereby closing
|
||||
* the channel and setting the current thread's interrupt status.
|
||||
* @exception ClosedChannelException If this channel is closed.
|
||||
* @exception ConnectionPendingException If a non-blocking connection
|
||||
* operation is already in progress on this channel.
|
||||
* @exception IOException If an error occurs
|
||||
* @exception SecurityException If a security manager has been installed and
|
||||
* it does not permit access to the given remote endpoint.
|
||||
* @exception UnresolvedAddressException If the given remote address is not
|
||||
* fully resolved.
|
||||
* @exception UnsupportedAddressTypeException If the type of the given remote
|
||||
* address is not supported.
|
||||
*/
|
||||
public abstract boolean connect(SocketAddress remote)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Finishes the process of connecting a socket channel.
|
||||
*
|
||||
* @exception AsynchronousCloseException If this channel is already connected.
|
||||
* @exception ClosedByInterruptException If another thread interrupts the
|
||||
* current thread while the connect operation is in progress, thereby closing
|
||||
* the channel and setting the current thread's interrupt status.
|
||||
* @exception ClosedChannelException If this channel is closed.
|
||||
* @exception IOException If an error occurs
|
||||
* @exception NoConnectionPendingException If this channel is not connected
|
||||
* and a connection operation has not been initiated.
|
||||
*/
|
||||
public abstract boolean finishConnect() throws IOException;
|
||||
|
||||
/**
|
||||
* Tells whether or not the channel's socket is connected.
|
||||
*/
|
||||
public abstract boolean isConnected();
|
||||
|
||||
/**
|
||||
* Tells whether or not a connection operation is in progress on this channel.
|
||||
*/
|
||||
public abstract boolean isConnectionPending();
|
||||
|
||||
/**
|
||||
* Reads data from the channel.
|
||||
*
|
||||
* @return the number of bytes read, zero is valid too, -1 if end of stream
|
||||
* is reached
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
* @exception NotYetConnectedException If this channel is not yet connected.
|
||||
*/
|
||||
public abstract long read(ByteBuffer[] dsts, int offset, int length)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Retrieves the channel's socket.
|
||||
*
|
||||
* @return the socket
|
||||
*/
|
||||
public abstract Socket socket();
|
||||
|
||||
/**
|
||||
* Writes data to the channel.
|
||||
*
|
||||
* @return the number of bytes written, zero is valid too
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
* @exception NotYetConnectedException If this channel is not yet connected.
|
||||
*/
|
||||
public abstract int write(ByteBuffer src) throws IOException;
|
||||
|
||||
/**
|
||||
* Writes data to the channel.
|
||||
*
|
||||
* @return the number of bytes written, zero is valid too
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
* @exception NotYetConnectedException If this channel is not yet connected.
|
||||
*/
|
||||
public abstract long write(ByteBuffer[] srcs, int offset, int length)
|
||||
throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/* UnresolvedAddressException.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public class UnresolvedAddressException extends IllegalArgumentException
|
||||
{
|
||||
/**
|
||||
* Creates the exception
|
||||
*/
|
||||
public UnresolvedAddressException()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/* UnsupportedAddressTypeException.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public class UnsupportedAddressTypeException extends IllegalArgumentException
|
||||
{
|
||||
/**
|
||||
* Creates the exception
|
||||
*/
|
||||
public UnsupportedAddressTypeException()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/* WritableByteChannel.java --
|
||||
Copyright (C) 2002 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.channels;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
|
||||
public interface WritableByteChannel extends Channel
|
||||
{
|
||||
/**
|
||||
* Writes a sequence of bytes to this channel from the given buffer
|
||||
*
|
||||
* @exception AsynchronousCloseException If another thread closes this
|
||||
* channel while the write operation is in progress
|
||||
* @exception ClosedByInterruptException If another thread interrupts the
|
||||
* current thread while the write operation is in progress, thereby closing
|
||||
* the channel and setting the current thread's interrupt status
|
||||
* @exception ClosedChannelException If this channel is closed
|
||||
* @exception IOException If an error occurs
|
||||
* @exception NonWritableChannelException If this channel was not opened for
|
||||
* writing
|
||||
*/
|
||||
int write(ByteBuffer src) throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||
<!-- package.html - describes classes in java.nio.channels package.
|
||||
Copyright (C) 2002 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. -->
|
||||
|
||||
<html>
|
||||
<head><title>GNU Classpath - java.nio.channels</title></head>
|
||||
|
||||
<body>
|
||||
<p>Classes for creating, selecting and non-blocking reading and writing of
|
||||
buffers from files and sockets.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,119 @@
|
||||
/* AbstractInterruptibleChannel.java --
|
||||
Copyright (C) 2002, 2004 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.channels.spi;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.AsynchronousCloseException;
|
||||
import java.nio.channels.Channel;
|
||||
import java.nio.channels.InterruptibleChannel;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class AbstractInterruptibleChannel
|
||||
implements Channel, InterruptibleChannel
|
||||
{
|
||||
private boolean closed;
|
||||
|
||||
/**
|
||||
* Initializes the channel.
|
||||
*/
|
||||
protected AbstractInterruptibleChannel()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the beginning of an I/O operation that might block indefinitely.
|
||||
*/
|
||||
protected final void begin()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the channel.
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
*/
|
||||
public final void close() throws IOException
|
||||
{
|
||||
if (! closed)
|
||||
{
|
||||
closed = true;
|
||||
implCloseChannel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the end of an I/O operation that might block indefinitely.
|
||||
*
|
||||
* @param completed true if the task completed successfully,
|
||||
* false otherwise
|
||||
*
|
||||
* @exception IOException if an error occurs
|
||||
* @exception AsynchronousCloseException If the channel was asynchronously
|
||||
* closed.
|
||||
* @exception ClosedByInterruptException If the thread blocked in the
|
||||
* I/O operation was interrupted.
|
||||
*/
|
||||
protected final void end(boolean completed)
|
||||
throws AsynchronousCloseException
|
||||
{
|
||||
// FIXME: check more here.
|
||||
|
||||
if (closed) throw new AsynchronousCloseException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the channel.
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
*/
|
||||
protected abstract void implCloseChannel() throws IOException;
|
||||
|
||||
/**
|
||||
* Tells whether or not this channel is open.
|
||||
*
|
||||
* @return true if the channel is open, false otherwise
|
||||
*/
|
||||
public final boolean isOpen()
|
||||
{
|
||||
return ! closed;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
/* AbstractSelectableChannel.java
|
||||
Copyright (C) 2002, 2003, 2004 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.channels.spi;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.nio.channels.SelectableChannel;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.Selector;
|
||||
import java.util.LinkedList;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public abstract class AbstractSelectableChannel extends SelectableChannel
|
||||
{
|
||||
private boolean blocking = true;
|
||||
private Object LOCK = new Object();
|
||||
private SelectorProvider provider;
|
||||
private LinkedList keys = new LinkedList();
|
||||
|
||||
/**
|
||||
* Initializes the channel
|
||||
*
|
||||
* @param provider the provider that created this channel
|
||||
*/
|
||||
protected AbstractSelectableChannel(SelectorProvider provider)
|
||||
{
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the object upon which the configureBlocking and register
|
||||
* methods synchronize.
|
||||
*
|
||||
* @return the blocking lock
|
||||
*/
|
||||
public final Object blockingLock()
|
||||
{
|
||||
return LOCK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts this channel's blocking mode.
|
||||
*
|
||||
* @param blocking true if blocking should be enabled, false otherwise
|
||||
*
|
||||
* @return this channel
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
*/
|
||||
public final SelectableChannel configureBlocking(boolean blocking)
|
||||
throws IOException
|
||||
{
|
||||
synchronized (blockingLock())
|
||||
{
|
||||
if (this.blocking != blocking)
|
||||
{
|
||||
implConfigureBlocking(blocking);
|
||||
this.blocking = blocking;
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes this channel.
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
*/
|
||||
protected final void implCloseChannel() throws IOException
|
||||
{
|
||||
implCloseSelectableChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes this selectable channel.
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
*/
|
||||
protected abstract void implCloseSelectableChannel()
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Adjusts this channel's blocking mode.
|
||||
*
|
||||
* @param blocking true if blocking should be enabled, false otherwise
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
*/
|
||||
protected abstract void implConfigureBlocking(boolean blocking)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Tells whether or not every I/O operation on this channel will block
|
||||
* until it completes.
|
||||
*
|
||||
* @return true of this channel is blocking, false otherwise
|
||||
*/
|
||||
public final boolean isBlocking()
|
||||
{
|
||||
return blocking;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether or not this channel is currently registered with
|
||||
* any selectors.
|
||||
*
|
||||
* @return true if this channel is registered, false otherwise
|
||||
*/
|
||||
public final boolean isRegistered()
|
||||
{
|
||||
return ! keys.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the key representing the channel's registration with the
|
||||
* given selector.
|
||||
*
|
||||
* @param selector the selector to get a selection key for
|
||||
*
|
||||
* @return the selection key this channel is registered with
|
||||
*/
|
||||
public final SelectionKey keyFor(Selector selector)
|
||||
{
|
||||
if (! isOpen())
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
synchronized (blockingLock())
|
||||
{
|
||||
return locate(selector);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the provider that created this channel.
|
||||
*
|
||||
* @return the selector provider that created this channel
|
||||
*/
|
||||
public final SelectorProvider provider()
|
||||
{
|
||||
return provider;
|
||||
}
|
||||
|
||||
private SelectionKey locate(Selector selector)
|
||||
{
|
||||
ListIterator it = keys.listIterator();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
SelectionKey key = (SelectionKey) it.next();
|
||||
|
||||
if (key.selector() == selector)
|
||||
return key;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers this channel with the given selector, returning a selection key.
|
||||
*
|
||||
* @param selin the seletor to use
|
||||
* @param ops the interested operations
|
||||
* @param att an attachment for the returned selection key
|
||||
*
|
||||
* @return the registered selection key
|
||||
*
|
||||
* @exception ClosedChannelException If the channel is already closed.
|
||||
*/
|
||||
public final SelectionKey register(Selector selin, int ops, Object att)
|
||||
throws ClosedChannelException
|
||||
{
|
||||
if (! isOpen())
|
||||
throw new ClosedChannelException();
|
||||
|
||||
if ((ops & ~validOps()) != 0)
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
SelectionKey key = null;
|
||||
AbstractSelector selector = (AbstractSelector) selin;
|
||||
|
||||
synchronized (blockingLock())
|
||||
{
|
||||
key = locate(selector);
|
||||
|
||||
if (key != null && key.isValid())
|
||||
{
|
||||
if (att != null)
|
||||
key.attach(att);
|
||||
}
|
||||
else
|
||||
{
|
||||
key = selector.register(this, ops, att);
|
||||
|
||||
if (key != null)
|
||||
addSelectionKey(key);
|
||||
}
|
||||
}
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
void addSelectionKey(SelectionKey key)
|
||||
{
|
||||
keys.add(key);
|
||||
}
|
||||
|
||||
// This method gets called by AbstractSelector.deregister().
|
||||
void removeSelectionKey(SelectionKey key)
|
||||
{
|
||||
keys.remove(key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/* AbstractSelectionKey.java --
|
||||
Copyright (C) 2002, 2003, 2004 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.channels.spi;
|
||||
|
||||
import java.nio.channels.SelectionKey;
|
||||
|
||||
|
||||
/**
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class AbstractSelectionKey extends SelectionKey
|
||||
{
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* Initializes the key.
|
||||
*/
|
||||
protected AbstractSelectionKey()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels this key.
|
||||
*/
|
||||
public final void cancel()
|
||||
{
|
||||
if (isValid())
|
||||
{
|
||||
((AbstractSelector) selector()).cancelKey(this);
|
||||
cancelled = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether this key is valid or not.
|
||||
*
|
||||
* @return true if this key is valid, false otherwise
|
||||
*/
|
||||
public final boolean isValid()
|
||||
{
|
||||
return ! cancelled;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
/* AbstractSelector.java --
|
||||
Copyright (C) 2002, 2003, 2004 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.channels.spi;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.ClosedSelectorException;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.Selector;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public abstract class AbstractSelector extends Selector
|
||||
{
|
||||
private boolean closed;
|
||||
private SelectorProvider provider;
|
||||
private HashSet cancelledKeys;
|
||||
|
||||
/**
|
||||
* Initializes the slector.
|
||||
*
|
||||
* @param provider the provider that created this selector
|
||||
*/
|
||||
protected AbstractSelector(SelectorProvider provider)
|
||||
{
|
||||
this.provider = provider;
|
||||
this.cancelledKeys = new HashSet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the channel.
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
*/
|
||||
public final synchronized void close() throws IOException
|
||||
{
|
||||
if (closed)
|
||||
return;
|
||||
|
||||
implCloseSelector();
|
||||
closed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether this channel is open or not.
|
||||
*
|
||||
* @return true if channel is open, false otherwise.
|
||||
*/
|
||||
public final boolean isOpen()
|
||||
{
|
||||
return ! closed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the beginning of an I/O operation that might block indefinitely.
|
||||
*/
|
||||
protected final void begin()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the end of an I/O operation that might block indefinitely.
|
||||
*/
|
||||
protected final void end()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the provider for this selector object.
|
||||
*
|
||||
* @return the SelectorProvider object that created this seletor
|
||||
*/
|
||||
public final SelectorProvider provider()
|
||||
{
|
||||
return provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cancelled keys set.
|
||||
*
|
||||
* @return the cancelled keys set
|
||||
*/
|
||||
protected final Set cancelledKeys()
|
||||
{
|
||||
if (! isOpen())
|
||||
throw new ClosedSelectorException();
|
||||
|
||||
return cancelledKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels a selection key.
|
||||
*/
|
||||
|
||||
// This method is only called by AbstractSelectionKey.cancel().
|
||||
final void cancelKey(AbstractSelectionKey key)
|
||||
{
|
||||
synchronized (cancelledKeys)
|
||||
{
|
||||
cancelledKeys.add(key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the channel.
|
||||
*
|
||||
* @exception IOException if an error occurs
|
||||
*/
|
||||
protected abstract void implCloseSelector() throws IOException;
|
||||
|
||||
/**
|
||||
* Registers a channel for the selection process.
|
||||
*
|
||||
* @param ch the channel register
|
||||
* @param ops the interested operations
|
||||
* @param att an attachement to the selection key
|
||||
*
|
||||
* @return the registered selection key
|
||||
*/
|
||||
protected abstract SelectionKey register(AbstractSelectableChannel ch,
|
||||
int ops, Object att);
|
||||
|
||||
/**
|
||||
* Deregisters the given selection key.
|
||||
*
|
||||
* @param key the key to deregister
|
||||
*/
|
||||
protected final void deregister(AbstractSelectionKey key)
|
||||
{
|
||||
((AbstractSelectableChannel) key.channel()).removeSelectionKey(key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
/* SelectorProvider.java
|
||||
Copyright (C) 2002, 2003, 2004 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.channels.spi;
|
||||
|
||||
import gnu.java.nio.SelectorProviderImpl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.DatagramChannel;
|
||||
import java.nio.channels.Pipe;
|
||||
import java.nio.channels.ServerSocketChannel;
|
||||
import java.nio.channels.SocketChannel;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class SelectorProvider
|
||||
{
|
||||
private static SelectorProvider systemDefaultProvider;
|
||||
|
||||
/**
|
||||
* Initializes the selector provider.
|
||||
*
|
||||
* @exception SecurityException If a security manager has been installed and
|
||||
* it denies @see RuntimePermission ("selectorProvider").
|
||||
*/
|
||||
protected SelectorProvider()
|
||||
{
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null)
|
||||
sm.checkPermission(new RuntimePermission("selectorProvider"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a datagram channel.
|
||||
*
|
||||
* @return a new datagram channel object
|
||||
*
|
||||
* @exception IOException if an error occurs
|
||||
*/
|
||||
public abstract DatagramChannel openDatagramChannel()
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Opens a pipe.
|
||||
*
|
||||
* @return a new pipe object
|
||||
*
|
||||
* @exception IOException if an error occurs
|
||||
*/
|
||||
public abstract Pipe openPipe() throws IOException;
|
||||
|
||||
/**
|
||||
* Opens a selector.
|
||||
*
|
||||
* @return a new selector object
|
||||
*
|
||||
* @exception IOException if an error occurs
|
||||
*/
|
||||
public abstract AbstractSelector openSelector() throws IOException;
|
||||
|
||||
/**
|
||||
* Opens a server socket channel.
|
||||
*
|
||||
* @return a new server socket channel object
|
||||
*
|
||||
* @exception IOException if an error occurs
|
||||
*/
|
||||
public abstract ServerSocketChannel openServerSocketChannel()
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Opens a socket channel.
|
||||
*
|
||||
* @return a new socket channel object
|
||||
*
|
||||
* @exception IOException if an error occurs
|
||||
*/
|
||||
public abstract SocketChannel openSocketChannel() throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the system-wide default selector provider for this invocation
|
||||
* of the Java virtual machine.
|
||||
*
|
||||
* @return the default seletor provider
|
||||
*/
|
||||
public static synchronized SelectorProvider provider()
|
||||
{
|
||||
if (systemDefaultProvider == null)
|
||||
{
|
||||
String propertyValue =
|
||||
System.getProperty("java.nio.channels.spi.SelectorProvider");
|
||||
|
||||
if (propertyValue == null || propertyValue.equals(""))
|
||||
systemDefaultProvider = new SelectorProviderImpl();
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
systemDefaultProvider =
|
||||
(SelectorProvider) Class.forName(propertyValue)
|
||||
.newInstance();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.err.println("Could not instantiate class: "
|
||||
+ propertyValue);
|
||||
systemDefaultProvider = new SelectorProviderImpl();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return systemDefaultProvider;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||
<!-- package.html - describes classes in java.nio.channels.spi package.
|
||||
Copyright (C) 2002 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. -->
|
||||
|
||||
<html>
|
||||
<head><title>GNU Classpath - java.nio.channels.spi</title></head>
|
||||
|
||||
<body>
|
||||
<p>Utility classes and interfaces for implementing channels.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,53 @@
|
||||
/* CharacterCodingException.java --
|
||||
Copyright (C) 2002 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.charset;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @since 1.4
|
||||
*/
|
||||
public class CharacterCodingException extends IOException
|
||||
{
|
||||
/**
|
||||
* Creates the exception
|
||||
*/
|
||||
public CharacterCodingException()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,406 @@
|
||||
/* Charset.java --
|
||||
Copyright (C) 2002, 2004, 2005 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.charset;
|
||||
|
||||
import gnu.classpath.SystemProperties;
|
||||
|
||||
import gnu.java.nio.charset.Provider;
|
||||
import gnu.java.nio.charset.iconv.IconvProvider;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.charset.spi.CharsetProvider;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* @author Jesse Rosenstock
|
||||
* @since 1.4
|
||||
* @status updated to 1.5
|
||||
*/
|
||||
public abstract class Charset implements Comparable
|
||||
{
|
||||
private CharsetEncoder cachedEncoder;
|
||||
private CharsetDecoder cachedDecoder;
|
||||
|
||||
/**
|
||||
* Charset providers.
|
||||
*/
|
||||
private static CharsetProvider[] providers;
|
||||
|
||||
private final String canonicalName;
|
||||
private final String[] aliases;
|
||||
|
||||
protected Charset (String canonicalName, String[] aliases)
|
||||
{
|
||||
checkName (canonicalName);
|
||||
if (aliases != null)
|
||||
{
|
||||
int n = aliases.length;
|
||||
for (int i = 0; i < n; ++i)
|
||||
checkName (aliases[i]);
|
||||
}
|
||||
|
||||
cachedEncoder = null;
|
||||
cachedDecoder = null;
|
||||
this.canonicalName = canonicalName;
|
||||
this.aliases = aliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalCharsetNameException if the name is illegal
|
||||
*/
|
||||
private static void checkName (String name)
|
||||
{
|
||||
int n = name.length ();
|
||||
|
||||
if (n == 0)
|
||||
throw new IllegalCharsetNameException (name);
|
||||
|
||||
char ch = name.charAt (0);
|
||||
if (!(('A' <= ch && ch <= 'Z')
|
||||
|| ('a' <= ch && ch <= 'z')
|
||||
|| ('0' <= ch && ch <= '9')))
|
||||
throw new IllegalCharsetNameException (name);
|
||||
|
||||
for (int i = 1; i < n; ++i)
|
||||
{
|
||||
ch = name.charAt (i);
|
||||
if (!(('A' <= ch && ch <= 'Z')
|
||||
|| ('a' <= ch && ch <= 'z')
|
||||
|| ('0' <= ch && ch <= '9')
|
||||
|| ch == '-' || ch == '.' || ch == ':' || ch == '_'))
|
||||
throw new IllegalCharsetNameException (name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the system default charset.
|
||||
*
|
||||
* This may be set by the user or VM with the file.encoding
|
||||
* property.
|
||||
*/
|
||||
public static Charset defaultCharset()
|
||||
{
|
||||
String encoding;
|
||||
|
||||
try
|
||||
{
|
||||
encoding = SystemProperties.getProperty("file.encoding");
|
||||
}
|
||||
catch(SecurityException e)
|
||||
{
|
||||
// Use fallback.
|
||||
encoding = "ISO-8859-1";
|
||||
}
|
||||
catch(IllegalArgumentException e)
|
||||
{
|
||||
// Use fallback.
|
||||
encoding = "ISO-8859-1";
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return forName(encoding);
|
||||
}
|
||||
catch(UnsupportedCharsetException e)
|
||||
{
|
||||
// Ignore.
|
||||
}
|
||||
catch(IllegalCharsetNameException e)
|
||||
{
|
||||
// Ignore.
|
||||
}
|
||||
catch(IllegalArgumentException e)
|
||||
{
|
||||
// Ignore.
|
||||
}
|
||||
|
||||
throw new IllegalStateException("Can't get default charset!");
|
||||
}
|
||||
|
||||
public static boolean isSupported (String charsetName)
|
||||
{
|
||||
return charsetForName (charsetName) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Charset instance for the charset of the given name.
|
||||
*
|
||||
* @param charsetName
|
||||
* @return
|
||||
* @throws UnsupportedCharsetException if this VM does not support
|
||||
* the charset of the given name.
|
||||
* @throws IllegalCharsetNameException if the given charset name is
|
||||
* legal.
|
||||
* @throws IllegalArgumentException if <code>charsetName</code> is null.
|
||||
*/
|
||||
public static Charset forName (String charsetName)
|
||||
{
|
||||
// Throws IllegalArgumentException as the JDK does.
|
||||
if(charsetName == null)
|
||||
throw new IllegalArgumentException("Charset name must not be null.");
|
||||
|
||||
Charset cs = charsetForName (charsetName);
|
||||
if (cs == null)
|
||||
throw new UnsupportedCharsetException (charsetName);
|
||||
return cs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a charset for the given charset name.
|
||||
*
|
||||
* @return A charset object for the charset with the specified name, or
|
||||
* <code>null</code> if no such charset exists.
|
||||
*
|
||||
* @throws IllegalCharsetNameException if the name is illegal
|
||||
*/
|
||||
private static Charset charsetForName(String charsetName)
|
||||
{
|
||||
checkName (charsetName);
|
||||
Charset cs = null;
|
||||
CharsetProvider[] providers = providers2();
|
||||
for (int i = 0; i < providers.length; i++)
|
||||
{
|
||||
cs = providers[i].charsetForName(charsetName);
|
||||
if (cs != null)
|
||||
break;
|
||||
}
|
||||
return cs;
|
||||
}
|
||||
|
||||
public static SortedMap availableCharsets()
|
||||
{
|
||||
TreeMap charsets = new TreeMap(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
CharsetProvider[] providers = providers2();
|
||||
for (int j = 0; j < providers.length; j++)
|
||||
{
|
||||
for (Iterator i = providers[j].charsets(); i.hasNext(); )
|
||||
{
|
||||
Charset cs = (Charset) i.next();
|
||||
charsets.put(cs.name(), cs);
|
||||
}
|
||||
}
|
||||
|
||||
return Collections.unmodifiableSortedMap(charsets);
|
||||
}
|
||||
|
||||
private static CharsetProvider provider()
|
||||
{
|
||||
String useIconv = SystemProperties.getProperty
|
||||
("gnu.classpath.nio.charset.provider.iconv");
|
||||
|
||||
if (useIconv != null)
|
||||
return IconvProvider.provider();
|
||||
|
||||
return Provider.provider();
|
||||
}
|
||||
|
||||
/**
|
||||
* We need to support multiple providers, reading them from
|
||||
* java.nio.charset.spi.CharsetProvider in the resource directory
|
||||
* META-INF/services.
|
||||
*/
|
||||
private static CharsetProvider[] providers2()
|
||||
{
|
||||
if (providers == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
Enumeration en = ClassLoader.getSystemResources
|
||||
("META-INF/services/java.nio.charset.spi.CharsetProvider");
|
||||
LinkedHashSet set = new LinkedHashSet();
|
||||
set.add(provider());
|
||||
while (en.hasMoreElements())
|
||||
{
|
||||
BufferedReader rdr = new BufferedReader(new InputStreamReader
|
||||
(((URL) (en.nextElement())).openStream()));
|
||||
while (true)
|
||||
{
|
||||
String s = rdr.readLine();
|
||||
if (s == null)
|
||||
break;
|
||||
CharsetProvider p =
|
||||
(CharsetProvider) ((Class.forName(s)).newInstance());
|
||||
set.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
providers = new CharsetProvider[set.size()];
|
||||
set.toArray(providers);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return providers;
|
||||
}
|
||||
|
||||
public final String name ()
|
||||
{
|
||||
return canonicalName;
|
||||
}
|
||||
|
||||
public final Set aliases ()
|
||||
{
|
||||
if (aliases == null)
|
||||
return Collections.EMPTY_SET;
|
||||
|
||||
// should we cache the aliasSet instead?
|
||||
int n = aliases.length;
|
||||
HashSet aliasSet = new HashSet (n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
aliasSet.add (aliases[i]);
|
||||
return Collections.unmodifiableSet (aliasSet);
|
||||
}
|
||||
|
||||
public String displayName ()
|
||||
{
|
||||
return canonicalName;
|
||||
}
|
||||
|
||||
public String displayName (Locale locale)
|
||||
{
|
||||
return canonicalName;
|
||||
}
|
||||
|
||||
public final boolean isRegistered ()
|
||||
{
|
||||
return (!canonicalName.startsWith ("x-")
|
||||
&& !canonicalName.startsWith ("X-"));
|
||||
}
|
||||
|
||||
public abstract boolean contains (Charset cs);
|
||||
|
||||
public abstract CharsetDecoder newDecoder ();
|
||||
|
||||
public abstract CharsetEncoder newEncoder ();
|
||||
|
||||
public boolean canEncode ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// NB: This implementation serializes different threads calling
|
||||
// Charset.encode(), a potential performance problem. It might
|
||||
// be better to remove the cache, or use ThreadLocal to cache on
|
||||
// a per-thread basis.
|
||||
public final synchronized ByteBuffer encode (CharBuffer cb)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (cachedEncoder == null)
|
||||
{
|
||||
cachedEncoder = newEncoder ()
|
||||
.onMalformedInput (CodingErrorAction.REPLACE)
|
||||
.onUnmappableCharacter (CodingErrorAction.REPLACE);
|
||||
} else
|
||||
cachedEncoder.reset();
|
||||
return cachedEncoder.encode (cb);
|
||||
}
|
||||
catch (CharacterCodingException e)
|
||||
{
|
||||
throw new AssertionError (e);
|
||||
}
|
||||
}
|
||||
|
||||
public final ByteBuffer encode (String str)
|
||||
{
|
||||
return encode (CharBuffer.wrap (str));
|
||||
}
|
||||
|
||||
// NB: This implementation serializes different threads calling
|
||||
// Charset.decode(), a potential performance problem. It might
|
||||
// be better to remove the cache, or use ThreadLocal to cache on
|
||||
// a per-thread basis.
|
||||
public final synchronized CharBuffer decode (ByteBuffer bb)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (cachedDecoder == null)
|
||||
{
|
||||
cachedDecoder = newDecoder ()
|
||||
.onMalformedInput (CodingErrorAction.REPLACE)
|
||||
.onUnmappableCharacter (CodingErrorAction.REPLACE);
|
||||
} else
|
||||
cachedDecoder.reset();
|
||||
|
||||
return cachedDecoder.decode (bb);
|
||||
}
|
||||
catch (CharacterCodingException e)
|
||||
{
|
||||
throw new AssertionError (e);
|
||||
}
|
||||
}
|
||||
|
||||
public final int compareTo (Object ob)
|
||||
{
|
||||
return canonicalName.compareToIgnoreCase (((Charset) ob).canonicalName);
|
||||
}
|
||||
|
||||
public final int hashCode ()
|
||||
{
|
||||
return canonicalName.hashCode ();
|
||||
}
|
||||
|
||||
public final boolean equals (Object ob)
|
||||
{
|
||||
if (ob instanceof Charset)
|
||||
return canonicalName.equalsIgnoreCase (((Charset) ob).canonicalName);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public final String toString ()
|
||||
{
|
||||
return canonicalName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,317 @@
|
||||
/* CharsetDecoder.java --
|
||||
Copyright (C) 2002 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.charset;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
|
||||
/**
|
||||
* @author Jesse Rosenstock
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class CharsetDecoder
|
||||
{
|
||||
private static final int STATE_RESET = 0;
|
||||
private static final int STATE_CODING = 1;
|
||||
private static final int STATE_END = 2;
|
||||
private static final int STATE_FLUSHED = 3;
|
||||
|
||||
private static final String DEFAULT_REPLACEMENT = "\uFFFD";
|
||||
|
||||
private final Charset charset;
|
||||
private final float averageCharsPerByte;
|
||||
private final float maxCharsPerByte;
|
||||
private String replacement;
|
||||
|
||||
private int state = STATE_RESET;
|
||||
|
||||
private CodingErrorAction malformedInputAction
|
||||
= CodingErrorAction.REPORT;
|
||||
private CodingErrorAction unmappableCharacterAction
|
||||
= CodingErrorAction.REPORT;
|
||||
|
||||
private CharsetDecoder (Charset cs, float averageCharsPerByte,
|
||||
float maxCharsPerByte, String replacement)
|
||||
{
|
||||
if (averageCharsPerByte <= 0.0f)
|
||||
throw new IllegalArgumentException ("Non-positive averageCharsPerByte");
|
||||
if (maxCharsPerByte <= 0.0f)
|
||||
throw new IllegalArgumentException ("Non-positive maxCharsPerByte");
|
||||
|
||||
this.charset = cs;
|
||||
this.averageCharsPerByte
|
||||
= averageCharsPerByte;
|
||||
this.maxCharsPerByte
|
||||
= maxCharsPerByte;
|
||||
this.replacement = replacement;
|
||||
implReplaceWith (replacement);
|
||||
}
|
||||
|
||||
protected CharsetDecoder (Charset cs, float averageCharsPerByte,
|
||||
float maxCharsPerByte)
|
||||
{
|
||||
this (cs, averageCharsPerByte, maxCharsPerByte, DEFAULT_REPLACEMENT);
|
||||
}
|
||||
|
||||
public final float averageCharsPerByte ()
|
||||
{
|
||||
return averageCharsPerByte;
|
||||
}
|
||||
|
||||
public final Charset charset ()
|
||||
{
|
||||
return charset;
|
||||
}
|
||||
|
||||
public final CharBuffer decode (ByteBuffer in)
|
||||
throws CharacterCodingException
|
||||
{
|
||||
// XXX: Sun's Javadoc seems to contradict itself saying an
|
||||
// IllegalStateException is thrown "if a decoding operation is already
|
||||
// in progress" and also that "it resets this Decoder".
|
||||
// Should we check to see that the state is reset, or should we
|
||||
// call reset()?
|
||||
if (state != STATE_RESET)
|
||||
throw new IllegalStateException ();
|
||||
|
||||
// REVIEW: Using max instead of average may allocate a very large
|
||||
// buffer. Maybe we should do something more efficient?
|
||||
int remaining = in.remaining ();
|
||||
int n = (int) (remaining * maxCharsPerByte ());
|
||||
CharBuffer out = CharBuffer.allocate (n);
|
||||
|
||||
if (remaining == 0)
|
||||
{
|
||||
state = STATE_FLUSHED;
|
||||
return out;
|
||||
}
|
||||
|
||||
CoderResult cr = decode (in, out, true);
|
||||
if (cr.isError ())
|
||||
cr.throwException ();
|
||||
|
||||
cr = flush (out);
|
||||
if (cr.isError ())
|
||||
cr.throwException ();
|
||||
|
||||
reset();
|
||||
out.flip ();
|
||||
|
||||
// Unfortunately, resizing the actual charbuffer array is required.
|
||||
char[] resized = new char[out.remaining()];
|
||||
out.get(resized);
|
||||
return CharBuffer.wrap(resized);
|
||||
}
|
||||
|
||||
public final CoderResult decode (ByteBuffer in, CharBuffer out,
|
||||
boolean endOfInput)
|
||||
{
|
||||
int newState = endOfInput ? STATE_END : STATE_CODING;
|
||||
// XXX: Need to check for "previous step was an invocation [not] of
|
||||
// this method with a value of true for the endOfInput parameter but
|
||||
// a return value indicating an incomplete decoding operation"
|
||||
// XXX: We will not check the previous return value, just
|
||||
// that the previous call passed true for endOfInput
|
||||
if (state != STATE_RESET && state != STATE_CODING
|
||||
&& !(endOfInput && state == STATE_END))
|
||||
throw new IllegalStateException ();
|
||||
state = newState;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
CoderResult cr;
|
||||
try
|
||||
{
|
||||
cr = decodeLoop (in, out);
|
||||
}
|
||||
catch (RuntimeException e)
|
||||
{
|
||||
throw new CoderMalfunctionError (e);
|
||||
}
|
||||
|
||||
if (cr.isOverflow ())
|
||||
return cr;
|
||||
|
||||
if (cr.isUnderflow ())
|
||||
{
|
||||
if (endOfInput && in.hasRemaining ())
|
||||
cr = CoderResult.malformedForLength (in.remaining ());
|
||||
else
|
||||
return cr;
|
||||
}
|
||||
|
||||
CodingErrorAction action = cr.isMalformed ()
|
||||
? malformedInputAction
|
||||
: unmappableCharacterAction;
|
||||
|
||||
if (action == CodingErrorAction.REPORT)
|
||||
return cr;
|
||||
|
||||
if (action == CodingErrorAction.REPLACE)
|
||||
{
|
||||
if (out.remaining () < replacement.length ())
|
||||
return CoderResult.OVERFLOW;
|
||||
out.put (replacement);
|
||||
}
|
||||
|
||||
in.position (in.position () + cr.length ());
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract CoderResult decodeLoop (ByteBuffer in, CharBuffer out);
|
||||
|
||||
public Charset detectedCharset ()
|
||||
{
|
||||
throw new UnsupportedOperationException ();
|
||||
}
|
||||
|
||||
public final CoderResult flush (CharBuffer out)
|
||||
{
|
||||
// It seems weird that you can flush after reset, but Sun's javadoc
|
||||
// says an IllegalStateException is thrown "If the previous step of the
|
||||
// current decoding operation was an invocation neither of the reset
|
||||
// method nor ... of the three-argument decode method with a value of
|
||||
// true for the endOfInput parameter."
|
||||
// Further note that flush() only requires that there not be
|
||||
// an IllegalStateException if the previous step was a call to
|
||||
// decode with true as the last argument. It does not require
|
||||
// that the call succeeded. decode() does require that it succeeded.
|
||||
// XXX: test this to see if reality matches javadoc
|
||||
if (state != STATE_RESET && state != STATE_END)
|
||||
throw new IllegalStateException ();
|
||||
|
||||
state = STATE_FLUSHED;
|
||||
return implFlush (out);
|
||||
}
|
||||
|
||||
protected CoderResult implFlush (CharBuffer out)
|
||||
{
|
||||
return CoderResult.UNDERFLOW;
|
||||
}
|
||||
|
||||
public final CharsetDecoder onMalformedInput (CodingErrorAction newAction)
|
||||
{
|
||||
if (newAction == null)
|
||||
throw new IllegalArgumentException ("Null action");
|
||||
|
||||
malformedInputAction = newAction;
|
||||
implOnMalformedInput (newAction);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected void implOnMalformedInput (CodingErrorAction newAction)
|
||||
{
|
||||
// default implementation does nothing
|
||||
}
|
||||
|
||||
protected void implOnUnmappableCharacter (CodingErrorAction newAction)
|
||||
{
|
||||
// default implementation does nothing
|
||||
}
|
||||
|
||||
protected void implReplaceWith (String newReplacement)
|
||||
{
|
||||
// default implementation does nothing
|
||||
}
|
||||
|
||||
protected void implReset ()
|
||||
{
|
||||
// default implementation does nothing
|
||||
}
|
||||
|
||||
public boolean isAutoDetecting ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isCharsetDetected ()
|
||||
{
|
||||
throw new UnsupportedOperationException ();
|
||||
}
|
||||
|
||||
public CodingErrorAction malformedInputAction ()
|
||||
{
|
||||
return malformedInputAction;
|
||||
}
|
||||
|
||||
public final float maxCharsPerByte ()
|
||||
{
|
||||
return maxCharsPerByte;
|
||||
}
|
||||
|
||||
public final CharsetDecoder onUnmappableCharacter
|
||||
(CodingErrorAction newAction)
|
||||
{
|
||||
if (newAction == null)
|
||||
throw new IllegalArgumentException ("Null action");
|
||||
|
||||
unmappableCharacterAction = newAction;
|
||||
implOnUnmappableCharacter (newAction);
|
||||
return this;
|
||||
}
|
||||
|
||||
public final String replacement ()
|
||||
{
|
||||
return replacement;
|
||||
}
|
||||
|
||||
public final CharsetDecoder replaceWith (String newReplacement)
|
||||
{
|
||||
if (newReplacement == null)
|
||||
throw new IllegalArgumentException ("Null replacement");
|
||||
if (newReplacement.length () == 0)
|
||||
throw new IllegalArgumentException ("Empty replacement");
|
||||
// XXX: what about maxCharsPerByte?
|
||||
|
||||
this.replacement = newReplacement;
|
||||
implReplaceWith (newReplacement);
|
||||
return this;
|
||||
}
|
||||
|
||||
public final CharsetDecoder reset ()
|
||||
{
|
||||
state = STATE_RESET;
|
||||
implReset ();
|
||||
return this;
|
||||
}
|
||||
|
||||
public CodingErrorAction unmappableCharacterAction ()
|
||||
{
|
||||
return unmappableCharacterAction;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,369 @@
|
||||
/* CharsetEncoder.java --
|
||||
Copyright (C) 2002 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.charset;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
|
||||
/**
|
||||
* @author Jesse Rosenstock
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class CharsetEncoder
|
||||
{
|
||||
private static final int STATE_RESET = 0;
|
||||
private static final int STATE_CODING = 1;
|
||||
private static final int STATE_END = 2;
|
||||
private static final int STATE_FLUSHED = 3;
|
||||
|
||||
private static final byte[] DEFAULT_REPLACEMENT = {(byte)'?'};
|
||||
|
||||
private final Charset charset;
|
||||
private final float averageBytesPerChar;
|
||||
private final float maxBytesPerChar;
|
||||
private byte[] replacement;
|
||||
|
||||
private int state = STATE_RESET;
|
||||
|
||||
private CodingErrorAction malformedInputAction
|
||||
= CodingErrorAction.REPORT;
|
||||
private CodingErrorAction unmappableCharacterAction
|
||||
= CodingErrorAction.REPORT;
|
||||
|
||||
protected CharsetEncoder (Charset cs, float averageBytesPerChar,
|
||||
float maxBytesPerChar)
|
||||
{
|
||||
this (cs, averageBytesPerChar, maxBytesPerChar, DEFAULT_REPLACEMENT);
|
||||
}
|
||||
|
||||
protected CharsetEncoder (Charset cs, float averageBytesPerChar,
|
||||
float maxBytesPerChar, byte[] replacement)
|
||||
{
|
||||
if (averageBytesPerChar <= 0.0f)
|
||||
throw new IllegalArgumentException ("Non-positive averageBytesPerChar");
|
||||
if (maxBytesPerChar <= 0.0f)
|
||||
throw new IllegalArgumentException ("Non-positive maxBytesPerChar");
|
||||
|
||||
this.charset = cs;
|
||||
this.averageBytesPerChar
|
||||
= averageBytesPerChar;
|
||||
this.maxBytesPerChar
|
||||
= maxBytesPerChar;
|
||||
this.replacement = replacement;
|
||||
implReplaceWith (replacement);
|
||||
}
|
||||
|
||||
public final float averageBytesPerChar ()
|
||||
{
|
||||
return averageBytesPerChar;
|
||||
}
|
||||
|
||||
public boolean canEncode (char c)
|
||||
{
|
||||
CharBuffer cb = CharBuffer.allocate (1).put (c);
|
||||
cb.flip ();
|
||||
return canEncode (cb);
|
||||
}
|
||||
|
||||
public boolean canEncode (CharSequence cs)
|
||||
{
|
||||
CharBuffer cb;
|
||||
if (cs instanceof CharBuffer)
|
||||
cb = ((CharBuffer) cs).duplicate ();
|
||||
else
|
||||
cb = CharBuffer.wrap (cs);
|
||||
return canEncode (cb);
|
||||
}
|
||||
|
||||
private boolean canEncode (CharBuffer cb)
|
||||
{
|
||||
// It is an error if a coding operation is "in progress"
|
||||
// I take that to mean the state is not reset or flushed.
|
||||
// XXX: check "in progress" everywhere
|
||||
if (state == STATE_FLUSHED)
|
||||
reset ();
|
||||
else if (state != STATE_RESET)
|
||||
throw new IllegalStateException ();
|
||||
|
||||
CodingErrorAction oldMalformedInputAction = malformedInputAction;
|
||||
CodingErrorAction oldUnmappableCharacterAction
|
||||
= unmappableCharacterAction;
|
||||
|
||||
try
|
||||
{
|
||||
if (oldMalformedInputAction != CodingErrorAction.REPORT)
|
||||
onMalformedInput (CodingErrorAction.REPORT);
|
||||
if (oldUnmappableCharacterAction != CodingErrorAction.REPORT)
|
||||
onUnmappableCharacter (CodingErrorAction.REPORT);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (oldMalformedInputAction != CodingErrorAction.REPORT)
|
||||
onMalformedInput (oldMalformedInputAction);
|
||||
if (oldUnmappableCharacterAction != CodingErrorAction.REPORT)
|
||||
onUnmappableCharacter (oldUnmappableCharacterAction);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public final Charset charset ()
|
||||
{
|
||||
return charset;
|
||||
}
|
||||
|
||||
public final ByteBuffer encode (CharBuffer in)
|
||||
throws CharacterCodingException
|
||||
{
|
||||
// XXX: Sun's Javadoc seems to contradict itself saying an
|
||||
// IllegalStateException is thrown "if a decoding operation is already
|
||||
// in progress" and also that "it resets this Encoder".
|
||||
// Should we check to see that the state is reset, or should we
|
||||
// call reset()?
|
||||
if (state != STATE_RESET)
|
||||
throw new IllegalStateException ();
|
||||
|
||||
// REVIEW: Using max instead of average may allocate a very large
|
||||
// buffer. Maybe we should do something more efficient?
|
||||
int remaining = in.remaining ();
|
||||
int n = (int) (remaining * maxBytesPerChar ());
|
||||
ByteBuffer out = ByteBuffer.allocate (n);
|
||||
|
||||
if (remaining == 0)
|
||||
{
|
||||
state = STATE_FLUSHED;
|
||||
return out;
|
||||
}
|
||||
|
||||
CoderResult cr = encode (in, out, true);
|
||||
if (cr.isError ())
|
||||
cr.throwException ();
|
||||
|
||||
cr = flush (out);
|
||||
if (cr.isError ())
|
||||
cr.throwException ();
|
||||
|
||||
out.flip ();
|
||||
|
||||
// Unfortunately, resizing the actual bytebuffer array is required.
|
||||
byte[] resized = new byte[out.remaining()];
|
||||
out.get(resized);
|
||||
return ByteBuffer.wrap(resized);
|
||||
}
|
||||
|
||||
public final CoderResult encode (CharBuffer in, ByteBuffer out,
|
||||
boolean endOfInput)
|
||||
{
|
||||
int newState = endOfInput ? STATE_END : STATE_CODING;
|
||||
// XXX: Need to check for "previous step was an invocation [not] of
|
||||
// this method with a value of true for the endOfInput parameter but
|
||||
// a return value indicating an incomplete decoding operation"
|
||||
// XXX: We will not check the previous return value, just
|
||||
// that the previous call passed true for endOfInput
|
||||
if (state != STATE_RESET && state != STATE_CODING
|
||||
&& !(endOfInput && state == STATE_END))
|
||||
throw new IllegalStateException ();
|
||||
state = newState;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
CoderResult cr;
|
||||
try
|
||||
{
|
||||
cr = encodeLoop (in, out);
|
||||
}
|
||||
catch (RuntimeException e)
|
||||
{
|
||||
throw new CoderMalfunctionError (e);
|
||||
}
|
||||
|
||||
if (cr.isOverflow ())
|
||||
return cr;
|
||||
|
||||
if (cr.isUnderflow ())
|
||||
{
|
||||
if (endOfInput && in.hasRemaining ())
|
||||
cr = CoderResult.malformedForLength (in.remaining ());
|
||||
else
|
||||
return cr;
|
||||
}
|
||||
|
||||
CodingErrorAction action = cr.isMalformed ()
|
||||
? malformedInputAction
|
||||
: unmappableCharacterAction;
|
||||
|
||||
if (action == CodingErrorAction.REPORT)
|
||||
return cr;
|
||||
|
||||
if (action == CodingErrorAction.REPLACE)
|
||||
{
|
||||
if (out.remaining () < replacement.length)
|
||||
return CoderResult.OVERFLOW;
|
||||
out.put (replacement);
|
||||
}
|
||||
|
||||
in.position (in.position () + cr.length ());
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract CoderResult encodeLoop (CharBuffer in, ByteBuffer out);
|
||||
|
||||
public final CoderResult flush (ByteBuffer out)
|
||||
{
|
||||
// It seems weird that you can flush after reset, but Sun's javadoc
|
||||
// says an IllegalStateException is thrown "If the previous step of the
|
||||
// current decoding operation was an invocation neither of the reset
|
||||
// method nor ... of the three-argument encode method with a value of
|
||||
// true for the endOfInput parameter."
|
||||
// Further note that flush() only requires that there not be
|
||||
// an IllegalStateException if the previous step was a call to
|
||||
// encode with true as the last argument. It does not require
|
||||
// that the call succeeded. encode() does require that it succeeded.
|
||||
// XXX: test this to see if reality matches javadoc
|
||||
if (state != STATE_RESET && state != STATE_END)
|
||||
throw new IllegalStateException ();
|
||||
|
||||
state = STATE_FLUSHED;
|
||||
return implFlush (out);
|
||||
}
|
||||
|
||||
protected CoderResult implFlush (ByteBuffer out)
|
||||
{
|
||||
return CoderResult.UNDERFLOW;
|
||||
}
|
||||
|
||||
protected void implOnMalformedInput (CodingErrorAction newAction)
|
||||
{
|
||||
// default implementation does nothing
|
||||
}
|
||||
|
||||
protected void implOnUnmappableCharacter (CodingErrorAction newAction)
|
||||
{
|
||||
// default implementation does nothing
|
||||
}
|
||||
|
||||
protected void implReplaceWith (byte[] newReplacement)
|
||||
{
|
||||
// default implementation does nothing
|
||||
}
|
||||
|
||||
protected void implReset ()
|
||||
{
|
||||
// default implementation does nothing
|
||||
}
|
||||
|
||||
public boolean isLegalReplacement (byte[] replacement)
|
||||
{
|
||||
// TODO: cache the decoder
|
||||
// error actions will be REPORT after construction
|
||||
CharsetDecoder decoder = charset.newDecoder ();
|
||||
ByteBuffer bb = ByteBuffer.wrap (replacement);
|
||||
CharBuffer cb
|
||||
= CharBuffer.allocate ((int) (replacement.length
|
||||
* decoder.maxCharsPerByte ()));
|
||||
return !decoder.decode (bb, cb, true).isError ();
|
||||
}
|
||||
|
||||
public CodingErrorAction malformedInputAction ()
|
||||
{
|
||||
return malformedInputAction;
|
||||
}
|
||||
|
||||
public final float maxBytesPerChar ()
|
||||
{
|
||||
return maxBytesPerChar;
|
||||
}
|
||||
|
||||
public final CharsetEncoder onMalformedInput (CodingErrorAction newAction)
|
||||
{
|
||||
if (newAction == null)
|
||||
throw new IllegalArgumentException ("Null action");
|
||||
|
||||
malformedInputAction = newAction;
|
||||
implOnMalformedInput (newAction);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CodingErrorAction unmappableCharacterAction ()
|
||||
{
|
||||
return unmappableCharacterAction;
|
||||
}
|
||||
|
||||
public final CharsetEncoder onUnmappableCharacter
|
||||
(CodingErrorAction newAction)
|
||||
{
|
||||
if (newAction == null)
|
||||
throw new IllegalArgumentException ("Null action");
|
||||
|
||||
unmappableCharacterAction = newAction;
|
||||
implOnUnmappableCharacter (newAction);
|
||||
return this;
|
||||
}
|
||||
|
||||
public final byte[] replacement ()
|
||||
{
|
||||
return replacement;
|
||||
}
|
||||
|
||||
public final CharsetEncoder replaceWith (byte[] newReplacement)
|
||||
{
|
||||
if (newReplacement == null)
|
||||
throw new IllegalArgumentException ("Null replacement");
|
||||
if (newReplacement.length == 0)
|
||||
throw new IllegalArgumentException ("Empty replacement");
|
||||
// XXX: what about maxBytesPerChar?
|
||||
|
||||
if (!isLegalReplacement (newReplacement))
|
||||
throw new IllegalArgumentException ("Illegal replacement");
|
||||
|
||||
this.replacement = newReplacement;
|
||||
implReplaceWith (newReplacement);
|
||||
return this;
|
||||
}
|
||||
|
||||
public final CharsetEncoder reset ()
|
||||
{
|
||||
state = STATE_RESET;
|
||||
implReset ();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/* CoderMalfunctionError.java --
|
||||
Copyright (C) 2002 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.charset;
|
||||
|
||||
/**
|
||||
* @since 1.4
|
||||
*/
|
||||
public class CoderMalfunctionError extends Error
|
||||
{
|
||||
/**
|
||||
* Creates the error
|
||||
*/
|
||||
public CoderMalfunctionError(Exception cause)
|
||||
{
|
||||
super (cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
/* CoderResult.java --
|
||||
Copyright (C) 2002, 2004 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.charset;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.nio.BufferOverflowException;
|
||||
import java.nio.BufferUnderflowException;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @author Jesse Rosenstock
|
||||
* @since 1.4
|
||||
*/
|
||||
public class CoderResult
|
||||
{
|
||||
private static final int TYPE_MALFORMED = 0;
|
||||
private static final int TYPE_OVERFLOW = 1;
|
||||
private static final int TYPE_UNDERFLOW = 2;
|
||||
private static final int TYPE_UNMAPPABLE = 3;
|
||||
|
||||
public static final CoderResult OVERFLOW
|
||||
= new CoderResult (TYPE_OVERFLOW, 0);
|
||||
public static final CoderResult UNDERFLOW
|
||||
= new CoderResult (TYPE_UNDERFLOW, 0);
|
||||
|
||||
private static final String[] names
|
||||
= { "MALFORMED", "OVERFLOW", "UNDERFLOW", "UNMAPPABLE" };
|
||||
|
||||
private static final Cache malformedCache
|
||||
= new Cache ()
|
||||
{
|
||||
protected CoderResult make (int length)
|
||||
{
|
||||
return new CoderResult (TYPE_MALFORMED, length);
|
||||
}
|
||||
};
|
||||
|
||||
private static final Cache unmappableCache
|
||||
= new Cache ()
|
||||
{
|
||||
protected CoderResult make (int length)
|
||||
{
|
||||
return new CoderResult (TYPE_UNMAPPABLE, length);
|
||||
}
|
||||
};
|
||||
|
||||
private final int type;
|
||||
private final int length;
|
||||
|
||||
// Package-private to avoid a trampoline constructor.
|
||||
CoderResult (int type, int length)
|
||||
{
|
||||
this.type = type;
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public boolean isError ()
|
||||
{
|
||||
return length > 0;
|
||||
}
|
||||
|
||||
public boolean isMalformed ()
|
||||
{
|
||||
return type == TYPE_MALFORMED;
|
||||
}
|
||||
|
||||
public boolean isOverflow ()
|
||||
{
|
||||
return type == TYPE_OVERFLOW;
|
||||
}
|
||||
|
||||
public boolean isUnderflow ()
|
||||
{
|
||||
return type == TYPE_UNDERFLOW;
|
||||
}
|
||||
|
||||
public boolean isUnmappable ()
|
||||
{
|
||||
return type == TYPE_UNMAPPABLE;
|
||||
}
|
||||
|
||||
public int length ()
|
||||
{
|
||||
if (length <= 0)
|
||||
throw new UnsupportedOperationException ();
|
||||
else
|
||||
return length;
|
||||
}
|
||||
|
||||
public static CoderResult malformedForLength (int length)
|
||||
{
|
||||
return malformedCache.get (length);
|
||||
}
|
||||
|
||||
public void throwException ()
|
||||
throws CharacterCodingException
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case TYPE_MALFORMED:
|
||||
throw new MalformedInputException (length);
|
||||
case TYPE_OVERFLOW:
|
||||
throw new BufferOverflowException ();
|
||||
case TYPE_UNDERFLOW:
|
||||
throw new BufferUnderflowException ();
|
||||
case TYPE_UNMAPPABLE:
|
||||
throw new UnmappableCharacterException (length);
|
||||
}
|
||||
}
|
||||
|
||||
public String toString ()
|
||||
{
|
||||
String name = names[type];
|
||||
return (length > 0) ? name + '[' + length + ']' : name;
|
||||
}
|
||||
|
||||
public static CoderResult unmappableForLength (int length)
|
||||
{
|
||||
return unmappableCache.get (length);
|
||||
}
|
||||
|
||||
private abstract static class Cache
|
||||
{
|
||||
private final HashMap cache;
|
||||
|
||||
// Package-private to avoid a trampoline constructor.
|
||||
Cache ()
|
||||
{
|
||||
cache = new HashMap ();
|
||||
}
|
||||
|
||||
// Package-private to avoid a trampoline.
|
||||
synchronized CoderResult get (int length)
|
||||
{
|
||||
if (length <= 0)
|
||||
throw new IllegalArgumentException ("Non-positive length");
|
||||
|
||||
Integer len = new Integer (length);
|
||||
CoderResult cr = null;
|
||||
Object o;
|
||||
if ((o = cache.get (len)) != null)
|
||||
cr = (CoderResult) ((WeakReference) o).get ();
|
||||
if (cr == null)
|
||||
{
|
||||
cr = make (length);
|
||||
cache.put (len, new WeakReference (cr));
|
||||
}
|
||||
|
||||
return cr;
|
||||
}
|
||||
|
||||
protected abstract CoderResult make (int length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/* CodingErrorAction.java --
|
||||
Copyright (C) 2002 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.charset;
|
||||
|
||||
public class CodingErrorAction
|
||||
{
|
||||
public static final CodingErrorAction IGNORE
|
||||
= new CodingErrorAction("ignore");
|
||||
public static final CodingErrorAction REPLACE
|
||||
= new CodingErrorAction("replace");
|
||||
public static final CodingErrorAction REPORT
|
||||
= new CodingErrorAction("report");
|
||||
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Private constructor only used to create the constant CodingErrorActions.
|
||||
*/
|
||||
private CodingErrorAction(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the CodingErrorAction.
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/* IllegalCharsetNameException.java --
|
||||
Copyright (C) 2002 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.charset;
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public class IllegalCharsetNameException extends IllegalArgumentException
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.4+
|
||||
*/
|
||||
private static final long serialVersionUID = 1457525358470002989L;
|
||||
|
||||
private String charsetName;
|
||||
|
||||
/**
|
||||
* Creates the exception
|
||||
*
|
||||
* @param charsetName name of the illegal charset
|
||||
*/
|
||||
public IllegalCharsetNameException (String charsetName)
|
||||
{
|
||||
super ();
|
||||
this.charsetName = charsetName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the illegal charset name
|
||||
*
|
||||
* @return the illegal charset name
|
||||
*/
|
||||
public String getCharsetName ()
|
||||
{
|
||||
return charsetName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/* MalformedInputException.java --
|
||||
Copyright (C) 2002 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.charset;
|
||||
|
||||
/**
|
||||
* @since 1.4
|
||||
*/
|
||||
public class MalformedInputException extends CharacterCodingException
|
||||
{
|
||||
private int inputLength;
|
||||
|
||||
/**
|
||||
* Creates the exception
|
||||
*
|
||||
* @param inputLength the position of malformed input in the input stream
|
||||
*/
|
||||
public MalformedInputException (int inputLength)
|
||||
{
|
||||
super ();
|
||||
this.inputLength = inputLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the position of the malformed input in the input stream.
|
||||
*
|
||||
* @return the position
|
||||
*/
|
||||
public int getInputLength ()
|
||||
{
|
||||
return inputLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the detail message string of this throwable
|
||||
*
|
||||
* @return the message
|
||||
*/
|
||||
public String getMessage ()
|
||||
{
|
||||
return "Input length = " + inputLength;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/* UnmappableCharacterException.java --
|
||||
Copyright (C) 2002 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.charset;
|
||||
|
||||
/**
|
||||
* @since 1.4
|
||||
*/
|
||||
public class UnmappableCharacterException extends CharacterCodingException
|
||||
{
|
||||
private int inputLength;
|
||||
|
||||
/**
|
||||
* Creates the exception
|
||||
*/
|
||||
public UnmappableCharacterException (int inputLength)
|
||||
{
|
||||
super ();
|
||||
this.inputLength = inputLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the illegal charset name
|
||||
*/
|
||||
public int getInputLength ()
|
||||
{
|
||||
return inputLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the detail message string of this throwable
|
||||
*/
|
||||
public String getMessage ()
|
||||
{
|
||||
return "Input length = " + inputLength;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/* UnsupportedCharsetException.java --
|
||||
Copyright (C) 2002 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.charset;
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @since 1.4
|
||||
*/
|
||||
public class UnsupportedCharsetException extends IllegalArgumentException
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.4+
|
||||
*/
|
||||
private static final long serialVersionUID = 1490765524727386367L;
|
||||
|
||||
String charsetName;
|
||||
|
||||
/**
|
||||
* Creates the exception
|
||||
*/
|
||||
public UnsupportedCharsetException (String charsetName)
|
||||
{
|
||||
super ();
|
||||
this.charsetName = charsetName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the illegal charset name
|
||||
*/
|
||||
public String getCharsetName ()
|
||||
{
|
||||
return charsetName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||
<!-- package.html - describes classes in java.nio.charset package.
|
||||
Copyright (C) 2002 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. -->
|
||||
|
||||
<html>
|
||||
<head><title>GNU Classpath - java.nio.charset</title></head>
|
||||
|
||||
<body>
|
||||
<p>Classes to manipulate, encode and decode different character sets from
|
||||
and to bytes.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,91 @@
|
||||
/* CharsetProvider.java -- charset service provider interface
|
||||
Copyright (C) 2002 Free Software Foundation
|
||||
|
||||
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.charset.spi;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
/**
|
||||
* This class allows an implementor to provide additional character sets. The
|
||||
* subclass must have a nullary constructor, and be attached to charset
|
||||
* implementation classes. These extensions are loaded via the context class
|
||||
* loader. To provide the charset extension, all files named
|
||||
* <code>META-INF/services/java.nio.charset.spi.CharsetProvider</code> are
|
||||
* read from the classpath. Each one should be a UTF-8 encoded list of
|
||||
* fully-qualified names of concrete subclasses of this class; whitespace is
|
||||
* ignored, and '#' starts comments. Duplicates are ignored. The
|
||||
* implementations must be accessible to the classloader that requests them.
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @see Charset
|
||||
* @since 1.4
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public abstract class CharsetProvider
|
||||
{
|
||||
/**
|
||||
* Initialize a new charset provider. This performs a security check on
|
||||
* RuntimePermission("charsetProvider").
|
||||
*
|
||||
* @throws SecurityException if building a new set is not allowed
|
||||
*/
|
||||
protected CharsetProvider()
|
||||
{
|
||||
SecurityManager s = System.getSecurityManager();
|
||||
if (s != null)
|
||||
s.checkPermission(new RuntimePermission("charsetProvider"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator over the charsets defined by this provider.
|
||||
*
|
||||
* @return the iterator
|
||||
* @see Charset#availableCharsets()
|
||||
*/
|
||||
public abstract Iterator charsets();
|
||||
|
||||
/**
|
||||
* Returns the named charset, by canonical name or alias.
|
||||
*
|
||||
* @param name the name of the character
|
||||
*
|
||||
* @return the charset, or null if not supported
|
||||
*/
|
||||
public abstract Charset charsetForName(String name);
|
||||
} // class CharsetProvider
|
||||
@@ -0,0 +1,46 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||
<!-- package.html - describes classes in java.nio.charset.spi package.
|
||||
Copyright (C) 2002 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. -->
|
||||
|
||||
<html>
|
||||
<head><title>GNU Classpath - java.nio.charset.spi</title></head>
|
||||
|
||||
<body>
|
||||
<p>Classes to provide new character sets.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,58 @@
|
||||
# This property file contains dependencies of classes, methods, and
|
||||
# field on other methods or classes.
|
||||
#
|
||||
# Syntax:
|
||||
#
|
||||
# <used>: <needed 1> [... <needed N>]
|
||||
#
|
||||
# means that when <used> is included, <needed 1> (... <needed N>) must
|
||||
# be included as well.
|
||||
#
|
||||
# <needed X> and <used> are of the form
|
||||
#
|
||||
# <class.methodOrField(signature)>
|
||||
#
|
||||
# or just
|
||||
#
|
||||
# <class>
|
||||
#
|
||||
# Within dependencies, variables can be used. A variable is defined as
|
||||
# follows:
|
||||
#
|
||||
# {variable}: value1 value2 ... value<n>
|
||||
#
|
||||
# variables can be used on the right side of dependencies as follows:
|
||||
#
|
||||
# <used>: com.bla.blu.{variable}.Class.m()V
|
||||
#
|
||||
# The use of the variable will expand to <n> dependencies of the form
|
||||
#
|
||||
# <used>: com.bla.blu.value1.Class.m()V
|
||||
# <used>: com.bla.blu.value2.Class.m()V
|
||||
# ...
|
||||
# <used>: com.bla.blu.value<n>.Class.m()V
|
||||
#
|
||||
# Variables can be redefined when building a system to select the
|
||||
# required support for features like encodings, protocols, etc.
|
||||
#
|
||||
# Hints:
|
||||
#
|
||||
# - For methods and fields, the signature is mandatory. For
|
||||
# specification, please see the Java Virtual Machine Specification by
|
||||
# SUN. Unlike in the spec, field signatures (types) are in brackets.
|
||||
#
|
||||
# - Package names must be separated by '/' (and not '.'). E.g.,
|
||||
# java/lang/Class (this is necessary, because the '.' is used to
|
||||
# separate method or field names from classes)
|
||||
#
|
||||
# - In case <needed> refers to a class, only the class itself will be
|
||||
# included in the resulting binary, NOT necessarily all its methods
|
||||
# and fields. If you want to refer to all methods and fields, you can
|
||||
# write class.* as an abbreviation.
|
||||
#
|
||||
# - Abbreviations for packages are also possible: my/package/* means all
|
||||
# methods and fields of all classes in my/package.
|
||||
#
|
||||
# - A line with a trailing '\' continues in the next line.
|
||||
|
||||
# end of file
|
||||
@@ -0,0 +1,46 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||
<!-- package.html - describes classes in java.nio package.
|
||||
Copyright (C) 2002 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. -->
|
||||
|
||||
<html>
|
||||
<head><title>GNU Classpath - java.nio</title></head>
|
||||
|
||||
<body>
|
||||
<p>Abstract classes for manipulating buffers of different primitive types.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user