by Anonymous » 16 Apr 2025, 05:34
Ich stehe gerade in Java auf den neuesten Stand und bin auf diesen Code gestoßen, den ich versuche, meinen Kopf herumzuwickeln, kann aber nicht ...

. Könnte mir jemand bitte helfen zu verstehen, was mit der folgenden Methode los ist? < /P>
Code: Select all
private @NotNull HttpRoutePlanner proxyRoutePlanner(String proxyHostname, int proxyPort) {
String nonProxyHostsProperty = System.getProperty("http.nonProxyHosts");
String[] nonProxyHosts = nonProxyHostsProperty != null ? nonProxyHostsProperty.split("\\|") : new String[0];
HttpHost proxyHost = new HttpHost(proxyHostname, proxyPort);
return (httpHost, httpRequest, httpContext) -> {
if (Arrays.stream(nonProxyHosts).anyMatch(nonProxyHost -> FilenameUtils.wildcardMatch(httpHost.getHostName(), nonProxyHost, IOCase.INSENSITIVE))) {
return new HttpRoute(httpHost);
}
return new HttpRoute(httpHost, proxyHost);
};
}
Hier ist, was ich verstehe:
- Die Methode speichert zunächst eine Liste von 'Non -Proxy' Hostnamen in ein Array von String s, nachdem sie von der http.nonproxyhostes -systems -codes -systems -symboles -system -achte it it tods tods tods the code systems -Eigenschaft. Httphost Objekt Verwenden Sie den ProxyHostName und proxyport übergeben in die ProxyroutePlanner () -Methode. Diese httphost -Methode wird später in der Methode beim Erstellen einer "Proxy" -Route ().
Hier bin ich total verwirrt:
Was genau läuft die Rückgabe Anweisung des enthaltenden ProxyroutePlanner () Methode? Gibt es eine andere anonyme Funktion zurück, die
noch etwas anderes zurückgibt (ein httproute Objekt)? Httphost befindet sich in der Liste der "Nicht -Proxy" -Hosts. Wenn dies der Fall ist, gibt es ein "Nicht -Proxy" -Httproute (httoHost) zurück, ansonsten für "Proxy" -Hosts, es gibt ein 'Proxy' httProute (httphost, proxyHost) Objekt zurück. Aber woher kommt diese Argumente? Httproute < /code>, das aussieht, wie
erneut aus der enthaltenden ProxyroutePlanner () < /code> -Methode zurückgegeben wird, dies ist jedoch nicht sinnvoll. Der Rückgabetyp der ProxyroutePlanner () ist nicht httproute , aber httproutePlanner ! und diese Objekte sind nicht einmal verwandt. Ich verstehe nichts. Könnte mir jemand bitte helfen zu verstehen, was mit dieser Funktion los ist? Jede Hilfe/Einsicht wäre sehr geschätzt. Vielen Dank für Ihre Zeit und Geduld im Voraus!
Ich stehe gerade in Java auf den neuesten Stand und bin auf diesen Code gestoßen, den ich versuche, meinen Kopf herumzuwickeln, kann aber nicht ... :). Könnte mir jemand bitte helfen zu verstehen, was mit der folgenden Methode los ist? < /P>
[code] private @NotNull HttpRoutePlanner proxyRoutePlanner(String proxyHostname, int proxyPort) {
String nonProxyHostsProperty = System.getProperty("http.nonProxyHosts");
String[] nonProxyHosts = nonProxyHostsProperty != null ? nonProxyHostsProperty.split("\\|") : new String[0];
HttpHost proxyHost = new HttpHost(proxyHostname, proxyPort);
return (httpHost, httpRequest, httpContext) -> {
if (Arrays.stream(nonProxyHosts).anyMatch(nonProxyHost -> FilenameUtils.wildcardMatch(httpHost.getHostName(), nonProxyHost, IOCase.INSENSITIVE))) {
return new HttpRoute(httpHost);
}
return new HttpRoute(httpHost, proxyHost);
};
}
[/code]
[b] Hier ist, was ich verstehe: [/b]
[list]
[*] Die Methode speichert zunächst eine Liste von 'Non -Proxy' Hostnamen in ein Array von String s, nachdem sie von der http.nonproxyhostes -systems -codes -systems -symboles -system -achte it it tods tods tods the code systems -Eigenschaft. Httphost Objekt Verwenden Sie den ProxyHostName und proxyport übergeben in die ProxyroutePlanner () -Methode. Diese httphost -Methode wird später in der Methode beim Erstellen einer "Proxy" -Route ([code]HttpRoute(httpHost, proxyHost)[/code]).
[/list]
[b] Hier bin ich total verwirrt: [/b]
Was genau läuft die Rückgabe Anweisung des enthaltenden ProxyroutePlanner () Methode? Gibt es eine andere anonyme Funktion zurück, die [b] noch etwas anderes zurückgibt [/b] (ein httproute Objekt)? Httphost befindet sich in der Liste der "Nicht -Proxy" -Hosts. Wenn dies der Fall ist, gibt es ein "Nicht -Proxy" -Httproute (httoHost) zurück, ansonsten für "Proxy" -Hosts, es gibt ein 'Proxy' httProute (httphost, proxyHost) Objekt zurück. Aber woher kommt diese Argumente? Httproute < /code>, das aussieht, wie
erneut aus der enthaltenden ProxyroutePlanner () < /code> -Methode zurückgegeben wird, dies ist jedoch nicht sinnvoll. Der Rückgabetyp der ProxyroutePlanner () ist nicht httproute , aber httproutePlanner ! und diese Objekte sind nicht einmal verwandt. Ich verstehe nichts. Könnte mir jemand bitte helfen zu verstehen, was mit dieser Funktion los ist? Jede Hilfe/Einsicht wäre sehr geschätzt. Vielen Dank für Ihre Zeit und Geduld im Voraus!