1 21 22 package org.apache.derby.impl.services.stream; 23 24 import org.apache.derby.iapi.services.stream.HeaderPrintWriter; 25 import org.apache.derby.iapi.services.stream.PrintWriterGetHeader; 26 27 import java.io.PrintWriter ; 28 import java.io.Writer ; 29 import java.io.OutputStream ; 30 31 39 class BasicHeaderPrintWriter 40 extends PrintWriter 41 implements HeaderPrintWriter 42 { 43 44 private final PrintWriterGetHeader headerGetter; 45 private final boolean canClose; 46 private final String name; 47 48 50 60 BasicHeaderPrintWriter(OutputStream writeTo, 61 PrintWriterGetHeader headerGetter, boolean canClose, String streamName){ 62 super(writeTo, true); 63 this.headerGetter = headerGetter; 64 this.canClose = canClose; 65 this.name = streamName; 66 } 67 68 78 BasicHeaderPrintWriter(Writer writeTo, 79 PrintWriterGetHeader headerGetter, boolean canClose, String writerName){ 80 super(writeTo, true); 81 this.headerGetter = headerGetter; 82 this.canClose = canClose; 83 this.name = writerName; 84 } 85 86 90 public synchronized void printlnWithHeader(String message) 91 { 92 print(headerGetter.getHeader()); 93 println(message); 94 } 95 96 public PrintWriterGetHeader getHeader() 97 { 98 return headerGetter; 99 } 100 101 public PrintWriter getPrintWriter(){ 102 return this; 103 } 104 105 public String getName(){ 106 return name; 107 } 108 109 113 114 void complete() { 115 flush(); 116 if (canClose) { 117 close(); 118 } 119 } 120 } 121 122 | Popular Tags |