All Downloads are FREE. Search and download functionalities are using the official Maven repository.

at.spardat.xma.serializer.BinaryDeserializer Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 * Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     s IT Solutions AT Spardat GmbH - initial API and implementation
 *******************************************************************************/

//@(#) $Id: BinaryDeserializer.java 2089 2007-11-28 13:56:13Z s3460 $
package at.spardat.xma.serializer;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;

import at.spardat.enterprise.exc.SysException;

/**
 * Deserializer implementation that uses the Java Serialization Mechanism
 * 
 * @author YSD, 11.02.2005  
 */
public class BinaryDeserializer implements Deserializer {

    // used to read the construction time provided byte array
    private ByteArrayInputStream            bin_;

    /**
     * the instance variable seen by objects implementing Synchronization.internalize.
     */
    public ObjectInput                      objIn_;
    
    
    /**
     * Constructor
     * 
     * @param data    serialized array of data 
     * @param length  first length bytes in data are used.
     */
    public BinaryDeserializer (byte[] data, int length) {
        this (data, 0, length);
    }
    
    /**
     * Constructor
     * 
     * @param data    serialized array of data 
     */
    public BinaryDeserializer (byte[] data) {
        this (data, 0, data.length);
    }
    
    /**
     * Constructor
     * 
     * @param data   input array
     * @param offset offset in the array where data starts
     * @param length number of bytes 
     */
    public BinaryDeserializer (byte[] data, int offset, int length) {
        try {
            bin_ = new ByteArrayInputStream (data, offset, length);
            objIn_ = new ObjectInputStream (bin_);
        } catch (IOException x) {
            throw new SysException (x);
        }        
    }

    /**
     * @see at.spardat.xma.serializer.XmaInput#readString()
     */
    public String readString() throws IOException {
        return objIn_.readUTF();
    }
    
    /**
     * @see at.spardat.xma.serializer.XmaInput#readStringN()
     */
    public String readStringN() throws IOException {
        boolean isNull = objIn_.readBoolean();
        if (!isNull) return objIn_.readUTF();
        else return null;
    }

    /**
     * @see at.spardat.xma.serializer.XmaInput#readInt()
     */
    public int readInt() throws IOException {
        return objIn_.readInt();
    }
    
    /**
     * @see at.spardat.xma.serializer.XmaInput#readLong()
     */
    public long readLong() throws IOException {
        return objIn_.readLong();
    }

    /**
     * @see at.spardat.xma.serializer.XmaInput#readShort()
     */
    public short readShort() throws IOException {
        return objIn_.readShort();
    }

    /**
     * @see at.spardat.xma.serializer.XmaInput#readBoolean()
     */
    public boolean readBoolean() throws IOException {
        return objIn_.readBoolean();
    }

    /**
     * @see at.spardat.xma.serializer.XmaInput#readByte()
     */
    public byte readByte() throws IOException {
        return objIn_.readByte();
    }
    
    /**
     * @see at.spardat.xma.serializer.XmaInput#readSerializedBytes()
     */
    public byte[] readSerializedBytes() throws IOException {
        int         len = objIn_.readInt();
        byte[] result = new byte[len];
        for (int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy