public void write(char[] cbuf, int off, int len) throws IOException {
        int nextOff;
        startProcess();
        nextOff = off;
        for (int i = off; i < off + len; i += 1) {
            if (cbuf[i] == '\n') {
                _displayIn.write(cbuf, nextOff, i - nextOff + 1);
                _displayIn.flush();
                nextOff = i + 1;
                try {
                    switch (_responseQueue.take()) {
                    case OK:
                        break;
                    case ERROR:
                        close();
                        throw new IOException("Postscript error");
                    case QUIT:
                        close();
                        throw new IOException("Viewer program terminated");
                    default:
                        assert false : "Statement should not be reached.";
                    }
                } catch (InterruptedException e) {
                    assert false : "Unexpected exception";
                }
            }
        }
        if (nextOff < off + len) {
            _displayIn.write(cbuf, nextOff, off + len - nextOff);
        }
    }