[
https://issues.apache.org/jira/browse/FLINK-2125?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15089426#comment-15089426
]
ASF GitHub Bot commented on FLINK-2125:
---------------------------------------
Github user tillrohrmann commented on a diff in the pull request:
https://github.com/apache/flink/pull/1491#discussion_r49204456
--- Diff:
flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/source/SocketTextStreamFunction.java
---
@@ -84,25 +84,25 @@ public SocketTextStreamFunction(String hostname, int
port, char delimiter, long
public void run(SourceContext<String> ctx) throws Exception {
final StringBuilder buffer = new StringBuilder();
long attempt = 0;
-
+
while (isRunning) {
-
+
try (Socket socket = new Socket()) {
currentSocket = socket;
-
+
LOG.info("Connecting to server socket " +
hostname + ':' + port);
socket.connect(new InetSocketAddress(hostname,
port), CONNECTION_TIMEOUT_TIME);
BufferedReader reader = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
- int data;
- while (isRunning && (data = reader.read()) !=
-1) {
- // check if the string is complete
- if (data != delimiter) {
- buffer.append((char) data);
- }
- else {
- // truncate trailing carriage
return
- if (delimiter == '\n' &&
buffer.length() > 0 && buffer.charAt(buffer.length() - 1) == '\r') {
+ char[] charBuffer = new
char[Math.max(8192,delimiter.length()*2)];
+ int bytesRead;
+ while (isRunning && (bytesRead =
reader.read(charBuffer)) != -1) {
+ String input = new String(charBuffer,
0, bytesRead);
+ int start = 0,pos;
+ while ((pos = input.indexOf(delimiter,
start)) > -1) {
--- End diff --
What happens if `input` does not contain `delimiter`? And what happens with
the input part after the last delimiter?
> String delimiter for SocketTextStream
> -------------------------------------
>
> Key: FLINK-2125
> URL: https://issues.apache.org/jira/browse/FLINK-2125
> Project: Flink
> Issue Type: Improvement
> Components: Streaming
> Affects Versions: 0.9
> Reporter: Márton Balassi
> Priority: Minor
> Labels: starter
>
> The SocketTextStreamFunction uses a character delimiter, despite other parts
> of the API using String delimiter.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)