View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.flatfile;
18  
19  import java.io.IOException;
20  import java.io.InputStream;
21  import java.io.OutputStream;
22  import java.io.Serializable;
23  
24  /**
25   * Represents a record or field.
26   * @version $Revision: 758023 $ $Date: 2009-03-24 16:09:19 -0500 (Tue, 24 Mar 2009) $
27   */
28  public interface Entity extends Cloneable, Serializable {
29      /**
30       * Get the length of this Entity.
31       * @return int
32       */
33      int length();
34  
35      /**
36       * Read value from an InputStream.
37       * @param is to read
38       * @throws IOException on error
39       */
40      void readFrom(InputStream is) throws IOException;
41  
42      /**
43       * Write value to an OutputStream.
44       * @param os to write to
45       * @throws IOException on error
46       */
47      void writeTo(OutputStream os) throws IOException;
48  
49      /**
50       * Clone oneself.
51       * @return a deep (or otherwise "safe") copy of this Entity.
52       */
53      Entity clone();
54  
55      /**
56       * Fill this entity's value with all <code>b</code>.
57       * @param b value
58       * @throws IOException on error
59       */
60      void fill(byte b) throws IOException;
61  
62      /**
63       * Get the value of this Entity.
64       * @return byte[]
65       */
66      byte[] getValue();
67  
68      /**
69       * Get a subset of this Entity's value.
70       * @param offset to start
71       * @param length to extend
72       * @return byte[]
73       */
74      byte[] getValue(int offset, int length);
75  
76      /**
77       * Set this Entity's value.
78       * @param b byte[]
79       */
80      void setValue(byte[] b);
81  
82      /**
83       * Set this Entity's value to a subset of the specified byte[].
84       * @param b byte[]
85       * @param offset int
86       * @param length int
87       */
88      void setValue(byte[] b, int offset, int length);
89  }