001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.flatfile;
018
019import java.io.IOException;
020import java.io.InputStream;
021import java.io.OutputStream;
022import java.io.Serializable;
023
024/**
025 * Represents a record or field.
026 * @version $Revision: 758023 $ $Date: 2009-03-24 16:09:19 -0500 (Tue, 24 Mar 2009) $
027 */
028public interface Entity extends Cloneable, Serializable {
029    /**
030     * Get the length of this Entity.
031     * @return int
032     */
033    int length();
034
035    /**
036     * Read value from an InputStream.
037     * @param is to read
038     * @throws IOException on error
039     */
040    void readFrom(InputStream is) throws IOException;
041
042    /**
043     * Write value to an OutputStream.
044     * @param os to write to
045     * @throws IOException on error
046     */
047    void writeTo(OutputStream os) throws IOException;
048
049    /**
050     * Clone oneself.
051     * @return a deep (or otherwise "safe") copy of this Entity.
052     */
053    Entity clone();
054
055    /**
056     * Fill this entity's value with all <code>b</code>.
057     * @param b value
058     * @throws IOException on error
059     */
060    void fill(byte b) throws IOException;
061
062    /**
063     * Get the value of this Entity.
064     * @return byte[]
065     */
066    byte[] getValue();
067
068    /**
069     * Get a subset of this Entity's value.
070     * @param offset to start
071     * @param length to extend
072     * @return byte[]
073     */
074    byte[] getValue(int offset, int length);
075
076    /**
077     * Set this Entity's value.
078     * @param b byte[]
079     */
080    void setValue(byte[] b);
081
082    /**
083     * Set this Entity's value to a subset of the specified byte[].
084     * @param b byte[]
085     * @param offset int
086     * @param length int
087     */
088    void setValue(byte[] b, int offset, int length);
089}