KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nightlabs > editor2d > iofilter > XMLFilter


1 /* *****************************************************************************
2  * NightLabs Editor2D - Graphical editor framework *
3  * Copyright (C) 2004-2005 NightLabs - http://NightLabs.org *
4  * *
5  * This library is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or (at your option) any later version. *
9  * *
10  * This library is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13  * Lesser General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU Lesser General Public *
16  * License along with this library; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin St, Fifth Floor, *
19  * Boston, MA 02110-1301 USA *
20  * *
21  * Or get it online : *
22  * http://www.gnu.org/copyleft/lesser.html *
23  * *
24  * *
25  ******************************************************************************/

26
27 package org.nightlabs.editor2d.iofilter;
28
29 import java.beans.XMLDecoder JavaDoc;
30 import java.beans.XMLEncoder JavaDoc;
31 import java.io.BufferedInputStream JavaDoc;
32 import java.io.BufferedOutputStream JavaDoc;
33 import java.io.InputStream JavaDoc;
34 import java.io.OutputStream JavaDoc;
35
36 import org.nightlabs.io.AbstractIOFilter;
37 import org.nightlabs.io.ReadException;
38 import org.nightlabs.io.WriteException;
39
40 public class XMLFilter
41 extends AbstractIOFilter
42 {
43     public static final String JavaDoc XML_FILE_EXTENSION = "xml";
44         
45     public XMLFilter()
46     {
47         setFileExtension(XML_FILE_EXTENSION);
48         setDescription("XML File Filter Description");
49     }
50     
51     public Object JavaDoc read(InputStream JavaDoc in)
52     throws ReadException
53     {
54         XMLDecoder JavaDoc decoder = new XMLDecoder JavaDoc(new BufferedInputStream JavaDoc(in));
55         Object JavaDoc o = decoder.readObject();
56         decoder.close();
57         return o;
58     }
59
60     public void write(Object JavaDoc o, OutputStream JavaDoc out)
61     throws WriteException
62     {
63         XMLEncoder JavaDoc encoder = new XMLEncoder JavaDoc(new BufferedOutputStream JavaDoc(out));
64         encoder.writeObject(o);
65         encoder.close();
66     }
67
68 }
69
Popular Tags