OSDN Git Service

53592d482e5ead806fe361117a0e10b9cbb554e8
[mikutoga/TogaGem.git] / src / main / java / jp / sourceforge / mikutoga / xml / BasicXmlExporter.java
1 /*
2  * basic xml exporter
3  *
4  * License : The MIT License
5  * Copyright(c) 2010 MikuToga Partners
6  */
7
8 package jp.sourceforge.mikutoga.xml;
9
10 import java.io.Closeable;
11 import java.io.Flushable;
12 import java.io.IOException;
13
14 /**
15  * Appendable用XMLエクスポータ実装。
16  */
17 public class BasicXmlExporter extends AbstractXmlExporter{
18
19     private Appendable appendable = null;
20
21
22     /**
23      * コンストラクタ。
24      */
25     public BasicXmlExporter(){
26         super();
27         return;
28     }
29
30
31     /**
32      * 出力先アペンダを指定する。
33      * @param app 出力先
34      * @throws NullPointerException 引数がnull
35      */
36     public void setAppendable(Appendable app) throws NullPointerException{
37         if(app == null) throw new NullPointerException();
38
39         this.appendable = app;
40
41         return;
42     }
43
44     /**
45      * {@inheritDoc}
46      * @param ch {@inheritDoc}
47      * @return {@inheritDoc}
48      * @throws IOException {@inheritDoc}
49      */
50     @Override
51     public Appendable append(char ch) throws IOException{
52         return this.appendable.append(ch);
53     }
54
55     /**
56      * {@inheritDoc}
57      * @param seq {@inheritDoc}
58      * @return {@inheritDoc}
59      * @throws IOException {@inheritDoc}
60      */
61     @Override
62     public Appendable append(CharSequence seq) throws IOException{
63         return this.appendable.append(seq);
64     }
65
66     /**
67      * {@inheritDoc}
68      * @param seq {@inheritDoc}
69      * @param start {@inheritDoc}
70      * @param end {@inheritDoc}
71      * @return {@inheritDoc}
72      * @throws IOException {@inheritDoc}
73      */
74     @Override
75     public Appendable append(CharSequence seq, int start, int end)
76             throws IOException{
77         return this.appendable.append(seq, start, end);
78     }
79
80     /**
81      * {@inheritDoc}
82      * 可能であれば出力をフラッシュする。
83      * @throws IOException {@inheritDoc}
84      */
85     @Override
86     public void flush() throws IOException{
87         if(this.appendable instanceof Flushable){
88             ((Flushable)this.appendable).flush();
89         }
90         return;
91     }
92
93     /**
94      * {@inheritDoc}
95      * 可能であれば出力をクローズする。
96      * @throws IOException {@inheritDoc}
97      */
98     @Override
99     public void close() throws IOException{
100         if(this.appendable instanceof Closeable){
101             ((Closeable)this.appendable).close();
102         }
103         return;
104     }
105
106 }