1 /*
2 * SSHTools - Java SSH2 API
3 *
4 * Copyright (C) 2002-2003 Lee David Painter and Contributors.
5 *
6 * Contributions made by:
7 *
8 * Brett Smith
9 * Richard Pernavas
10 * Erwin Bolwidt
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 */
26 /**
27 * SSHTools - Java SSH API The contents of this package has been derived from
28 * the TelnetD library available from http://sourceforge.net/projects/telnetd
29 * The original license of the source code is as follows: TelnetD library
30 * (embeddable telnet daemon) Copyright (C) 2000 Dieter Wimberger This library
31 * is free software; you can either redistribute it and/or modify it under the
32 * terms of the GNU Lesser General Public License version 2.1,1999 as
33 * published by the Free Software Foundation (see copy received along with the
34 * library), or under the terms of the BSD-style license received along with
35 * this library.
36 */
37 package com.sshtools.daemon.terminal;
38
39 import java.util;
40
41
42 class CharBuffer {
43 //Members
44 private Vector myBuffer;
45 private int mySize;
46
47 /**
48 * Creates a new CharBuffer object.
49 *
50 * @param size
51 */
52 public CharBuffer(int size) {
53 myBuffer = new Vector(size);
54 mySize = size;
55 }
56
57 //constructor
58 public char getCharAt(int pos) throws IndexOutOfBoundsException {
59 return ((Character) myBuffer.elementAt(pos)).charValue();
60 }
61
62 //getCharAt
63 public void setCharAt(int pos, char ch) throws IndexOutOfBoundsException {
64 myBuffer.setElementAt(new Character(ch), pos);
65 }
66
67 //setCharAt
68 public void insertCharAt(int pos, char ch)
69 throws BufferOverflowException, IndexOutOfBoundsException {
70 myBuffer.insertElementAt(new Character(ch), pos);
71 }
72
73 //insertCharAt
74 public void append(char aChar) throws BufferOverflowException {
75 myBuffer.addElement(new Character(aChar));
76 }
77
78 //append
79 public void removeCharAt(int pos) throws IndexOutOfBoundsException {
80 myBuffer.removeElementAt(pos);
81 }
82
83 //removeCharAt
84 public void clear() {
85 myBuffer.removeAllElements();
86 }
87
88 //clear
89 public int size() {
90 return myBuffer.size();
91 }
92
93 //size
94 public String toString() {
95 StringBuffer sbuf = new StringBuffer();
96
97 for (int i = 0; i < myBuffer.size(); i++) {
98 sbuf.append(((Character) myBuffer.elementAt(i)).charValue());
99 }
100
101 return sbuf.toString();
102 }
103
104 //toString
105 public void ensureSpace(int chars) throws BufferOverflowException {
106 if (chars > (mySize - myBuffer.size())) {
107 throw new BufferOverflowException();
108 }
109 }
110
111 //ensureSpace
112 }
113
114
115 //class CharBuffer