/*
 * @(#)TerminalType.java
 *
 * Copyright (c) 2003 JSCAPE
 * 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * JSCAPE. ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with
 * the terms of the license agreement you entered into with JSCAPE.
 */
package com.jscape.inet.telnet.options;

import com.jscape.inet.telnet.Telnet;
import com.jscape.inet.telnet.TelnetOption;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * Represents the TERMINAL TYPE Telnet option as defined in RFC 1091.  This option is used for negotiation
 * of display options with the server.
 * <p/>
 * Example:
 * <p/>
 * TerminalType term = new TerminalType("dumb"); *
 *
 * @author vglass
 */
public class TerminalType
        extends TelnetOption {
    private String terminalType = null;

    /**
     * Creates a new TerminalType instance.
     */
    public TerminalType() {
        optionCode = 24;
    }

    /**
     * Creates a new TerminalType instance.
     *
     * @param terminalType the terminal type
     */
    public TerminalType(String terminalType) {
        this();
        this.terminalType = terminalType;
    }

    /**
     * Writes subnegotiation data for this TelnetOption.
     *
     * @param out the OutputStream to write data to.
     *
     * @throws IOException if an I/O related error occurs.
     */
    public void writeSubnegotiation(OutputStream out)
            throws IOException {
        out.write(Telnet.TSC_NULL);
        out.write(terminalType.getBytes());
    }

    /**
     * Reads subnegotiation data for this TelnetOption
     *
     * @param in the InputStream to read from
     *
     * @throws IOException if an I/O related error occurs
     */
    public void readSubnegotiation(InputStream in)
            throws IOException {
    }

    /**
     * Gets the terminal type.
     *
     * @return terminal type
     */
    public String getTerminalType() {
        return terminalType;
    }

    /**
     * Sets the terminal type.
     *
     * @param terminalType the terminal type
     */
    public void setTerminalType(String terminalType) {
        this.terminalType = terminalType;
    }

}
