Java Code Examples for org.apache.flink.types.StringValue#readString()

The following examples show how to use org.apache.flink.types.StringValue#readString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StringSerializationTest.java    From flink with Apache License 2.0 6 votes vote down vote up
public static final void testSerialization(String[] values) throws IOException {
	ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
	DataOutputStream serializer = new DataOutputStream(baos);
	
	for (String value : values) {
		StringValue.writeString(value, serializer);
	}
	
	serializer.close();
	baos.close();
	
	ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
	DataInputStream deserializer = new DataInputStream(bais);
	
	int num = 0;
	while (deserializer.available() > 0) {
		String deser = StringValue.readString(deserializer);
		
		assertEquals("DeserializedString differs from original string.", values[num], deser);
		num++;
	}
	
	assertEquals("Wrong number of deserialized values", values.length, num);
}
 
Example 2
Source File: NFAStateSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
private ComputationState deserializeSingleComputationState(DataInputView source) throws IOException {
	String stateName = StringValue.readString(source);
	NodeId prevState = nodeIdSerializer.deserialize(source);
	DeweyNumber version = versionSerializer.deserialize(source);
	long startTimestamp = source.readLong();

	EventId startEventId = deserializeStartEvent(source);

	return ComputationState.createState(stateName,
		prevState,
		version,
		startTimestamp,
		startEventId);
}
 
Example 3
Source File: NodeId.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public NodeId deserialize(DataInputView source) throws IOException {
	byte b = source.readByte();
	if (b == 0) {
		return null;
	}

	EventId eventId = eventIdSerializer.deserialize(source);
	String pageName = StringValue.readString(source);
	return new NodeId(eventId, pageName);
}
 
Example 4
Source File: StringComparator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public int compareSerialized(DataInputView firstSource, DataInputView secondSource) throws IOException {
	String s1 = StringValue.readString(firstSource);
	String s2 = StringValue.readString(secondSource);
	int comp = s1.compareTo(s2); 
	return ascendingComparison ? comp : -comp;
}
 
Example 5
Source File: NodeId.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public NodeId deserialize(DataInputView source) throws IOException {
	byte b = source.readByte();
	if (b == 0) {
		return null;
	}

	EventId eventId = eventIdSerializer.deserialize(source);
	String pageName = StringValue.readString(source);
	return new NodeId(eventId, pageName);
}
 
Example 6
Source File: NodeId.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public NodeId deserialize(DataInputView source) throws IOException {
	byte b = source.readByte();
	if (b == 0) {
		return null;
	}

	EventId eventId = eventIdSerializer.deserialize(source);
	String pageName = StringValue.readString(source);
	return new NodeId(eventId, pageName);
}
 
Example 7
Source File: StringSerializationTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public static final void testCopy(String[] values) throws IOException {
	ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
	DataOutputStream serializer = new DataOutputStream(baos);
	
	for (String value : values) {
		StringValue.writeString(value, serializer);
	}
	
	serializer.close();
	baos.close();
	
	ByteArrayInputStream sourceInput = new ByteArrayInputStream(baos.toByteArray());
	DataInputStream source = new DataInputStream(sourceInput);
	ByteArrayOutputStream targetOutput = new ByteArrayOutputStream(4096);
	DataOutputStream target = new DataOutputStream(targetOutput);
	
	for (int i = 0; i < values.length; i++) {
		StringValue.copyString(source, target);
	}
	
	ByteArrayInputStream validateInput = new ByteArrayInputStream(targetOutput.toByteArray());
	DataInputStream validate = new DataInputStream(validateInput);
	
	int num = 0;
	while (validate.available() > 0) {
		String deser = StringValue.readString(validate);
		
		assertEquals("DeserializedString differs from original string.", values[num], deser);
		num++;
	}
	
	assertEquals("Wrong number of deserialized values", values.length, num);
}
 
Example 8
Source File: StringArraySerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public String[] deserialize(DataInputView source) throws IOException {
	final int len = source.readInt();
	String[] array = new String[len];
	
	for (int i = 0; i < len; i++) {
		array[i] = StringValue.readString(source);
	}
	
	return array;
}
 
Example 9
Source File: StringComparator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public int compareSerialized(DataInputView firstSource, DataInputView secondSource) throws IOException {
	String s1 = StringValue.readString(firstSource);
	String s2 = StringValue.readString(secondSource);
	int comp = s1.compareTo(s2); 
	return ascendingComparison ? comp : -comp;
}
 
Example 10
Source File: StringPairSerializer.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public StringPair deserialize(DataInputView source) throws IOException {
	return new StringPair(StringValue.readString(source), StringValue.readString(source));
}
 
Example 11
Source File: StringSerializer.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public String deserialize(DataInputView source) throws IOException {
	return StringValue.readString(source);
}
 
Example 12
Source File: StringSerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public String deserialize(DataInputView source) throws IOException {
	return StringValue.readString(source);
}
 
Example 13
Source File: Configuration.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void read(DataInputView in) throws IOException {
	synchronized (this.confData) {
		final int numberOfProperties = in.readInt();

		for (int i = 0; i < numberOfProperties; i++) {
			String key = StringValue.readString(in);
			Object value;

			byte type = in.readByte();
			switch (type) {
				case TYPE_STRING:
					value = StringValue.readString(in);
					break;
				case TYPE_INT:
					value = in.readInt();
					break;
				case TYPE_LONG:
					value = in.readLong();
					break;
				case TYPE_FLOAT:
					value = in.readFloat();
					break;
				case TYPE_DOUBLE:
					value = in.readDouble();
					break;
				case TYPE_BOOLEAN:
					value = in.readBoolean();
					break;
				case TYPE_BYTES:
					byte[] bytes = new byte[in.readInt()];
					in.readFully(bytes);
					value = bytes;
					break;
				default:
					throw new IOException("Unrecognized type: " + type);
			}

			this.confData.put(key, value);
		}
	}
}
 
Example 14
Source File: Configuration.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void read(DataInputView in) throws IOException {
	synchronized (this.confData) {
		final int numberOfProperties = in.readInt();

		for (int i = 0; i < numberOfProperties; i++) {
			String key = StringValue.readString(in);
			Object value;

			byte type = in.readByte();
			switch (type) {
				case TYPE_STRING:
					value = StringValue.readString(in);
					break;
				case TYPE_INT:
					value = in.readInt();
					break;
				case TYPE_LONG:
					value = in.readLong();
					break;
				case TYPE_FLOAT:
					value = in.readFloat();
					break;
				case TYPE_DOUBLE:
					value = in.readDouble();
					break;
				case TYPE_BOOLEAN:
					value = in.readBoolean();
					break;
				case TYPE_BYTES:
					byte[] bytes = new byte[in.readInt()];
					in.readFully(bytes);
					value = bytes;
					break;
				default:
					throw new IOException("Unrecognized type: " + type);
			}

			this.confData.put(key, value);
		}
	}
}
 
Example 15
Source File: StringSerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public String deserialize(DataInputView source) throws IOException {
	return StringValue.readString(source);
}
 
Example 16
Source File: StringPairSerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public StringPair deserialize(DataInputView source) throws IOException {
	return new StringPair(StringValue.readString(source), StringValue.readString(source));
}
 
Example 17
Source File: StringPairSerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public StringPair deserialize(DataInputView source) throws IOException {
	return new StringPair(StringValue.readString(source), StringValue.readString(source));
}
 
Example 18
Source File: StringUtils.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Reads a non-null String from the given input.
 *
 * @param in The input to read from
 * @return The deserialized String
 *
 * @throws IOException Thrown, if the reading or the deserialization fails.
 */
public static String readString(DataInputView in) throws IOException {
	return StringValue.readString(in);
}
 
Example 19
Source File: StringUtils.java    From Flink-CEPplus with Apache License 2.0 2 votes vote down vote up
/**
 * Reads a non-null String from the given input.
 *
 * @param in The input to read from
 * @return The deserialized String
 *
 * @throws IOException Thrown, if the reading or the deserialization fails.
 */
public static String readString(DataInputView in) throws IOException {
	return StringValue.readString(in);
}
 
Example 20
Source File: StringUtils.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Reads a non-null String from the given input.
 *
 * @param in The input to read from
 * @return The deserialized String
 *
 * @throws IOException Thrown, if the reading or the deserialization fails.
 */
public static String readString(DataInputView in) throws IOException {
	return StringValue.readString(in);
}