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?
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---