2003-08-02 Michael Koch <konqueror@gmx.de>
* java/nio/ByteBufferImpl.java (getChar): Check remaining bytes, fixed comment about endianess. (putChar): Likewise. (getShort): Likewise. (putShort): Likewise. (getInt): Check remaining bytes, fixed conversion, fixed comment about endianess. (putInt): Likewise. (getLong): Likewise. (putLong): Likewise. (getFloat): Likewise. (putFloat): Likewise. (getDouble): Likewise. (putDouble): Likewise. * java/nio/DirectByteBufferImpl.java (getChar): Wrapped code, fixed comment about endianess. (putchar): Likewise. (getShort): Likewise. (putShort): Likewise. (getInt): Fixed conversion, fixed comment about endianess. (putInt): Likewise. (getLong): Likewise. (putLong): Likewise. (getFloat): Likewise. (putFloat): Likewise. (getDouble): Likewise. (putDouble): Likewise. * java/nio/MappedByteBufferImpl.java (compact): Implemented. (getChar): Implemented. (putChar): Implemented. (getDouble): Implemented. (putdouble): Implemented. (getFloat): Implemented. (putFloat): Implemented. (getInt): Implemented. (putInt): Implemented. (getLong): Implemented. (putLong): Implemented. (getShort): Implemented. (putShort): Implemented. * java/nio/channels/FileChannelImpl.java (read): Set position where to access file. (write): Likewise. (transferTo): Flip buffer after read and before write. (transferFrom): Likewise. From-SVN: r70102
This commit is contained in:
committed by
Michael Koch
parent
2937079664
commit
7318eb21d1
@@ -182,13 +182,20 @@ final class ByteBufferImpl extends ByteBuffer
|
||||
|
||||
final public char getChar ()
|
||||
{
|
||||
// FIXME: this handles big endian only
|
||||
return (char) (((get () & 0xff) << 8) + (get () & 0xff));
|
||||
if (remaining() < 2)
|
||||
throw new BufferUnderflowException();
|
||||
|
||||
// FIXME: this handles little endian only
|
||||
return (char) (((get () & 0xff) << 8)
|
||||
+ (get () & 0xff));
|
||||
}
|
||||
|
||||
final public ByteBuffer putChar (char value)
|
||||
{
|
||||
// FIXME: this handles big endian only
|
||||
if (remaining() < 2)
|
||||
throw new BufferOverflowException();
|
||||
|
||||
// FIXME: this handles little endian only
|
||||
put ((byte) ((((int) value) & 0xff00) >> 8));
|
||||
put ((byte) (((int) value) & 0x00ff));
|
||||
return this;
|
||||
@@ -196,13 +203,18 @@ final class ByteBufferImpl extends ByteBuffer
|
||||
|
||||
final public char getChar (int index)
|
||||
{
|
||||
// FIXME: this handles big endian only
|
||||
if (remaining() < 2)
|
||||
throw new BufferUnderflowException();
|
||||
|
||||
// FIXME: this handles little endian only
|
||||
return (char) (((get (index) & 0xff) << 8) + (get (index + 1) & 0xff));
|
||||
}
|
||||
|
||||
final public ByteBuffer putChar (int index, char value)
|
||||
{
|
||||
// FIXME: this handles big endian only
|
||||
if (remaining() < 2)
|
||||
throw new BufferOverflowException();
|
||||
// FIXME: this handles little endian only
|
||||
put (index, (byte) ((((int) value) & 0xff00) >> 8));
|
||||
put (index + 1, (byte) (((int) value) & 0x00ff));
|
||||
return this;
|
||||
@@ -210,13 +222,19 @@ final class ByteBufferImpl extends ByteBuffer
|
||||
|
||||
final public short getShort ()
|
||||
{
|
||||
// FIXME: this handles big endian only
|
||||
if (remaining() < 2)
|
||||
throw new BufferUnderflowException();
|
||||
|
||||
// FIXME: this handles little endian only
|
||||
return (short) (((get () & 0xff) << 8) + (get () & 0xff));
|
||||
}
|
||||
|
||||
final public ByteBuffer putShort (short value)
|
||||
{
|
||||
// FIXME: this handles big endian only
|
||||
if (remaining() < 2)
|
||||
throw new BufferOverflowException();
|
||||
|
||||
// FIXME: this handles little endian only
|
||||
put ((byte) ((((int) value) & 0xff00) >> 8));
|
||||
put ((byte) (((int) value) & 0x00ff));
|
||||
return this;
|
||||
@@ -224,13 +242,19 @@ final class ByteBufferImpl extends ByteBuffer
|
||||
|
||||
final public short getShort (int index)
|
||||
{
|
||||
// FIXME: this handles big endian only
|
||||
if (remaining() < 2)
|
||||
throw new BufferUnderflowException();
|
||||
|
||||
// FIXME: this handles little endian only
|
||||
return (short) (((get (index) & 0xff) << 8) + (get (index + 1) & 0xff));
|
||||
}
|
||||
|
||||
final public ByteBuffer putShort (int index, short value)
|
||||
{
|
||||
// FIXME: this handles big endian only
|
||||
if (remaining() < 2)
|
||||
throw new BufferOverflowException();
|
||||
|
||||
// FIXME: this handles little endian only
|
||||
put (index, (byte) ((((int) value) & 0xff00) >> 8));
|
||||
put (index + 1, (byte) (((int) value) & 0x00ff));
|
||||
return this;
|
||||
@@ -238,58 +262,76 @@ final class ByteBufferImpl extends ByteBuffer
|
||||
|
||||
final public int getInt ()
|
||||
{
|
||||
// FIXME: this handles big endian only
|
||||
if (remaining() < 4)
|
||||
throw new BufferUnderflowException();
|
||||
|
||||
// FIXME: this handles little endian only
|
||||
return (int) (((get () & 0xff) << 24)
|
||||
+ (get () & 0xff) << 16
|
||||
+ (get () & 0xff) << 8
|
||||
+ ((get () & 0xff) << 16)
|
||||
+ ((get () & 0xff) << 8)
|
||||
+ (get () & 0xff));
|
||||
}
|
||||
|
||||
final public ByteBuffer putInt (int value)
|
||||
{
|
||||
// FIXME: this handles big endian only
|
||||
put ((byte) ((((int) value) & 0xff000000) >> 24));
|
||||
put ((byte) ((((int) value) & 0x00ff0000) >> 16));
|
||||
put ((byte) ((((int) value) & 0x0000ff00) >> 8));
|
||||
put ((byte) (((int) value) & 0x000000ff));
|
||||
if (remaining() < 4)
|
||||
throw new BufferOverflowException();
|
||||
|
||||
// FIXME: this handles little endian only
|
||||
put ((byte) ((value & 0xff000000) >> 24));
|
||||
put ((byte) ((value & 0x00ff0000) >> 16));
|
||||
put ((byte) ((value & 0x0000ff00) >> 8));
|
||||
put ((byte) (value & 0x000000ff));
|
||||
return this;
|
||||
}
|
||||
|
||||
final public int getInt (int index)
|
||||
{
|
||||
// FIXME: this handles big endian only
|
||||
if (remaining() < 4)
|
||||
throw new BufferUnderflowException();
|
||||
|
||||
// FIXME: this handles little endian only
|
||||
return (int) (((get (index) & 0xff) << 24)
|
||||
+ (get (index + 1) & 0xff) << 16
|
||||
+ (get (index + 2) & 0xff) << 8
|
||||
+ ((get (index + 1) & 0xff) << 16)
|
||||
+ ((get (index + 2) & 0xff) << 8)
|
||||
+ (get (index + 3) & 0xff));
|
||||
}
|
||||
|
||||
final public ByteBuffer putInt (int index, int value)
|
||||
{
|
||||
// FIXME: this handles big endian only
|
||||
put (index, (byte) ((((int) value) & 0xff000000) >> 24));
|
||||
put (index + 1, (byte) ((((int) value) & 0x00ff0000) >> 16));
|
||||
put (index + 2, (byte) ((((int) value) & 0x0000ff00) >> 8));
|
||||
put (index + 3, (byte) (((int) value) & 0x000000ff));
|
||||
if (remaining() < 4)
|
||||
throw new BufferOverflowException();
|
||||
|
||||
// FIXME: this handles little endian only
|
||||
put (index, (byte) ((value & 0xff000000) >> 24));
|
||||
put (index + 1, (byte) ((value & 0x00ff0000) >> 16));
|
||||
put (index + 2, (byte) ((value & 0x0000ff00) >> 8));
|
||||
put (index + 3, (byte) (value & 0x000000ff));
|
||||
return this;
|
||||
}
|
||||
|
||||
final public long getLong ()
|
||||
{
|
||||
// FIXME: this handles big endian only
|
||||
if (remaining() < 8)
|
||||
throw new BufferUnderflowException();
|
||||
|
||||
// FIXME: this handles little endian only
|
||||
return (long) (((get () & 0xff) << 56)
|
||||
+ (get () & 0xff) << 48
|
||||
+ (get () & 0xff) << 40
|
||||
+ (get () & 0xff) << 32
|
||||
+ (get () & 0xff) << 24
|
||||
+ (get () & 0xff) << 16
|
||||
+ (get () & 0xff) << 8
|
||||
+ ((get () & 0xff) << 48)
|
||||
+ ((get () & 0xff) << 40)
|
||||
+ ((get () & 0xff) << 32)
|
||||
+ ((get () & 0xff) << 24)
|
||||
+ ((get () & 0xff) << 16)
|
||||
+ ((get () & 0xff) << 8)
|
||||
+ (get () & 0xff));
|
||||
}
|
||||
|
||||
final public ByteBuffer putLong (long value)
|
||||
{
|
||||
// FIXME: this handles big endian only
|
||||
if (remaining() < 8)
|
||||
throw new BufferOverflowException();
|
||||
|
||||
// FIXME: this handles little endian only
|
||||
put ((byte) ((value & 0xff00000000000000L) >> 56));
|
||||
put ((byte) ((value & 0x00ff000000000000L) >> 48));
|
||||
put ((byte) ((value & 0x0000ff0000000000L) >> 40));
|
||||
@@ -303,20 +345,26 @@ final class ByteBufferImpl extends ByteBuffer
|
||||
|
||||
final public long getLong (int index)
|
||||
{
|
||||
// FIXME: this handles big endian only
|
||||
if (remaining() < 8)
|
||||
throw new BufferUnderflowException();
|
||||
|
||||
// FIXME: this handles little endian only
|
||||
return (long) (((get (index) & 0xff) << 56)
|
||||
+ (get (index + 1) & 0xff) << 48
|
||||
+ (get (index + 2) & 0xff) << 40
|
||||
+ (get (index + 3) & 0xff) << 32
|
||||
+ (get (index + 4) & 0xff) << 24
|
||||
+ (get (index + 5) & 0xff) << 16
|
||||
+ (get (index + 6) & 0xff) << 8
|
||||
+ ((get (index + 1) & 0xff) << 48)
|
||||
+ ((get (index + 2) & 0xff) << 40)
|
||||
+ ((get (index + 3) & 0xff) << 32)
|
||||
+ ((get (index + 4) & 0xff) << 24)
|
||||
+ ((get (index + 5) & 0xff) << 16)
|
||||
+ ((get (index + 6) & 0xff) << 8)
|
||||
+ (get (index + 7) & 0xff));
|
||||
}
|
||||
|
||||
final public ByteBuffer putLong (int index, long value)
|
||||
{
|
||||
// FIXME: this handles big endian only
|
||||
if (remaining() < 8)
|
||||
throw new BufferOverflowException();
|
||||
|
||||
// FIXME: this handles little endian only
|
||||
put (index, (byte) ((value & 0xff00000000000000L) >> 56));
|
||||
put (index + 1, (byte) ((value & 0x00ff000000000000L) >> 48));
|
||||
put (index + 2, (byte) ((value & 0x0000ff0000000000L) >> 40));
|
||||
@@ -330,16 +378,22 @@ final class ByteBufferImpl extends ByteBuffer
|
||||
|
||||
final public float getFloat ()
|
||||
{
|
||||
// FIXME: this handles big endian only
|
||||
if (remaining() < 4)
|
||||
throw new BufferUnderflowException();
|
||||
|
||||
// FIXME: this handles little endian only
|
||||
return (float) (((get () & 0xff) << 24)
|
||||
+ (get () & 0xff) << 16
|
||||
+ (get () & 0xff) << 8
|
||||
+ ((get () & 0xff) << 16)
|
||||
+ ((get () & 0xff) << 8)
|
||||
+ (get () & 0xff));
|
||||
}
|
||||
|
||||
final public ByteBuffer putFloat (float value)
|
||||
{
|
||||
// FIXME: this handles big endian only
|
||||
if (remaining() < 4)
|
||||
throw new BufferOverflowException();
|
||||
|
||||
// FIXME: this handles little endian only
|
||||
put ((byte) ((((int) value) & 0xff000000) >> 24));
|
||||
put ((byte) ((((int) value) & 0x00ff0000) >> 16));
|
||||
put ((byte) ((((int) value) & 0x0000ff00) >> 8));
|
||||
@@ -349,16 +403,22 @@ final class ByteBufferImpl extends ByteBuffer
|
||||
|
||||
final public float getFloat (int index)
|
||||
{
|
||||
// FIXME: this handles big endian only
|
||||
if (remaining() < 4)
|
||||
throw new BufferUnderflowException();
|
||||
|
||||
// FIXME: this handles little endian only
|
||||
return (float) (((get (index) & 0xff) << 24)
|
||||
+ (get (index + 1) & 0xff) << 16
|
||||
+ (get (index + 2) & 0xff) << 8
|
||||
+ ((get (index + 1) & 0xff) << 16)
|
||||
+ ((get (index + 2) & 0xff) << 8)
|
||||
+ (get (index + 3) & 0xff));
|
||||
}
|
||||
|
||||
final public ByteBuffer putFloat (int index, float value)
|
||||
{
|
||||
// FIXME: this handles big endian only
|
||||
if (remaining() < 4)
|
||||
throw new BufferOverflowException();
|
||||
|
||||
// FIXME: this handles little endian only
|
||||
put (index, (byte) ((((int) value) & 0xff000000) >> 24));
|
||||
put (index + 1, (byte) ((((int) value) & 0x00ff0000) >> 16));
|
||||
put (index + 2, (byte) ((((int) value) & 0x0000ff00) >> 8));
|
||||
@@ -368,20 +428,26 @@ final class ByteBufferImpl extends ByteBuffer
|
||||
|
||||
final public double getDouble ()
|
||||
{
|
||||
// FIXME: this handles big endian only
|
||||
if (remaining() < 8)
|
||||
throw new BufferUnderflowException();
|
||||
|
||||
// FIXME: this handles little endian only
|
||||
return (double) (((get () & 0xff) << 56)
|
||||
+ (get () & 0xff) << 48
|
||||
+ (get () & 0xff) << 40
|
||||
+ (get () & 0xff) << 32
|
||||
+ (get () & 0xff) << 24
|
||||
+ (get () & 0xff) << 16
|
||||
+ (get () & 0xff) << 8
|
||||
+ ((get () & 0xff) << 48)
|
||||
+ ((get () & 0xff) << 40)
|
||||
+ ((get () & 0xff) << 32)
|
||||
+ ((get () & 0xff) << 24)
|
||||
+ ((get () & 0xff) << 16)
|
||||
+ ((get () & 0xff) << 8)
|
||||
+ (get () & 0xff));
|
||||
}
|
||||
|
||||
final public ByteBuffer putDouble (double value)
|
||||
{
|
||||
// FIXME: this handles big endian only
|
||||
if (remaining() < 8)
|
||||
throw new BufferOverflowException();
|
||||
|
||||
// FIXME: this handles little endian only
|
||||
put ((byte) ((((long) value) & 0xff00000000000000L) >> 56));
|
||||
put ((byte) ((((long) value) & 0x00ff000000000000L) >> 48));
|
||||
put ((byte) ((((long) value) & 0x0000ff0000000000L) >> 40));
|
||||
@@ -395,20 +461,26 @@ final class ByteBufferImpl extends ByteBuffer
|
||||
|
||||
final public double getDouble (int index)
|
||||
{
|
||||
// FIXME: this handles big endian only
|
||||
if (remaining() < 8)
|
||||
throw new BufferUnderflowException();
|
||||
|
||||
// FIXME: this handles little endian only
|
||||
return (double) (((get (index) & 0xff) << 56)
|
||||
+ (get (index + 1) & 0xff) << 48
|
||||
+ (get (index + 2) & 0xff) << 40
|
||||
+ (get (index + 3) & 0xff) << 32
|
||||
+ (get (index + 4) & 0xff) << 24
|
||||
+ (get (index + 5) & 0xff) << 16
|
||||
+ (get (index + 6) & 0xff) << 8
|
||||
+ ((get (index + 1) & 0xff) << 48)
|
||||
+ ((get (index + 2) & 0xff) << 40)
|
||||
+ ((get (index + 3) & 0xff) << 32)
|
||||
+ ((get (index + 4) & 0xff) << 24)
|
||||
+ ((get (index + 5) & 0xff) << 16)
|
||||
+ ((get (index + 6) & 0xff) << 8)
|
||||
+ (get (index + 7) & 0xff));
|
||||
}
|
||||
|
||||
final public ByteBuffer putDouble (int index, double value)
|
||||
{
|
||||
// FIXME: this handles big endian only
|
||||
if (remaining() < 8)
|
||||
throw new BufferOverflowException();
|
||||
|
||||
// FIXME: this handles little endian only
|
||||
put (index, (byte) ((((long) value) & 0xff00000000000000L) >> 56));
|
||||
put (index + 1, (byte) ((((long) value) & 0x00ff000000000000L) >> 48));
|
||||
put (index + 2, (byte) ((((long) value) & 0x0000ff0000000000L) >> 40));
|
||||
|
||||
Reference in New Issue
Block a user