01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package com.sun.midp.publickeystore;
28:
29: import java.io.*;
30:
31: /**
32: * Write fields to an OutputStream.
33: */
34: class OutputStorage extends Storage {
35: /** stream to write to */
36: private DataOutputStream out;
37:
38: /**
39: * Constructs an OutputStorage for an OutputStream.
40: * @param output the output storage output stream.
41: * @exception IOException if the storage version cannot be written
42: */
43: OutputStorage(OutputStream output) throws IOException {
44: out = new DataOutputStream(output);
45:
46: out.writeByte(CURRENT_VERSION);
47: }
48:
49: /**
50: * Stores a byte array field as tag, BINARY_TYPE, value.
51: * @param tag number to unique to this field
52: * @param value value of field
53: */
54: void writeValue(byte tag, byte[] value) throws IOException {
55: out.writeByte(tag);
56: out.writeByte(BINARY_TYPE);
57:
58: /*
59: * must write our own length, because DataOutputStream does not handle
60: * handle byte arrays.
61: */
62: out.writeShort(value.length);
63: out.write(value);
64: }
65:
66: /**
67: * Stores a String field as tag, STRING_TYPE, value.
68: * @param tag number to unique to this field
69: * @param value value of field
70: */
71: void writeValue(byte tag, String value) throws IOException {
72: out.writeByte(tag);
73: out.writeByte(STRING_TYPE);
74: out.writeUTF(value);
75: }
76:
77: /**
78: * Stores a long field as tag, LONG_TYPE, value.
79: * @param tag number to unique to this field
80: * @param value value of field
81: */
82: void writeValue(byte tag, long value) throws IOException {
83: out.writeByte(tag);
84: out.writeByte(LONG_TYPE);
85: out.writeLong(value);
86: }
87:
88: /**
89: * Stores a boolean field as tag, BOOLEAN_TYPE, value.
90: * @param tag number to unique to this field
91: * @param value value of field
92: */
93: void writeValue(byte tag, boolean value) throws IOException {
94: out.writeByte(tag);
95: out.writeByte(BOOLEAN_TYPE);
96: out.writeBoolean(value);
97: }
98: }
|