001: /*
002: * SSHTools - Java SSH2 API
003: *
004: * Copyright (C) 2002-2003 Lee David Painter and Contributors.
005: *
006: * Contributions made by:
007: *
008: * Brett Smith
009: * Richard Pernavas
010: * Erwin Bolwidt
011: *
012: * This program is free software; you can redistribute it and/or
013: * modify it under the terms of the GNU General Public License
014: * as published by the Free Software Foundation; either version 2
015: * of the License, or (at your option) any later version.
016: *
017: * This program is distributed in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: * GNU General Public License for more details.
021: *
022: * You should have received a copy of the GNU General Public License
023: * along with this program; if not, write to the Free Software
024: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
025: */
026: /**
027: * SSHTools - Java SSH API The contents of this package has been derived from
028: * the TelnetD library available from http://sourceforge.net/projects/telnetd
029: * The original license of the source code is as follows: TelnetD library
030: * (embeddable telnet daemon) Copyright (C) 2000 Dieter Wimberger This library
031: * is free software; you can either redistribute it and/or modify it under the
032: * terms of the GNU Lesser General Public License version 2.1,1999 as
033: * published by the Free Software Foundation (see copy received along with the
034: * library), or under the terms of the BSD-style license received along with
035: * this library.
036: */package com.sshtools.daemon.terminal;
037:
038: import java.util.*;
039:
040: class CharBuffer {
041: //Members
042: private Vector myBuffer;
043: private int mySize;
044:
045: /**
046: * Creates a new CharBuffer object.
047: *
048: * @param size
049: */
050: public CharBuffer(int size) {
051: myBuffer = new Vector(size);
052: mySize = size;
053: }
054:
055: //constructor
056: public char getCharAt(int pos) throws IndexOutOfBoundsException {
057: return ((Character) myBuffer.elementAt(pos)).charValue();
058: }
059:
060: //getCharAt
061: public void setCharAt(int pos, char ch)
062: throws IndexOutOfBoundsException {
063: myBuffer.setElementAt(new Character(ch), pos);
064: }
065:
066: //setCharAt
067: public void insertCharAt(int pos, char ch)
068: throws BufferOverflowException, IndexOutOfBoundsException {
069: myBuffer.insertElementAt(new Character(ch), pos);
070: }
071:
072: //insertCharAt
073: public void append(char aChar) throws BufferOverflowException {
074: myBuffer.addElement(new Character(aChar));
075: }
076:
077: //append
078: public void removeCharAt(int pos) throws IndexOutOfBoundsException {
079: myBuffer.removeElementAt(pos);
080: }
081:
082: //removeCharAt
083: public void clear() {
084: myBuffer.removeAllElements();
085: }
086:
087: //clear
088: public int size() {
089: return myBuffer.size();
090: }
091:
092: //size
093: public String toString() {
094: StringBuffer sbuf = new StringBuffer();
095:
096: for (int i = 0; i < myBuffer.size(); i++) {
097: sbuf
098: .append(((Character) myBuffer.elementAt(i))
099: .charValue());
100: }
101:
102: return sbuf.toString();
103: }
104:
105: //toString
106: public void ensureSpace(int chars) throws BufferOverflowException {
107: if (chars > (mySize - myBuffer.size())) {
108: throw new BufferOverflowException();
109: }
110: }
111:
112: //ensureSpace
113: }
114:
115: //class CharBuffer
|