Content of buffer.java extracted from proxy.jar
package proxy; import java.io.*; // // La classe buffer viene utilizzata fra client e server per // il trasferimento dei messaggi // // versione 0.2: aggiunto il metodo delete // versione 0.3: aggiunti i metodi insert che accettano stringhe public class buffer { static int bufsize = 2048; byte buf[] = new byte[bufsize]; int size = 0; // clear: azzera il buffer public void clear () { size = 0; }; // delete: elimina gli <n> elementi a partire da <pos> public void delete (int pos, int n) { size -= n; System.arraycopy(buf,pos+n,buf,pos,size); }; // insert: inserisce nuovi dati nel buffer public void insert (byte b) { buf[size++] = b; }; public void insert (byte b[]) { System.arraycopy(b,0,buf,size,b.length); size += b.length; }; public void insert (String s) { insert(s.getBytes()); }; public void insert (int pos, byte b[]) { System.arraycopy(buf,pos,buf,pos+b.length,size - pos); System.arraycopy(b,0,buf,pos,b.length); size += b.length; }; public void insert (int pos, String s) { insert(pos, s.getBytes()); }; public void insert (buffer b) { System.arraycopy(b.buf,0,buf,size,b.size); size += b.size; }; // readStream: legge il buffer da uno stream // attenzione: readStream sovrascrive eventuali dati gia' presenti nel buffer public int readStream (InputStream in) throws IOException { return(size = in.read(buf)); }; // writeStream: scrive il buffer in uno stream public void writeStream (OutputStream out) throws IOException { out.write(buf, 0, size); }; // print: stampa il contenuto del buffer public void print () { for (int i=0; i < size; i++){ System.out.println(buf[i]); }; }; // toString: converte il buffer in String public String toString() { return new String(buf, 0, size); }; };