hanicz commented on code in PR #947: URL: https://github.com/apache/knox/pull/947#discussion_r1834047083
########## gateway-spi/src/main/java/org/apache/knox/gateway/sse/SSEEntity.java: ########## @@ -0,0 +1,150 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.knox.gateway.sse; + +import org.apache.http.HttpEntity; +import org.apache.http.entity.AbstractHttpEntity; + +import javax.servlet.AsyncContext; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.CharBuffer; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; + +public class SSEEntity extends AbstractHttpEntity { + + private static final String SSE_DELIMITER = ":"; + + private final BlockingQueue<SSEvent> eventQueue; + private final StringBuilder eventBuilder = new StringBuilder(); + private final HttpEntity httpEntity; + private char previousChar = '0'; + + public SSEEntity(HttpEntity httpEntity) { + this.httpEntity = httpEntity; + this.eventQueue = new LinkedBlockingQueue<>(); + } + + public boolean readCharBuffer(CharBuffer charBuffer) { + while (charBuffer.hasRemaining()) { + processChar(charBuffer.get()); + } + return !this.eventQueue.isEmpty(); Review Comment: Removed ########## gateway-spi/src/main/java/org/apache/knox/gateway/sse/SSEEntity.java: ########## @@ -0,0 +1,150 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.knox.gateway.sse; + +import org.apache.http.HttpEntity; +import org.apache.http.entity.AbstractHttpEntity; + +import javax.servlet.AsyncContext; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.CharBuffer; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; + +public class SSEEntity extends AbstractHttpEntity { + + private static final String SSE_DELIMITER = ":"; + + private final BlockingQueue<SSEvent> eventQueue; + private final StringBuilder eventBuilder = new StringBuilder(); + private final HttpEntity httpEntity; + private char previousChar = '0'; + + public SSEEntity(HttpEntity httpEntity) { + this.httpEntity = httpEntity; + this.eventQueue = new LinkedBlockingQueue<>(); + } + + public boolean readCharBuffer(CharBuffer charBuffer) { + while (charBuffer.hasRemaining()) { + processChar(charBuffer.get()); + } + return !this.eventQueue.isEmpty(); + } + + //Two new line chars (\n\n) after each other means the event is finished streaming + //We can process it and add it to the event queue + private void processChar(char nextChar) { + if (isNewLineChar(nextChar) && isNewLineChar(this.previousChar)) { + this.processEvent(); Review Comment: Removed them -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@knox.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org