KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hpsf > MutableProperty


1 /* ====================================================================
2    Copyright 2002-2004 Apache Software Foundation
3
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7
8        http://www.apache.org/licenses/LICENSE-2.0
9
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15 ==================================================================== */

16         
17 package org.apache.poi.hpsf;
18
19 import java.io.IOException JavaDoc;
20 import java.io.OutputStream JavaDoc;
21
22 /**
23  * <p>Adds writing capability to the {@link Property} class.</p>
24  *
25  * <p>Please be aware that this class' functionality will be merged into the
26  * {@link Property} class at a later time, so the API will change.</p>
27  *
28  * @author Rainer Klute <a
29  * HREF="mailto:klute@rainer-klute.de">&lt;klute@rainer-klute.de&gt;</a>
30  * @since 2003-08-03
31  * @version $Id: MutableProperty.java,v 1.6 2004/08/31 20:42:12 klute Exp $
32  */

33 public class MutableProperty extends Property
34 {
35
36     /**
37      * <p>Creates an empty property. It must be filled using the set method to
38      * be usable.</p>
39      */

40     public MutableProperty()
41     { }
42
43
44
45     /**
46      * <p>Creates a <code>MutableProperty</code> as a copy of an existing
47      * <code>Property</code>.</p>
48      *
49      * @param p The property to copy.
50      */

51     public MutableProperty(final Property p)
52     {
53         setID(p.getID());
54         setType(p.getType());
55         setValue(p.getValue());
56     }
57
58
59     /**
60      * <p>Sets the property's ID.</p>
61      *
62      * @param id the ID
63      */

64     public void setID(final long id)
65     {
66         this.id = id;
67     }
68
69
70
71     /**
72      * <p>Sets the property's type.</p>
73      *
74      * @param type the property's type
75      */

76     public void setType(final long type)
77     {
78         this.type = type;
79     }
80
81
82
83     /**
84      * <p>Sets the property's value.</p>
85      *
86      * @param value the property's value
87      */

88     public void setValue(final Object JavaDoc value)
89     {
90         this.value = value;
91     }
92
93
94
95     /**
96      * <p>Writes the property to an output stream.</p>
97      *
98      * @param out The output stream to write to.
99      * @param codepage The codepage to use for writing non-wide strings
100      * @return the number of bytes written to the stream
101      *
102      * @exception IOException if an I/O error occurs
103      * @exception WritingNotSupportedException if a variant type is to be
104      * written that is not yet supported
105      */

106     public int write(final OutputStream JavaDoc out, final int codepage)
107         throws IOException JavaDoc, WritingNotSupportedException
108     {
109         int length = 0;
110         long variantType = getType();
111
112         /* Ensure that wide strings are written if the codepage is Unicode. */
113         if (codepage == Constants.CP_UNICODE && variantType == Variant.VT_LPSTR)
114             variantType = Variant.VT_LPWSTR;
115
116         length += TypeWriter.writeUIntToStream(out, variantType);
117         length += VariantSupport.write(out, variantType, getValue(), codepage);
118         return length;
119     }
120
121 }
122
Popular Tags