/[classpath]/classpath/gnu/java/nio/DoubleBufferImpl.java
ViewVC logotype

Diff of /classpath/gnu/java/nio/DoubleBufferImpl.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.14 by mkoch, Tue Mar 11 11:48:51 2003 UTC revision 1.15 by mkoch, Mon May 19 08:36:27 2003 UTC
# Line 1  Line 1 
1  /* DoubleBufferImpl.java --  /* DoubleBufferImpl.java --
2     Copyright (C) 2002 Free Software Foundation, Inc.     Copyright (C) 2002, 2003 Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 35  this exception to your version of the li Line 35  this exception to your version of the li
35  obligated to do so.  If you do not wish to do so, delete this  obligated to do so.  If you do not wish to do so, delete this
36  exception statement from your version. */  exception statement from your version. */
37    
38    
39  package gnu.java.nio;  package gnu.java.nio;
40    
41  import java.nio.ByteBuffer;  import java.nio.ByteBuffer;
# Line 48  import java.nio.ReadOnlyBufferException; Line 49  import java.nio.ReadOnlyBufferException;
49  public final class DoubleBufferImpl extends DoubleBuffer  public final class DoubleBufferImpl extends DoubleBuffer
50  {  {
51    private boolean readOnly;    private boolean readOnly;
     
   public DoubleBufferImpl(int cap, int off, int lim)  
   {  
     super (cap, lim, off, 0);  
     this.backing_buffer = new double[cap];  
     readOnly = false;  
   }  
     
   public DoubleBufferImpl(double[] array, int offset, int length)  
   {  
     super (array.length, length, offset, 0);  
     this.backing_buffer = array;  
     readOnly = false;  
   }  
52    
53    public DoubleBufferImpl(DoubleBufferImpl copy)    public DoubleBufferImpl (int capacity)
54    {    {
55      super (copy.capacity (), copy.limit (), copy.position (), 0);      this (new double [capacity], 0, capacity, capacity, 0, -1, false);
     backing_buffer = copy.backing_buffer;  
     readOnly = copy.isReadOnly ();  
56    }    }
57        
58    DoubleBufferImpl (byte[] copy)    public DoubleBufferImpl (double[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly)
59    {    {
60      super (copy.length, copy.length, 0, 0);      super (buffer, offset, capacity, limit, position, mark);
61      this.backing_buffer = copy != null ? nio_cast (copy) : null;      this.readOnly = readOnly;
     readOnly = false;  
62    }    }
63      
   private static native byte nio_get_Byte (DoubleBufferImpl b, int index, int limit);  
   
   private static native void nio_put_Byte (DoubleBufferImpl b, int index, int limit, byte value);  
   
   public ByteBuffer asByteBuffer ()  
   {  
     ByteBufferImpl res = new ByteBufferImpl (backing_buffer);  
     res.limit ((limit () * 1) / 8);  
     return res;  
   }  
   
   private static native double[] nio_cast (byte[] copy);  
   
64    public boolean isReadOnly ()    public boolean isReadOnly ()
65    {    {
66      return readOnly;      return readOnly;
67    }    }
68      
69    public DoubleBuffer slice ()    public DoubleBuffer slice ()
70    {    {
71      return new DoubleBufferImpl (this);      return new DoubleBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ());
72    }    }
73      
74    public DoubleBuffer duplicate()    public DoubleBuffer duplicate ()
75    {    {
76      return new DoubleBufferImpl(this);      return new DoubleBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ());
77    }    }
78      
79    public DoubleBuffer asReadOnlyBuffer()    public DoubleBuffer asReadOnlyBuffer ()
80    {    {
81      DoubleBufferImpl result = new DoubleBufferImpl (this);      return new DoubleBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true);
     result.readOnly = true;  
     return result;  
82    }    }
83      
84    public DoubleBuffer compact()    public DoubleBuffer compact ()
85    {    {
86        int copied = 0;
87        
88        while (remaining () > 0)
89          {
90            put (copied, get ());
91            copied++;
92          }
93    
94        position (copied);
95      return this;      return this;
96    }    }
97      
98    public boolean isDirect()    public boolean isDirect ()
99    {    {
100      return false;      return false;
101    }    }
102    
103    final public double get()    /**
104       * Relative get method. Reads the next <code>double</code> from the buffer.
105       */
106      final public double get ()
107    {    {
108      double e = backing_buffer[position()];      double result = backing_buffer [position ()];
109      position(position()+1);      position (position () + 1);
110      return e;      return result;
111    }    }
112      
113    final public DoubleBuffer put(double b)    /**
114       * Relative put method. Writes <code>value</code> to the next position
115       * in the buffer.
116       *
117       * @exception ReadOnlyBufferException If this buffer is read-only.
118       */
119      final public DoubleBuffer put (double value)
120    {    {
121      if (readOnly)      if (readOnly)
122        throw new ReadOnlyBufferException ();        throw new ReadOnlyBufferException ();
123                            
124      backing_buffer[position()] = b;      backing_buffer [position ()] = value;
125      position(position()+1);      position (position () + 1);
126      return this;      return this;
127    }    }
128      
129    final public double get(int index)    /**
130       * Absolute get method. Reads the <code>double</code> at position
131       * <code>index</code>.
132       *
133       * @exception IndexOutOfBoundsException If index is negative or not smaller
134       * than the buffer's limit.
135       */
136      final public double get (int index)
137    {    {
138      return backing_buffer[index];      return backing_buffer [index];
139    }    }
140      
141    final public DoubleBuffer put(int index, double b)    /**
142       * Absolute put method. Writes <code>value</value> to position
143       * <code>index</code> in the buffer.
144       *
145       * @exception IndexOutOfBoundsException If index is negative or not smaller
146       * than the buffer's limit.
147       * @exception ReadOnlyBufferException If this buffer is read-only.
148       */
149      final public DoubleBuffer put (int index, double value)
150    {    {
151      if (readOnly)      if (readOnly)
152        throw new ReadOnlyBufferException ();        throw new ReadOnlyBufferException ();
153                    
154      backing_buffer[index] = b;      backing_buffer [index] = value;
155      return this;      return this;
156    }    }
157        
158    final public ByteOrder order ()    final public ByteOrder order ()
159    {    {
160      return ByteOrder.BIG_ENDIAN;      return ByteOrder.nativeOrder ();
161    }    }
162  }  }

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26