1 | /* |
2 | |
3 | Derby - Class org.apache.derby.iapi.services.io.FormatableLongHolder |
4 | |
5 | Copyright 1999, 2004 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | package org.apache.derby.iapi.services.io; |
22 | |
23 | import org.apache.derby.iapi.services.io.ArrayInputStream; |
24 | |
25 | import org.apache.derby.iapi.services.io.FormatIdUtil; |
26 | import org.apache.derby.iapi.services.io.Formatable; |
27 | import org.apache.derby.iapi.services.io.StoredFormatIds; |
28 | |
29 | import java.io.ObjectOutput; |
30 | import java.io.ObjectInput; |
31 | import java.io.IOException; |
32 | |
33 | /** |
34 | * A formatable holder for an long. |
35 | */ |
36 | public class FormatableLongHolder implements Formatable |
37 | { |
38 | |
39 | // the int |
40 | private long theLong; |
41 | |
42 | /** |
43 | * Niladic constructor for formatable |
44 | */ |
45 | public FormatableLongHolder() |
46 | { |
47 | } |
48 | |
49 | /** |
50 | * Construct a FormatableLongHolder using the input integer. |
51 | * |
52 | * @param theLong the long to hold |
53 | */ |
54 | public FormatableLongHolder(long theLong) |
55 | { |
56 | this.theLong = theLong; |
57 | } |
58 | |
59 | /** |
60 | * Set the held long to the input int. |
61 | * |
62 | * @param theLong the int to hold |
63 | */ |
64 | public void setLong(int theLong) |
65 | { |
66 | this.theLong = theLong; |
67 | } |
68 | |
69 | /** |
70 | * Get the held int. |
71 | * |
72 | * @return The held int. |
73 | */ |
74 | public long getLong() |
75 | { |
76 | return theLong; |
77 | } |
78 | |
79 | /** |
80 | * Create and return an array of FormatableLongHolders |
81 | * given an array of ints. |
82 | * |
83 | * @param theLongs The array of longs |
84 | * |
85 | * @return An array of FormatableLongHolders |
86 | */ |
87 | public static FormatableLongHolder[] getFormatableLongHolders(long[] theLongs) |
88 | { |
89 | if (theLongs == null) |
90 | { |
91 | return null; |
92 | } |
93 | |
94 | FormatableLongHolder[] flhArray = new FormatableLongHolder[theLongs.length]; |
95 | |
96 | for (int index = 0; index < theLongs.length; index++) |
97 | { |
98 | flhArray[index] = new FormatableLongHolder(theLongs[index]); |
99 | } |
100 | return flhArray; |
101 | } |
102 | |
103 | ////////////////////////////////////////////// |
104 | // |
105 | // FORMATABLE |
106 | // |
107 | ////////////////////////////////////////////// |
108 | /** |
109 | * Write this formatable out |
110 | * |
111 | * @param out write bytes here |
112 | * |
113 | * @exception IOException thrown on error |
114 | */ |
115 | public void writeExternal(ObjectOutput out) throws IOException |
116 | { |
117 | out.writeLong(theLong); |
118 | } |
119 | |
120 | /** |
121 | * Read this formatable from a stream of stored objects. |
122 | * |
123 | * @param in read this. |
124 | * |
125 | * @exception IOException thrown on error |
126 | */ |
127 | public void readExternal(ObjectInput in) |
128 | throws IOException |
129 | { |
130 | theLong = in.readLong(); |
131 | } |
132 | public void readExternal(ArrayInputStream in) |
133 | throws IOException |
134 | { |
135 | theLong = in.readLong(); |
136 | } |
137 | |
138 | /** |
139 | * Get the formatID which corresponds to this class. |
140 | * |
141 | * @return the formatID of this class |
142 | */ |
143 | public int getTypeFormatId() { return StoredFormatIds.FORMATABLE_LONG_HOLDER_V01_ID; } |
144 | } |