View Javadoc

1   package fr.in2p3.jsaga.impl.buffer;
2   
3   import org.ogf.saga.SagaObject;
4   import org.ogf.saga.buffer.Buffer;
5   import org.ogf.saga.error.*;
6   
7   /* ***************************************************
8   * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
9   * ***             http://cc.in2p3.fr/             ***
10  * ***************************************************
11  * File:   ImplementationAllocatedBufferImpl
12  * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
13  * Date:   16 sept. 2007
14  * ***************************************************
15  * Description:                                      */
16  /**
17   *
18   */
19  public class ImplementationAllocatedBufferImpl extends AbstractBufferImpl implements Buffer {
20      /** constructor */
21      public ImplementationAllocatedBufferImpl(int size) throws BadParameterException, NoSuccessException {
22          super();
23          this.setSize(size);
24      }
25  
26      /** clone: copy buffer content */
27      public SagaObject clone() throws CloneNotSupportedException {
28          ImplementationAllocatedBufferImpl clone = (ImplementationAllocatedBufferImpl) super.clone();
29          if (m_buffer != null) {
30              clone.m_buffer = new byte[m_buffer.length];
31              System.arraycopy(m_buffer, 0, clone.m_buffer, 0, m_buffer.length);
32          } else {
33              clone.m_buffer = null;
34          }
35          return clone;
36      }
37  
38      public void setSize(int size) throws BadParameterException, NoSuccessException {
39          if (size > -1) {
40              m_buffer = new byte[size];
41          } else {
42              throw new BadParameterException("You must specify either the buffer or its size");
43          }
44      }
45  
46      public void setSize() throws BadParameterException, NoSuccessException {
47          if (m_buffer != null) {
48              m_buffer = new byte[m_buffer.length];
49          } else {
50              throw new BadParameterException("You must specify either the buffer or its size");
51          }
52      }
53  
54      public void setData(byte[] data) throws BadParameterException, IncorrectStateException, NoSuccessException {
55          throw new IncorrectStateException("Not allowed to change the byte[] of an implementation-allocated buffer", this);
56      }
57  }