View Javadoc

1   /*
2    * Copyright (c) 2006-2007 Creative Sphere Limited.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v10.html
7    *
8    * Contributors:
9    *
10   *   Creative Sphere - initial API and implementation
11   *
12   */
13  package org.abstracthorizon.danube.http.util;
14  
15  import java.io.OutputStream;
16  import java.io.PrintWriter;
17  import java.io.UnsupportedEncodingException;
18  import java.nio.charset.IllegalCharsetNameException;
19  
20  public class EncodingPrintWrtier extends PrintWriter {
21  
22      protected BufferlessOutputStreamWriter cachedOut;
23  
24      public EncodingPrintWrtier(OutputStream outputStream, String encoding) throws IllegalCharsetNameException, UnsupportedEncodingException {
25          super(new BufferlessOutputStreamWriter(outputStream, encoding));
26          cachedOut = (BufferlessOutputStreamWriter)out;
27      }
28  
29      public void close() {
30          super.close();
31      }
32  
33      public void resetInternals() {
34          out = cachedOut;
35      }
36  
37      public void setEncoding(String encoding) throws UnsupportedEncodingException, IllegalCharsetNameException {
38          cachedOut.setEncoding(encoding);
39      }
40  
41      public String getEcoding() {
42          return cachedOut.getEncoding();
43      }
44  }