(
DataOutput out,
Object val)
| 219 | } |
| 220 | |
| 221 | @SuppressWarnings("unchecked") |
| 222 | public static void writeDatum( |
| 223 | DataOutput out, |
| 224 | Object val) throws IOException { |
| 225 | // Read the data type |
| 226 | byte type = DataType.findType(val); |
| 227 | switch (type) { |
| 228 | case DataType.TUPLE: |
| 229 | Tuple t = (Tuple)val; |
| 230 | out.writeByte(DataType.TUPLE); |
| 231 | int sz = t.size(); |
| 232 | out.writeInt(sz); |
| 233 | for (int i = 0; i < sz; i++) { |
| 234 | DataReaderWriter.writeDatum(out, t.get(i)); |
| 235 | } |
| 236 | break; |
| 237 | |
| 238 | case DataType.BAG: |
| 239 | DataBag bag = (DataBag)val; |
| 240 | out.writeByte(DataType.BAG); |
| 241 | out.writeLong(bag.size()); |
| 242 | Iterator<Tuple> it = bag.iterator(); |
| 243 | while (it.hasNext()) { |
| 244 | DataReaderWriter.writeDatum(out, it.next()); |
| 245 | } |
| 246 | break; |
| 247 | |
| 248 | case DataType.MAP: { |
| 249 | out.writeByte(DataType.MAP); |
| 250 | Map<String, Object> m = (Map<String, Object>)val; |
| 251 | out.writeInt(m.size()); |
| 252 | Iterator<Map.Entry<String, Object> > i = |
| 253 | m.entrySet().iterator(); |
| 254 | while (i.hasNext()) { |
| 255 | Map.Entry<String, Object> entry = i.next(); |
| 256 | writeDatum(out, entry.getKey()); |
| 257 | writeDatum(out, entry.getValue()); |
| 258 | } |
| 259 | break; |
| 260 | } |
| 261 | |
| 262 | case DataType.INTERNALMAP: { |
| 263 | out.writeByte(DataType.INTERNALMAP); |
| 264 | Map<Object, Object> m = (Map<Object, Object>)val; |
| 265 | out.writeInt(m.size()); |
| 266 | Iterator<Map.Entry<Object, Object> > i = |
| 267 | m.entrySet().iterator(); |
| 268 | while (i.hasNext()) { |
| 269 | Map.Entry<Object, Object> entry = i.next(); |
| 270 | writeDatum(out, entry.getKey()); |
| 271 | writeDatum(out, entry.getValue()); |
| 272 | } |
| 273 | break; |
| 274 | } |
| 275 | |
| 276 | case DataType.INTEGER: |
| 277 | out.writeByte(DataType.INTEGER); |
| 278 | out.writeInt((Integer)val); |
no test coverage detected