Coverage Report - com.ccg.macros.OutputWriter
 
Classes in this File Line Coverage Branch Coverage Complexity
OutputWriter
56% 
100% 
1.143
 
 1  
 /*----------------------------------------------------------------
 2  
  * $Id: OutputWriter.java,v 1.1.1.1 2004/01/26 20:46:18 pkb Exp $
 3  
  * 
 4  
  * (c)2000 - Paul Blankenbaker
 5  
  *
 6  
  * Revision Log
 7  
  * 
 8  
  *  2000-11-16 11:31:37        Paul Blankenbaker 
 9  
  * 
 10  
  *         Created initial version
 11  
  */
 12  
 //----------------------------------------------------------------
 13  
 
 14  
 package com.ccg.macros;
 15  
 
 16  
 import java.io.*;                // needed for I/O operations
 17  
 
 18  
 //----------------------------------------------------------------
 19  
 /** Describe...
 20  
  * 
 21  
  * <code><pre>
 22  
  * class Example {
 23  
  *   public void main(String[] args) {
 24  
  *     com.ccg.macros.OutputWriter o = new com.ccg.macros.OutputWriter();
 25  
  *           System.out.println(o);
 26  
  *   }
 27  
  * }
 28  
  * </pre></code>
 29  
  * 
 30  
  * @version $Revision: 1.1.1.1 $
 31  
  * 
 32  
  * @since 1.0
 33  
  * 
 34  
  * @author $Author: pkb $
 35  
  * 
 36  
  * @see Output */
 37  
 //----------------------------------------------------------------
 38  
 
 39  
 public class OutputWriter implements Output {
 40  
 
 41  
   //----------------------------------------------------------------
 42  
   /** Create a {@link Output Output} object which uses a {@link Writer
 43  
    * Writer} to write the results of interpretation to.
 44  
    *
 45  
    * @param        out
 46  
    * 
 47  
    *         {@link Writer Writer} to write interpretted results to.
 48  
    * 
 49  
    * @since        1.0 */
 50  
   //----------------------------------------------------------------
 51  
 
 52  
 
 53  0
   public OutputWriter(Writer out) {
 54  0
     _out = out;
 55  0
   }
 56  
 
 57  
 
 58  
 
 59  
   //----------------------------------------------------------------
 60  
   /** Create a {@link Output Output} object which uses a {@link
 61  
    * OutputStream OutputStream} to write the results of interpretation
 62  
    * to.
 63  
    *
 64  
    * @param        out
 65  
    * 
 66  
    *         Output stream to write interpretted results to.
 67  
    * 
 68  
    * @since        1.0 */
 69  
   //----------------------------------------------------------------
 70  
 
 71  2
   public OutputWriter(OutputStream out) {
 72  2
     _out = new OutputStreamWriter(out);
 73  2
   }
 74  
 
 75  
   public OutputWriter(File f) throws IOException {
 76  0
     this(new BufferedWriter(new FileWriter(f)));
 77  0
   }
 78  
 
 79  
   public void close() throws IOException {
 80  2
     _out.close();
 81  2
   }
 82  
 
 83  
   public void flush() throws IOException {
 84  0
     _out.flush();
 85  0
   }
 86  
 
 87  
 
 88  
   //----------------------------------------------------------------
 89  
   /** Writes a set of characters from a buffer to the output.
 90  
    * 
 91  
    * This method is used by macro processors (such as the {@link
 92  
    * AtMacros AtMacros} class) to send a set of characters to the
 93  
    * output device (string, file, etc).
 94  
    * 
 95  
    * @param        buf
 96  
    * 
 97  
    *         A character array to take the data from (must not be null)
 98  
    * 
 99  
    * @param        ofs
 100  
    * 
 101  
    *         Offset into the buffer to the first character to start the
 102  
    *         copy from. Should be in the range of [0,buf.length-1].
 103  
    * 
 104  
    * @param        len
 105  
    * 
 106  
    *         How many characters to copy. When added to the offset, the
 107  
    *         resulting value should not exceed the length of the array.
 108  
    * 
 109  
    * @throws        IOException
 110  
    * 
 111  
    *         If a I/O error is encountered.
 112  
    * 
 113  
    * @since        1.0 */
 114  
   //----------------------------------------------------------------
 115  
 
 116  
   public void write(char[] buf, int ofs, int len) throws IOException {
 117  150
     _out.write(buf,ofs,len);
 118  150
   }
 119  
 
 120  
 
 121  
   //----------------------------------------------------------------
 122  
   /** Outputs the {@link java.lang.String string} representation of a {@link java.lang.Object Object}.
 123  
    * 
 124  
    * This method is used by macro processors (such as the {@link
 125  
    * AtMacros AtMacros} class) to cause the {@link java.lang.String
 126  
    * string} representation of a {@link java.lang.Object Object} to be
 127  
    * sent to the output device.
 128  
    * 
 129  
    * @param        object
 130  
    * 
 131  
    *         The object to write out (the {@link java.lang.Object#toString
 132  
    *         toString()} method is used to write out the string
 133  
    *         representation of the object). You may pass null (in which
 134  
    *         case nothing will be done).
 135  
    * 
 136  
    * @throws        IOException
 137  
    * 
 138  
    *         If a I/O error is encountered.
 139  
    * 
 140  
    * @since        1.0 */
 141  
   //----------------------------------------------------------------
 142  
 
 143  
   public void write(Object o) throws IOException {
 144  84
     if (o != null) _out.write(o.toString());
 145  84
   }
 146  
 
 147  
 
 148  
   //----------------------------------------------------------------  
 149  
   // private data
 150  
   //----------------------------------------------------------------
 151  
 
 152  
   private transient Writer _out;
 153  
 
 154  
 }