protected SliceIterator(final VPackSlice slice) throws VPackValueTypeException { super(); this.slice = slice; size = slice.getLength(); position = 0; }
@Override public int getTextLength() throws IOException { return currentValue.getLength(); }
public int size() { return getLength(); }
private <T> Object deserializeArray(final VPackSlice parent, final VPackSlice vpack, final Type type) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, VPackException { final int length = (int) vpack.getLength(); final Class<?> componentType = ((Class<?>) type).getComponentType(); final Object value = Array.newInstance(componentType, length); for (int i = 0; i < length; i++) { Array.set(value, i, getValue(parent, vpack.get(i), componentType, null)); } return value; }
private void parseArray(final VPackSlice value, final StringBuilder json, final boolean includeNullValues) throws VPackException { json.append(ARRAY_OPEN); int added = 0; for (int i = 0; i < value.getLength(); i++) { final VPackSlice valueAt = value.get(i); if (!valueAt.isNull() || includeNullValues) { if (added++ > 0) { json.append(SEPARATOR); } parse(value, null, valueAt, json, includeNullValues); } } json.append(ARRAY_CLOSE); }
private <T, C> Object deserializeCollection( final VPackSlice parent, final VPackSlice vpack, final Type type, final Type contentType) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, VPackException { final Collection value = (Collection) createInstance(type); final long length = vpack.getLength(); if (length > 0) { for (int i = 0; i < length; i++) { value.add(getValue(parent, vpack.get(i), contentType, null)); } } return value; }
private Object readArray(final TypeInformation<?> type, final VPackSlice source) { if (!source.isArray()) { throw new MappingException( String.format("Can't read array type %s from VPack type %s!", type, source.getType())); } final TypeInformation<?> componentType = getNonNullComponentType(type); final int length = source.getLength(); final Object array = Array.newInstance(componentType.getType(), length); for (int i = 0; i < length; ++i) { Array.set(array, i, readInternal(componentType, source.get(i))); } return array; }
private Object readArray(final TypeInformation<?> type, final VPackSlice source) { if (!source.isArray()) { throw new MappingException( String.format("Can't read array type %s from VPack type %s!", type, source.getType())); } final TypeInformation<?> componentType = getNonNullComponentType(type); final int length = source.getLength(); final Object array = Array.newInstance(componentType.getType(), length); for (int i = 0; i < length; ++i) { Array.set(array, i, readInternal(componentType, source.get(i))); } return array; }
@Override public void seal() throws VPackException { if (builder == null) { return; } builder.close(); final VPackSlice slice = builder.slice(); for (int i = 0; i < slice.getLength(); i++) { final VPackSlice key = slice.keyAt(i); final VPackSlice value = slice.valueAt(i); attributeToKey.put(key.getAsString(), value); keyToAttribute.put(value.getAsInt(), key); } }
private <T, K, C> Object deserializeMap( final VPackSlice parent, final VPackSlice vpack, final Type type, final Type keyType, final Type valueType) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, VPackException { final int length = (int) vpack.getLength(); final Map value = (Map) createInstance(type); if (length > 0) { final VPackKeyMapAdapter<Object> keyMapAdapter = getKeyMapAdapter(keyType); if (keyMapAdapter != null) { for (final Iterator<Entry<String, VPackSlice>> iterator = vpack.objectIterator(); iterator.hasNext();) { final Entry<String, VPackSlice> next = iterator.next(); final Object name = keyMapAdapter.deserialize(next.getKey()); value.put(name, getValue(vpack, next.getValue(), valueType, name.toString())); } } else { for (int i = 0; i < vpack.getLength(); i++) { final VPackSlice entry = vpack.get(i); final Object mapKey = getValue(parent, entry.get(ATTR_KEY), keyType, null); final Object mapValue = getValue(parent, entry.get(ATTR_VALUE), valueType, null); value.put(mapKey, mapValue); } } } return value; }
private Object readCollection(final TypeInformation<?> type, final VPackSlice source) { if (!source.isArray()) { throw new MappingException( String.format("Can't read collection type %s from VPack type %s!", type, source.getType())); } final TypeInformation<?> componentType = getNonNullComponentType(type); final Class<?> collectionType = Iterable.class.equals(type.getType()) ? Collection.class : type.getType(); final Collection<Object> collection = CollectionFactory.createCollection(collectionType, componentType.getType(), source.getLength()); final Iterator<VPackSlice> iterator = source.arrayIterator(); while (iterator.hasNext()) { final VPackSlice elem = iterator.next(); collection.add(readInternal(componentType, elem)); } return collection; }
private Object readCollection(final TypeInformation<?> type, final VPackSlice source) { if (!source.isArray()) { throw new MappingException( String.format("Can't read collection type %s from VPack type %s!", type, source.getType())); } final TypeInformation<?> componentType = getNonNullComponentType(type); final Class<?> collectionType = Iterable.class.equals(type.getType()) ? Collection.class : type.getType(); final Collection<Object> collection = CollectionFactory.createCollection(collectionType, componentType.getType(), source.getLength()); final Iterator<VPackSlice> iterator = source.arrayIterator(); while (iterator.hasNext()) { final VPackSlice elem = iterator.next(); collection.add(readInternal(componentType, elem)); } return collection; }