Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/jguild/jrpm/io/datatype/NULL.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 org.apache.log4j.Logger;
11  
12  import java.io.DataInputStream;
13  import java.io.IOException;
14  
15  
16  /**
17   * A representation of a rpm null array data object
18   *
19   * @author kuss
20   */
21  public class NULL implements DataTypeIf {
22      private static final Logger logger = Logger.getLogger(NULL.class);
23      private Object[] data;
24      private long size;
25  
26      /*
27       * @see com.jguild.jrpm.io.datatype.DataTypeIf#isArray()
28       */
29      public boolean isArray() {
30          return true;
31      }
32  
33      /**
34       * Get the rpm NULL array as a java object array of null objects
35       *
36       * @return An array of null objects
37       */
38      public Object[] getData() {
39          return data;
40      }
41  
42      /*
43       * @see com.jguild.jrpm.io.datatype.DataTypeIf#getData()
44       */
45      public Object getDataObject() {
46          return data;
47      }
48  
49      /*
50       * @see com.jguild.jrpm.io.datatype.DataTypeIf#getSize()
51       */
52      public long getSize() {
53          return size;
54      }
55  
56      /*
57       * @see com.jguild.jrpm.io.datatype.DataTypeIf#getType()
58       */
59      public RPMIndexType getType() {
60          return RPMIndexType.NULL;
61      }
62  
63      /**
64       * Constructs a type froma stream
65       *
66       * @param inputStream An input stream
67       * @param indexEntry The index informations
68       * @return The size of the read data
69       */
70      public static NULL readFromStream(DataInputStream inputStream, IndexEntry indexEntry)
71          throws IOException {
72          if (indexEntry.getType() != RPMIndexType.NULL) {
73              throw new IllegalArgumentException("Type <" + indexEntry.getType() + "> does not match <" + RPMIndexType.NULL + ">");
74          }
75  
76          NULL nullObject = new NULL();
77          nullObject.data = new Object[(int) indexEntry.getCount()];
78  
79          if (logger.isDebugEnabled()) {
80              logger.debug(nullObject.toString());
81          }
82  
83          nullObject.size = indexEntry.getType().getSize() * indexEntry.getCount();
84  
85          return nullObject;
86      }
87  
88      /*
89       * @see com.jguild.jrpm.io.datatype.DataTypeIf#getElementCount()
90       */
91      public long getElementCount() {
92          return data.length;
93      }
94  
95      /*
96       * @see com.jguild.jrpm.io.datatype.DataTypeIf#get(int)
97       */
98      public Object get(int i) {
99          return data[i];
100     }
101 
102     /*
103      * @see java.lang.Object#toString()
104      */
105     public String toString() {
106         StringBuffer buf = new StringBuffer();
107 
108         if (data.length > 1) {
109             buf.append("[");
110         }
111 
112         for (int pos = 0; pos < data.length; pos++) {
113             buf.append(data[pos]);
114 
115             if (pos < (data.length - 1)) {
116                 buf.append(", ");
117             }
118         }
119 
120         if (data.length > 1) {
121             buf.append("]");
122         }
123 
124         return buf.toString();
125     }
126 }