This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void run() { | |
try { | |
httpd.getMyServerSocket().bind(httpd.hostname != null ? new InetSocketAddress(httpd.hostname, httpd.myPort) : new InetSocketAddress(httpd.myPort)); | |
hasBinded = true; | |
} catch (IOException e) { | |
this.bindException = e; | |
return; | |
} | |
do { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
else if (frame.getOpCode() == OpCode.Ping) { | |
sendFrame(new WebSocketFrame(OpCode.Pong, true, frame.getBinaryPayload())); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
do { | |
try { | |
final Socket finalAccept = httpd.getMyServerSocket().accept(); | |
if (this.timeout > 0) { | |
finalAccept.setSoTimeout(this.timeout); | |
} | |
final InputStream inputStream = finalAccept.getInputStream(); | |
httpd.asyncRunner.exec(httpd.createClientHandler(finalAccept, inputStream)); | |
} catch (IOException e) { | |
NanoHTTPD.LOG.log(Level.FINE, "Communication with the client broken", e); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Maximum time to wait on Socket.getInputStream().read() (in milliseconds) | |
* This is required as the Keep-Alive HTTP connections would otherwise block | |
* the socket reading thread forever (or as long the browser is open). | |
*/ | |
public static final int SOCKET_READ_TIMEOUT = 5000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected boolean isWebsocketRequested(IHTTPSession session) { | |
Map<String, String> headers = session.getHeaders(); | |
String upgrade = headers.get(NanoWSD.HEADER_UPGRADE); | |
boolean isCorrectConnection = isWebSocketConnectionHeader(headers); | |
boolean isUpgrade = NanoWSD.HEADER_UPGRADE_VALUE.equalsIgnoreCase(upgrade); | |
return isUpgrade && isCorrectConnection; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Response handleWebSocket(final IHTTPSession session) { | |
Map<String, String> headers = session.getHeaders(); | |
if (isWebsocketRequested(session)) { | |
if (!NanoWSD.HEADER_WEBSOCKET_VERSION_VALUE. | |
equalsIgnoreCase(headers.get(NanoWSD.HEADER_WEBSOCKET_VERSION))) { | |
return Response. | |
newFixedLengthResponse(Status.BAD_REQUEST, NanoHTTPD.MIME_PLAINTEXT, | |
"Invalid Websocket-Version " + headers.get(NanoWSD.HEADER_WEBSOCKET_VERSION)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// BinaryOperator | |
System.out.println("binaryOpeartor = " + Stream.of(1,2,3,4). | |
reduce(new BinaryOperator<Integer>() { | |
@Override | |
public Integer apply(Integer x, Integer y) { | |
return x + y; | |
} | |
}).get()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Optional; | |
import java.util.function.*; | |
import java.util.stream.Stream; | |
public class FunctionalInterfaces { | |
@FunctionalInterface | |
public interface foo | |
{ | |
abstract public void food(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Supplier | |
Optional<Integer> value = Stream.of(1,2,3,4).reduce(new BinaryOperator<Integer>() { | |
@Override | |
public Integer apply(Integer x, Integer y) { | |
return x + y; | |
} | |
}); | |
value.orElseGet(new Supplier<Integer>() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Function, Consumer | |
Stream.of(strings).filter(s -> s.matches("\\d+")).map(new Function<String, Integer>() { | |
/** | |
* Applies this function to the given argument. | |
* | |
* @param s the function argument | |
* @return the function result | |
*/ | |
@Override |
NewerOlder