Name: rmT116609 Date: 08/07/2001 java version "1.4.0-beta" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65) Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode) The ByteBuffer class defines methods that can create views of a given ByteBuffer such as: CharBuffer ByteBuffer.asCharBuffer() DoubleBuffer ByteBuffer.asDoubleBuffer() LongBuffer ByteBuffer.asLongBuffer() ... etc. Why is there no corresponding method in the view buffer classes to create a ByteBuffer view? ByteBuffer CharBuffer.asByteBuffer() ByteBuffer DoubleBuffer.asByteBuffer() ByteBuffer LongBuffer.asByteBuffer() ... etc. The nio class Channel only has methods for IO using ByteBuffer so the only way I can see to write a DoubleBuffer is to 'copy' it into a ByteBuffer. I can see no utility in the method DoubleBuffer.wrap(double[] array) if I cannot write the newly created DoubleBuffer. Ideally I would like to create a ByteBuffer view of a DoubleBuffer and/or be able to write a DoubleBuffer directly via a Channel method. Another possiblity would be additonal wrap methods in ByteBuffer such as: ByteBuffer ByteBuffer.wrap(char[] array) ByteBuffer ByteBuffer.wrap(double[] array) ByteBuffer ByteBuffer.wrap(long[] array) ... etc. I am developing an application that must process very large amounts of both numerical and text data. Because this data will not all fit in memory I must stage this data in TEMPORARY files while I process it. This requires that I write and reread this data during processing (potentially many times). I feel it is unnecessary to add the additional overhead of byteswapping for numerical data or Unicode encoding/decoding for text data for a temporary file read/write. For instance: I see no way using nio to write a Unicode string to disk without incurring substantial overhead. I can create a CharBuffer by wrapping a String but I cannot write a CharBuffer. I could use CharsetDecoder to decode the String into a ByteBuffer, write it, and then read it back using CharsetEncoder but the overhead is substantial for use in a temporary storage situation. The same holds true for other primitive types. I can create a DoubleBuffer by wrapping a double[] but I cannot write a DoubleBuffer, ... etc. I propose a simple solution, add the following static methods to ByteBuffer: ByteBuffer ByteBuffer.wrap(String) ByteBuffer ByteBuffer.wrap(char[]) ByteBuffer ByteBuffer.wrap(double[]) ByteBuffer ByteBuffer.wrap(float[]) ByteBuffer ByteBuffer.wrap(long[]) ByteBuffer ByteBuffer.wrap(int[]) ByteBuffer ByteBuffer.wrap(short[]) (Review ID: 129561) ======================================================================
|