/*
 * AbstractTextBinaryTypeDriver.java
 * 
 * (C) 28.02.2005 Markus Schaber, Logi-Track ag, CH 8001 Zuerich
 * 
 * $Id: $
 */
package org.postgresql.types;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.Date;
import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;

/** Should serve as a convenience base class for most TypeDrivers */
public abstract class AbstractTextBinaryTypeDriver extends AbstractTextTypeDriver
        implements
            TypeBinaryReader,
            TypeBinaryWriter {

    public boolean supportsBinaryWrite() {
        return true;
    }

    public boolean supportsBinaryReading() {
        return true;
    }

    // *** TypeBinaryReader methods ***
    public String getString(byte[] data, int start, int length) throws SQLException {
        throw new SQLException("Unknown type!");
    }

    public boolean getBoolean(byte[] data, int start, int length) throws SQLException {
        throw new SQLException("Unknown type!");
    }

    public byte getByte(byte[] data, int start, int length) throws SQLException {
        throw new SQLException("Unknown type!");
    }

    public short getShort(byte[] data, int start, int length) throws SQLException {
        throw new SQLException("Unknown type!");
    }

    public int getInt(byte[] data, int start, int length) throws SQLException {
        throw new SQLException("Unknown type!");
    }

    public long getLong(byte[] data, int start, int length) throws SQLException {
        throw new SQLException("Unknown type!");
    }

    public float getFloat(byte[] data, int start, int length) throws SQLException {
        throw new SQLException("Unknown type!");
    }

    public double getDouble(byte[] data, int start, int length) throws SQLException {
        throw new SQLException("Unknown type!");
    }

    public BigDecimal getBigDecimal(byte[] data, int start, int length) throws SQLException {
        throw new SQLException("Unknown type!");
    }

    public byte[] getBytes(byte[] data, int start, int length) throws SQLException {
        throw new SQLException("Unknown type!");
    }

    public Date getDate(byte[] data, int start, int length) throws SQLException {
        throw new SQLException("Unknown type!");
    }

    public Date getDate(byte[] data, int start, int length, Calendar cal) throws SQLException {
        throw new SQLException("Unknown type!");
    }

    public Time getTime(byte[] data, int start, int length) throws SQLException {
        throw new SQLException("Unknown type!");
    }

    public Time getTime(byte[] data, int start, int length, Calendar cal) throws SQLException {
        throw new SQLException("Unknown type!");
    }

    public Timestamp getTimestamp(byte[] data, int start, int length) throws SQLException {
        throw new SQLException("Unknown type!");
    }

    public Timestamp getTimestamp(byte[] data, int start, int length, Calendar cal)
            throws SQLException {
        throw new SQLException("Unknown type!");
    }

    public InputStream getAsciiStream(byte[] data, int start, int length) throws SQLException {
        throw new SQLException("Unknown type!");
    }

    public InputStream getUnicodeStream(byte[] data, int start, int length) throws SQLException {
        throw new SQLException("Unknown type!");
    }

    public InputStream getBinaryStream(byte[] data, int start, int length) throws SQLException {
        throw new SQLException("Unknown type!");
    }

    public Object getObject(byte[] data, int start, int length) throws SQLException {
        throw new SQLException("Unknown type!");
    }

    public Reader getCharacterStream(byte[] data, int start, int length) throws SQLException {
        throw new SQLException("Unknown type!");
    }

    public URL getURL(byte[] data, int start, int length) throws SQLException {
        throw new SQLException("Unknown type!");
    }

    // *** TypeBinaryWriter Methods ***
    public abstract int objectBytesLength(Object data) throws SQLException;

    public abstract void renderObject(Object data, byte[] target, int startindex);

    public void renderObject(Object data, OutputStream outstream) throws SQLException, IOException {
        byte[] temp = new byte[objectBytesLength(data)];
        renderObject(data, temp, 0);
        outstream.write(temp);
    }
}
