Debian Codegraph @

rhino/testsrc/tests/src/com/netscape/javascript/qa/drivers/TestLog.java

raw symbols SCIP
1 /* -*- Mode: java; tab-width: 8 -*-
2 * Copyright (C) 1997, 1998 Netscape Communications Corporation,
3 * All Rights Reserved.
4 */
5
6 package com.netscape.javascript.qa.drivers;
7
8 //import netscape.security.PrivilegeManager;
9 import java.io.*;
10
11 /**
12 * Class that writes and appends test result information to a file.
13 *
14 * @author [email protected]
15 *
16 */
17 public class TestLog {
18 private String name;
19 private ByteArrayOutputStream outputStream;
20 private PrintStream printStream;
21 private String terminator;
22
23 /**
24 * Create a new TestLog and open associated streams.
25 *
26 * @param name name of the log file
27 * @param terminator string that will be appended to the end of each line
28 *
29 *
30 */
31 public TestLog ( String name, String terminator ) {
32 this.name = name;
33 this.terminator = terminator;
34
35 openLog();
36 }
37
38 /**
39 * Write a string to the end TestLog file.
40 */
41 public void writeLine( String string ) {
42 if ( printStream != null ) {
43 printStream.println( string + terminator );
44 try {
45 RandomAccessFile raf = new RandomAccessFile( name, "rw" );
46 raf.seek( raf.length() );
47 raf.write( outputStream.toByteArray() );
48 raf.close();
49 outputStream.reset();
50 } catch ( Exception e ) {
51 System.out.println( "Exception writing to "+ name +".writeLine():"+ e );
52 }
53 }
54 }
55
56 /**
57 * Override if privileges are required to write to file system.
58 * The default implemenation does nothing.
59 */
60 public void enablePrivileges() {
61 return;
62 }
63
64 /**
65 * Close print stream associated with the TestLog file.
66 */
67 public void closeLog() {
68 if ( printStream != null ) {
69 printStream.close();
70 }
71 }
72 /**
73 * Create streams associated with this TestLog file.
74 */
75 public void openLog() {
76 enablePrivileges();
77 this.outputStream = new ByteArrayOutputStream();
78 this.printStream = new PrintStream( this.outputStream );
79 }
80
81 public String toString() {
82 return this.name;
83 }
84 }