[
http://issues.apache.org/jira/browse/HARMONY-26?page=comments#action_12363202 ]
Richard Liang commented on HARMONY-26:
--------------------------------------
Hello Tim,
There are several unnecessary fields/methods caused by the implementation
classes of NIO buffers being in a separate internal package com.ibm.io.nio. To
solve this issue, we can just move the implementation classes back to java.nio
and make them package private. I will describe details below. There are lots of
steps required to keep the code building right, if you prefer I can just send
the updated code. Let me know whether you are satisfied with our solution.
Thanks a lot.
1. Move all classes in com.ibm.io.nio *except* FileChannelImpl, FileLockImpl
and LockManager (total 35 classes) from com.ibm.io.nio into java.nio.
2. For the 35 moved classes, change their package statement from com.ibm.io.nio
to java.nio
3. For the 35 moved classes, remove the *unnecessary* import statements of
java.nio
4. For the 7 classes java.nio.ByteBuffer, CharBuffer, DoubleBuffer,
FloatBuffer, IntBuffer, LongBuffer, and
ShortBuffer, Remove the *unnecessary* import statement "import
com.ibm.io.nio.BufferFactory;"
**note** The above 4 steps can be conveniently achieved if you use "Refactor ->
move" in Eclipse.
5. Add a new interface in com.ibm.io.nio called DirectBuffer (I will attach the
file to JIRA)
6. Make java.nio.DirectByteBuffer to implement the new interface
com.ibm.io.nio.DirectBuffer by:
6.1 Adding import statement: import com.ibm.io.nio.DirectBuffer
6.2 Changing Class declaration from
"abstract class DirectByteBuffer extends BaseByteBuffer"
to
"abstract class DirectByteBuffer extends BaseByteBuffer implements
DirectBuffer"
7. Change the following "protected" methods of java.nio.DirectByteBuffer to
"public"
7.1 isAddressValid()
7.2 addressValidityCheck()
7.3 PlatformAddress getBaseAddress()
7.4 PlatformAddress getEffectiveAddress()
7.5 free()
8. In com.ibm.io.nio.FileChannelImpl:
8.1 Add import statement: "import java.nio.Buffer"
8.2 In method "public int read(ByteBuffer buffer)",
8.2.1 Change the line 270:
"DirectByteBuffer directBuffer = (DirectByteBuffer) buffer;"
to "DirectBuffer directBuffer = (DirectBuffer) buffer;"
8.2.2 Remove line 275:
"HeapByteBuffer heapBuffer = (HeapByteBuffer) buffer;"
8.2.3 Change the line 275 & 276:
"bytesRead = (int) fileSystem.read(handle, heapBuffer.array(),
heapBuffer.arrayOffset(), buffer.remaining());"
to "bytesRead = (int) fileSystem.read(handle, buffer.array(),
buffer.arrayOffset(), buffer.remaining());"
8.3 We do the same for the method "public int write(ByteBuffer buffer)",
8.3.1 Change the line 348:
"DirectByteBuffer directBuffer = (DirectByteBuffer) buffer;"
to "DirectBuffer directBuffer = (DirectBuffer) buffer;"
8.3.2 Remove line 353:
"HeapByteBuffer heapBuffer = (HeapByteBuffer) buffer;"
8.3.3 Change the line 353 & 354:
"bytesWritten = (int) fileSystem.write(handle, heapBuffer
.array(), heapBuffer.arrayOffset(), buffer.remaining());"
to "bytesWritten = (int) fileSystem.write(handle, buffer
.array(), buffer.arrayOffset(), buffer.remaining());"
9. Make java.nio.BufferFactory as package private by removing "public" at line
31
10. Make java.nio.DirectByteBuffer.SafeAddress as package private by removing
"protected" at line 39.
11. Make java.nio.DirectByteBuffers as package private by removing "public" at
line 27
12. Remove the "protected" modifier of the following fields:
java.nio.Buffer.UNSET_MARK
java.nio.Buffer.capacity
java.nio.Buffer.limit
java.nio.Buffer.mark
java.nio.Buffer.position
java.nio.ByteBuffer.order
java.nio.MappedByteBuffer.mapMode
java.nio.MappedByteBuffer.mappedFile
java.nio.MappedByteBuffer.offset
java.nio.MappedByteBuffer.wrappedBuffer
12. Remove the "protected" modifier of the constructor of java.nio.Buffer:
"protected Buffer(int capacity)"
13. For the classes java.nio.ByteBuffer, CharBuffer, DoubleBuffer, FloatBuffer,
IntBuffer, LongBuffer, ShortBuffer, remove the "protected" modifier of:
13.1 protected constructor
13.2 protected abstract byte[] protectedArray()
13.3 protected abstract int protectedArrayOffset()
13.4 protected abstract boolean protectedHasArray()
14. Remove the "protected" modifier of the following methods in
java.nio.MappedByteBuffer
protected MappedByteBuffer(File mappedFile, long offset, int size, MapMode
mapMode)
protected MappedByteBuffer(File mappedFile, long offset, int size, MapMode
mapMode, ByteBuffer wrappedBuffer)
15. Make the following field "final"
public ByteBuffer order(ByteOrder byteOrder) in java.nio.ByteBuffer
public CharBuffer put(char[] src) in java.nio.CharBuffer
16. Remove method "public ByteBuffer order(ByteOrder byteOrder)" in
java.nio.MappedToByteBufferAdapter (because this method is defined as "final"
in its super class java.nio.ByteBuffer)
> The API of buffer classes in java.nio are not compliant with the
> specification of Java 5.0
> ------------------------------------------------------------------------------------------
>
> Key: HARMONY-26
> URL: http://issues.apache.org/jira/browse/HARMONY-26
> Project: Harmony
> Type: Bug
> Components: Classlib
> Reporter: Richard Liang
> Assignee: Tim Ellison
>
> 1. java.nio.CharBuffer
> 1.1) java.nio.CharBuffer needs to implement two new interface
> java.lang.Appendable and java.lang.Readable
> 1.2) The following methods should NOT be "protected":
> protected CharBuffer(int capacity)
> protected abstract char[] protectedArray();
> protected abstract int protectedArrayOffset();
> protected abstract boolean protectedHasArray();
>
> 1.3) The following method should be "final":
> public CharBuffer put(char[] src)
>
> 2. java.nio.Buffer
> 2.1) The following fields should NOT be "protected":
> int UNSET_MARK
> int capacity
> int limit
> int mark should
> int position
> 2.3) The following method should NOT be "protected":
> protected Buffer(int capacity)
> 3. java.nio.ByteBuffer, DoubleBuffer, FloatBuffer, IntBuffer, LongBuffer,
> ShortBuffer
> 3.1) The following field should NOT be "protected":
> com.ibm.platform.Endianness order
> 3.2) The following methods should NOT be "protected":
> protected ByteBuffer(int capacity)
> protected abstract byte[] protectedArray();
> protected abstract int protectedArrayOffset();
> protected abstract boolean protectedHasArray();
> 3.3) The following method should be "final":
> public ByteBuffer order(ByteOrder byteOrder)
>
> 4. The implementation of bulk put/get methods of all the buffer classes are
> low-efficiency
>
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira