private Object parseAttribute(String line) { List<String> tokens = newArrayList(Splitter.on('\t').split(line)); Preconditions.checkArgument(tokens.size() == 2, "Wrong attribute definition: %s", line); String typeName = tokens.get(0); String value = tokens.get(1); FieldType type; try { type = FieldType.valueOf(typeName); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Wrong type name: " + typeName); } return TextValueSerializer.fromString(type, value); }
private Object parseAttribute(String line) { List<String> tokens = newArrayList(Splitter.on('\t').split(line)); Preconditions.checkArgument(tokens.size() == 2, "Wrong attribute definition: %s", line); String typeName = tokens.get(0); String value = tokens.get(1); FieldType type; try { type = FieldType.valueOf(typeName); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Wrong type name: " + typeName); } return TextValueSerializer.fromString(type, value); }
@Override public Map<String, Object> readMap(DataInput in) throws IOException { final int size = in.readInt(); Map<String, Object> map = Maps.newHashMap(); for (int i = 0; i < size; i++) { String key = readString(in); byte fieldTag = in.readByte(); FieldType fieldType = FieldType.valueOf(fieldTag); Object value = decode(fieldType, in); map.put(key, value); } return map; }
@Override public Map<String, Object> readMap(DataInput in) throws IOException { final int size = in.readInt(); Map<String, Object> map = Maps.newHashMap(); for (int i = 0; i < size; i++) { String key = readString(in); byte fieldTag = in.readByte(); FieldType fieldType = FieldType.valueOf(fieldTag); Object value = decode(fieldType, in); map.put(key, value); } return map; }
public static NodeId read(DataInput in) throws IOException { final String name = in.readUTF(); FieldType type = FieldType.valueOf(in.readUnsignedByte()); final Object val = DataStreamValueSerializerV2.INSTANCE.decode(type, in); return new NodeId(name, val); } }
public static NodeId read(DataInput in) throws IOException { final String name = in.readUTF(); FieldType type = FieldType.valueOf(in.readUnsignedByte()); final Object val = DataStreamValueSerializerV2.INSTANCE.decode(type, in); return new NodeId(name, val); } }
private @Nullable Object parse(int index) { final int offset = offsets[index]; final int tagValue = data[offset] & 0xFF; if (tagValue > 100) { throw new IllegalStateException(); } final FieldType type = FieldType.valueOf(tagValue); final DataInput in = ByteStreams.newDataInput(data, offset + 1); @Nullable Object value; try { value = valueParser.decode(type, in); } catch (IOException e) { throw new RuntimeException(e); } return value; }
private @Nullable Object parse(int index) { final int offset = offsets[index]; final int tagValue = data[offset] & 0xFF; if (tagValue > 100) { throw new IllegalStateException(); } final FieldType type = FieldType.valueOf(tagValue); final DataInput in = ByteStreams.newDataInput(data, offset + 1); @Nullable Object value; try { value = valueParser.decode(type, in); } catch (IOException e) { throw Throwables.propagate(e); } return value; }
@Override public Optional<Geometry> get(int index, GeometryFactory gf) { final int offset = offsets[index]; final int tagValue = data[offset] & 0xFF; final FieldType type = FieldType.valueOf(tagValue); if (FieldType.NULL.equals(type)) { return Optional.absent(); } DataInput in = ByteStreams.newDataInput(data, offset + 1); Geometry value; try { value = valueParser.readGeometry(in, gf); } catch (IOException e) { throw new RuntimeException(e); } return Optional.of(value); }
@Override public Optional<Geometry> get(int index, GeometryFactory gf) { final int offset = offsets[index]; final int tagValue = data[offset] & 0xFF; final FieldType type = FieldType.valueOf(tagValue); if (FieldType.NULL.equals(type)) { return Optional.absent(); } DataInput in = ByteStreams.newDataInput(data, offset + 1); Geometry value; try { value = valueParser.readGeometry(in, gf); } catch (IOException e) { throw Throwables.propagate(e); } return Optional.of(value); }
@Override public Map<String, Object> readMap(DataInput in) throws IOException { final int size = readUnsignedVarInt(in); Map<String, Object> map = new HashMap<>(); String key; byte fieldTag; FieldType fieldType; Object value; for (int i = 0; i < size; i++) { key = readString(in); fieldTag = in.readByte(); fieldType = FieldType.valueOf(fieldTag); value = decode(fieldType, in); map.put(key, value); } return map; }
@Override public Map<String, Object> readMap(DataInput in) throws IOException { final int size = readUnsignedVarInt(in); Map<String, Object> map = new HashMap<>(); String key; byte fieldTag; FieldType fieldType; Object value; for (int i = 0; i < size; i++) { key = readString(in); fieldTag = in.readByte(); fieldType = FieldType.valueOf(fieldTag); value = decode(fieldType, in); map.put(key, value); } return map; }
public @Nullable Object findInMap(final DataInput in, final String mapKey) throws IOException { final StringTable st = stringTable.get(); final int keyIndex = st.get(mapKey); if (-1 == keyIndex) { return null; } final int[] keyIndices = readIntArray(in); final int valueIndex = Arrays.binarySearch(keyIndices, keyIndex); Preconditions.checkState(valueIndex >= 0); final int[] offsets = readIntArray(in); final int valueOffset = offsets[valueIndex]; final int dataSectionSize = readUnsignedVarInt(in); Preconditions.checkState(dataSectionSize > valueOffset); in.skipBytes(valueOffset); final int tagValue = in.readUnsignedByte(); FieldType type = FieldType.valueOf(tagValue); return decode(type, in); }
public static RevFeature readFeature(ObjectId id, DataInput in) throws IOException { final int count = in.readInt(); final RevFeatureBuilder builder = RevFeature.builder(); for (int i = 0; i < count; i++) { final byte fieldTag = in.readByte(); final FieldType fieldType = FieldType.valueOf(fieldTag); Object value = DataStreamValueSerializerV1.INSTANCE.decode(fieldType, in); builder.addValue(value); } RevFeature built = builder.build(); return built; }
public static RevFeature readFeature(ObjectId id, DataInput in) throws IOException { final int count = in.readInt(); final RevFeatureBuilder builder = RevFeatureBuilder.builder(); for (int i = 0; i < count; i++) { final byte fieldTag = in.readByte(); final FieldType fieldType = FieldType.valueOf(fieldTag); Object value = DataStreamValueSerializerV1.INSTANCE.decode(fieldType, in); builder.addValue(value); } RevFeature built = builder.build(); return built; }
private static AttributeType readAttributeType(DataInput in, FeatureTypeFactory typeFactory) throws IOException { final Name name = readName(in); final byte typeTag = in.readByte(); final FieldType type = FieldType.valueOf(typeTag); if (Geometry.class.isAssignableFrom(type.getBinding())) { final boolean isCRSCode = in.readBoolean(); // as opposed to a raw WKT string final String crsText = in.readUTF(); final CoordinateReferenceSystem crs; try { if (isCRSCode) { if (RevObjects.NULL_CRS_IDENTIFIER.equals(crsText)) { crs = null; } else { boolean forceLongitudeFirst = crsText.startsWith("EPSG:"); crs = CRS.decode(crsText, forceLongitudeFirst); } } else { crs = CRS.parseWKT(crsText); } } catch (FactoryException e) { throw new RuntimeException(e); } return typeFactory.createGeometryType(name, type.getBinding(), crs, false, false, Collections.<Filter> emptyList(), null, null); } else { return typeFactory.createAttributeType(name, type.getBinding(), false, false, Collections.<Filter> emptyList(), null, null); } }
final Name name = readName(in); final byte typeTag = in.readByte(); final FieldType type = FieldType.valueOf(typeTag); if (Geometry.class.isAssignableFrom(type.getBinding())) { final boolean isCRSCode = in.readBoolean(); // as opposed to a raw
private static AttributeType readAttributeType(DataInput in, FeatureTypeFactory typeFactory) throws IOException { final Name name = readName(in); final byte typeTag = in.readByte(); final FieldType type = FieldType.valueOf(typeTag); if (Geometry.class.isAssignableFrom(type.getBinding())) { final boolean isCRSCode = in.readBoolean(); // as opposed to a raw WKT string final String crsText = in.readUTF(); final CoordinateReferenceSystem crs; try { if (isCRSCode) { if (RevObjects.NULL_CRS_IDENTIFIER.equals(crsText)) { crs = null; } else { boolean forceLongitudeFirst = crsText.startsWith("EPSG:"); crs = CRS.decode(crsText, forceLongitudeFirst); } } else { crs = CRS.parseWKT(crsText); } } catch (FactoryException e) { throw new RuntimeException(e); } return typeFactory.createGeometryType(name, type.getBinding(), crs, false, false, Collections.<Filter> emptyList(), null, null); } else { return typeFactory.createAttributeType(name, type.getBinding(), false, false, Collections.<Filter> emptyList(), null, null); } }
public RevFeature readFeature(@Nullable ObjectId id, DataInput in) throws IOException { final int count = readUnsignedVarInt(in); final RevFeatureBuilder builder = RevFeatureBuilder.builder(); for (int i = 0; i < count; i++) { final byte fieldTag = in.readByte(); final FieldType fieldType = FieldType.valueOf(fieldTag); Object value = valueEncoder.decode(fieldType, in); builder.addValueNoCopy(value); } RevFeature built = id == null ? builder.build() : builder.build(id); return built; }
public RevFeature readFeature(@Nullable ObjectId id, DataInput in) throws IOException { final int count = readUnsignedVarInt(in); final RevFeatureBuilder builder = RevFeature.builder(); for (int i = 0; i < count; i++) { final byte fieldTag = in.readByte(); final FieldType fieldType = FieldType.valueOf(fieldTag); Object value = valueEncoder.decode(fieldType, in); builder.addValueNoCopy(value); } RevFeature built = builder.id(id).build(); return built; }