FileDocCategorySizeDatePackage
Recorder.javaAPI DocExample1388Thu Nov 08 00:23:28 GMT 2001com.ora.rmibook.chapter2.sockets

Recorder

public class Recorder extends Object

Fields Summary
public static final int
DEFAULT_WRITE_GAP
private int
_numberOfBytes
private int
_lastRecordedNumberOfBytes
private int
_recordingDifferential
private String
_fileName
Constructors Summary
public Recorder(String fileName)


       
        this (fileName, DEFAULT_WRITE_GAP);
    
public Recorder(String fileName, int recordingDifferential)

        _recordingDifferential = recordingDifferential;
        _numberOfBytes = 0;
        _lastRecordedNumberOfBytes = 0;
        _fileName = fileName;
    
Methods Summary
public voidflush()

        log();
        _lastRecordedNumberOfBytes = _numberOfBytes;
    
public voidincrementCounter(int numberOfbytes)

        _numberOfBytes += numberOfbytes;
        if (_recordingDifferential < (_numberOfBytes - _lastRecordedNumberOfBytes)) {
            flush();
        }
    
private voidlog()

        try {
            OutputStream outputStream = new FileOutputStream(_fileName);
            PrintWriter writer = new PrintWriter(outputStream);

            writer.println(_numberOfBytes + " have been sent through the stream");
        } catch (Exception e) {
            System.out.println("Log failure with exception\n" + e);
            e.printStackTrace();
        }