Source code: com/jguild/jrpm/io/datatype/TypeFactory.java
1 /*
2 * jGuild Project: jRPM
3 * Released under the Apache License ( http://www.apache.org/LICENSE )
4 */
5 package com.jguild.jrpm.io.datatype;
6
7 import com.jguild.jrpm.io.IndexEntry;
8 import com.jguild.jrpm.io.constant.RPMIndexType;
9
10 import java.io.DataInputStream;
11 import java.io.IOException;
12
13
14 /**
15 * Factory to create rpm data types
16 *
17 * @author kuss
18 */
19 public class TypeFactory {
20 /**
21 * This method creates a rpm data type out of a input stream and an IndexEntry.
22 * The object must at the current position of the input stream. The length
23 * is only needed for string objects; the string objects will read length
24 * bytes of the input stream and will try to convert the data into a rpm
25 * data type.
26 *
27 * @param inputStream The input stream
28 * @param indexEntry The IndexEntry that should be read
29 * @param length The number of bytes to read for string objects
30 *
31 * @return One of the rpm data types coresponding with the type contained in the
32 * IndexEntry.
33 *
34 * @throws IOException if something was wrong during reading of the input stream
35 */
36 public static DataTypeIf createFromStream(DataInputStream inputStream, IndexEntry indexEntry, long length)
37 throws IOException {
38 DataTypeIf ret = null;
39
40 switch ((int) indexEntry.getType().getId()) {
41 case RPMIndexType._NULL:
42 ret = NULL.readFromStream(inputStream, indexEntry);
43
44 break;
45
46 case RPMIndexType._CHAR:
47 ret = CHAR.readFromStream(inputStream, indexEntry);
48
49 break;
50
51 case RPMIndexType._INT8:
52 ret = INT8.readFromStream(inputStream, indexEntry);
53
54 break;
55
56 case RPMIndexType._INT16:
57 ret = INT16.readFromStream(inputStream, indexEntry);
58
59 break;
60
61 case RPMIndexType._INT32:
62 ret = INT32.readFromStream(inputStream, indexEntry);
63
64 break;
65
66 case RPMIndexType._INT64:
67 ret = INT64.readFromStream(inputStream, indexEntry);
68
69 break;
70
71 case RPMIndexType._STRING:
72 ret = STRING.readFromStream(inputStream, indexEntry, length);
73
74 break;
75
76 case RPMIndexType._BIN:
77 ret = BIN.readFromStream(inputStream, indexEntry);
78
79 break;
80
81 case RPMIndexType._STRING_ARRAY:
82 ret = STRING_ARRAY.readFromStream(inputStream, indexEntry, length);
83
84 break;
85
86 case RPMIndexType._I18NSTRING:
87 ret = I18NSTRING.readFromStream(inputStream, indexEntry, length);
88
89 break;
90
91 default:
92 // TODO: UNKNOWN
93 }
94
95 return ret;
96 }
97 }