1
2
3
4
5 package com.jguild.jrpm.io.datatype;
6
7 import java.io.DataInputStream;
8 import java.io.IOException;
9
10 import com.jguild.jrpm.io.IndexEntry;
11 import com.jguild.jrpm.io.constant.RPMIndexType;
12
13 /***
14 * Factory to create rpm data types
15 *
16 * @author kuss
17 */
18 public class TypeFactory {
19
20 public static BIN createBIN(byte data[]) {
21 return new BIN(data);
22 }
23
24 public static CHAR createCHAR(char data[]) {
25 return new CHAR(data);
26 }
27
28 public static I18NSTRING createI18NSTRING(String str[]) {
29 return new I18NSTRING(str);
30 }
31
32 public static INT8 createINT8(byte data[]) {
33 return new INT8(data);
34 }
35
36 public static INT16 createINT16(short data[]) {
37 return new INT16(data);
38 }
39
40 public static INT32 createINT32(int data[]) {
41 return new INT32(data);
42 }
43
44 public static INT64 createINT64(long data[]) {
45 return new INT64(data);
46 }
47
48 public static NULL createNULL(int size) {
49 return new NULL(size);
50 }
51
52 public static STRING createSTRING(String str) {
53 return new STRING(str);
54 }
55
56 public static STRING_ARRAY createSTRING_ARRAY(String str[]) {
57 return new STRING_ARRAY(str);
58 }
59
60 /***
61 * This method creates a rpm data type out of a input stream and an
62 * IndexEntry. The object must at the current position of the input stream.
63 * The length is only needed for string objects; the string objects will
64 * read length bytes of the input stream and will try to convert the data
65 * into a rpm data type.
66 *
67 * @param inputStream
68 * The input stream
69 * @param indexEntry
70 * The IndexEntry that should be read
71 * @param length
72 * The number of bytes to read for string objects
73 *
74 * @return One of the rpm data types coresponding with the type contained
75 * in the IndexEntry.
76 *
77 * @throws IOException
78 * if something was wrong during reading of the input stream
79 */
80 public static DataTypeIf createFromStream(DataInputStream inputStream,
81 IndexEntry indexEntry, long length) throws IOException {
82 DataTypeIf ret = null;
83
84 switch ((int) indexEntry.getType().getId()) {
85 case RPMIndexType._NULL:
86 ret = NULL.readFromStream(indexEntry);
87
88 break;
89
90 case RPMIndexType._CHAR:
91 ret = CHAR.readFromStream(inputStream, indexEntry);
92
93 break;
94
95 case RPMIndexType._INT8:
96 ret = INT8.readFromStream(inputStream, indexEntry);
97
98 break;
99
100 case RPMIndexType._INT16:
101 ret = INT16.readFromStream(inputStream, indexEntry);
102
103 break;
104
105 case RPMIndexType._INT32:
106 ret = INT32.readFromStream(inputStream, indexEntry);
107
108 break;
109
110 case RPMIndexType._INT64:
111 ret = INT64.readFromStream(inputStream, indexEntry);
112
113 break;
114
115 case RPMIndexType._STRING:
116 ret = STRING.readFromStream(inputStream, indexEntry, length);
117
118 break;
119
120 case RPMIndexType._BIN:
121 ret = BIN.readFromStream(inputStream, indexEntry);
122
123 break;
124
125 case RPMIndexType._STRING_ARRAY:
126 ret = STRING_ARRAY.readFromStream(inputStream, indexEntry, length);
127
128 break;
129
130 case RPMIndexType._I18NSTRING:
131 ret = I18NSTRING.readFromStream(inputStream, indexEntry, length);
132
133 break;
134
135 default:
136
137 }
138
139 return ret;
140 }
141 }