
org.objectweb.dream.serializator.ByteArrayChunk Maven / Gradle / Ivy
/**
* Dream
* Copyright (C) 2003-2004 INRIA Rhone-Alpes
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: [email protected]
*
* Initial developer(s): Vivien Quema
* Contributor(s):
*/
package org.objectweb.dream.serializator;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import org.objectweb.dream.message.AbstractChunk;
import org.objectweb.dream.util.Util;
/**
* Chunk containing a byte array.
*/
public class ByteArrayChunk extends AbstractChunk
{
private static final long serialVersionUID = 3977295521272901942L;
/** The default name for chunks of this type. */
public static final String DEFAULT_NAME = "byteArrayChunk";
/** The byte array. */
protected byte[] byteArray;
// ---------------------------------------------------------------------------
// Chunk methods
// ---------------------------------------------------------------------------
/**
* Returns the byte array contained in this chunk.
*
* @return the byte array contained in this chunk.
*/
public byte[] getByteArray()
{
return byteArray;
}
/**
* Sets the byte array contained in this chunk.
*
* @param byteArray the array contained in this chunk.
*/
public void setByteArray(byte[] byteArray)
{
this.byteArray = byteArray;
}
// ---------------------------------------------------------------------------
// Implementation of the Chunk interface
// ---------------------------------------------------------------------------
/**
* @see AbstractChunk#transfertStateTo(AbstractChunk)
*/
public void transfertStateTo(ByteArrayChunk newInstance)
{
newInstance.setByteArray(getByteArray());
}
/**
* @see AbstractChunk#newChunk()
*/
public ByteArrayChunk newChunk()
{
return new ByteArrayChunk();
}
/**
* @see org.objectweb.dream.pool.Recyclable#recycle()
*/
public void recycle()
{
byteArray = null;
}
// ---------------------------------------------------------------------------
// Implementation of the Externalizable interface
// ---------------------------------------------------------------------------
/**
* @see java.io.Externalizable#readExternal(java.io.ObjectInput)
*/
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException
{
byteArray = Util.readExternalByteArray(in);
}
/**
* @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
*/
public void writeExternal(ObjectOutput out) throws IOException
{
Util.writeExternalByteArray(out, byteArray);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy