1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-12-08 20:11:08 +01:00

Enable LeftCurly checkstyle check

This commit is contained in:
Florian Schmaus 2018-04-06 10:21:46 +02:00
parent 5a841ff0a8
commit 9b5dafe541
93 changed files with 549 additions and 1087 deletions

View file

@ -193,8 +193,7 @@ public final class ProviderManager {
*/
@SuppressWarnings("unchecked")
public static void addIQProvider(String elementName, String namespace,
Object provider)
{
Object provider) {
validate(elementName, namespace);
// First remove existing providers
String key = removeIQProvider(elementName, namespace);
@ -255,8 +254,7 @@ public final class ProviderManager {
*/
@SuppressWarnings("unchecked")
public static void addExtensionProvider(String elementName, String namespace,
Object provider)
{
Object provider) {
validate(elementName, namespace);
// First remove existing providers
String key = removeExtensionProvider(elementName, namespace);

View file

@ -37,8 +37,7 @@ class HTTPProxySocketConnection implements ProxySocketConnection {
private final ProxyInfo proxy;
HTTPProxySocketConnection(ProxyInfo proxy)
{
HTTPProxySocketConnection(ProxyInfo proxy) {
this.proxy = proxy;
}
@ -51,12 +50,10 @@ class HTTPProxySocketConnection implements ProxySocketConnection {
String hostport = "CONNECT " + host + ":" + port;
String proxyLine;
String username = proxy.getProxyUsername();
if (username == null)
{
if (username == null) {
proxyLine = "";
}
else
{
else {
String password = proxy.getProxyPassword();
proxyLine = "\r\nProxy-Authorization: Basic " + Base64.encode(username + ":" + password);
}
@ -67,41 +64,33 @@ class HTTPProxySocketConnection implements ProxySocketConnection {
StringBuilder got = new StringBuilder(100);
int nlchars = 0;
while (true)
{
while (true) {
int inByte = in.read();
if (inByte == -1)
{
if (inByte == -1) {
throw new ProxyException(ProxyInfo.ProxyType.HTTP);
}
char c = (char) inByte;
got.append(c);
if (got.length() > 1024)
{
if (got.length() > 1024) {
throw new ProxyException(ProxyInfo.ProxyType.HTTP, "Received " +
"header of >1024 characters from "
+ proxyhost + ", cancelling connection");
}
if ((nlchars == 0 || nlchars == 2) && c == '\r')
{
if ((nlchars == 0 || nlchars == 2) && c == '\r') {
nlchars++;
}
else if ((nlchars == 1 || nlchars == 3) && c == '\n')
{
else if ((nlchars == 1 || nlchars == 3) && c == '\n') {
nlchars++;
}
else
{
else {
nlchars = 0;
}
if (nlchars == 4)
{
if (nlchars == 4) {
break;
}
}
if (nlchars != 4)
{
if (nlchars != 4) {
throw new ProxyException(ProxyInfo.ProxyType.HTTP, "Never " +
"received blank line from "
+ proxyhost + ", cancelling connection");
@ -112,23 +101,20 @@ class HTTPProxySocketConnection implements ProxySocketConnection {
BufferedReader br = new BufferedReader(new StringReader(gotstr));
String response = br.readLine();
if (response == null)
{
if (response == null) {
throw new ProxyException(ProxyInfo.ProxyType.HTTP, "Empty proxy " +
"response from " + proxyhost + ", cancelling");
}
Matcher m = RESPONSE_PATTERN.matcher(response);
if (!m.matches())
{
if (!m.matches()) {
throw new ProxyException(ProxyInfo.ProxyType.HTTP , "Unexpected " +
"proxy response from " + proxyhost + ": " + response);
}
int code = Integer.parseInt(m.group(1));
if (code != HttpURLConnection.HTTP_OK)
{
if (code != HttpURLConnection.HTTP_OK) {
throw new ProxyException(ProxyInfo.ProxyType.HTTP);
}
}

View file

@ -29,13 +29,11 @@ public class ProxyException extends IOException {
*/
private static final long serialVersionUID = 1L;
public ProxyException(ProxyInfo.ProxyType type, String ex)
{
public ProxyException(ProxyInfo.ProxyType type, String ex) {
super("Proxy Exception " + type.toString() + " : " + ex);
}
public ProxyException(ProxyInfo.ProxyType type)
{
public ProxyException(ProxyInfo.ProxyType type) {
super("Proxy Exception " + type.toString() + " : " + "Unknown Error");
}
}

View file

@ -23,10 +23,8 @@ package org.jivesoftware.smack.proxy;
* @author Atul Aggarwal
*/
public class ProxyInfo
{
public enum ProxyType
{
public class ProxyInfo {
public enum ProxyType {
HTTP,
SOCKS4,
SOCKS5
@ -40,8 +38,7 @@ public class ProxyInfo
private final ProxySocketConnection proxySocketConnection;
public ProxyInfo(ProxyType pType, String pHost, int pPort, String pUser,
String pPass)
{
String pPass) {
this.proxyType = pType;
this.proxyAddress = pHost;
this.proxyPort = pPort;
@ -63,45 +60,37 @@ public class ProxyInfo
}
public static ProxyInfo forHttpProxy(String pHost, int pPort, String pUser,
String pPass)
{
String pPass) {
return new ProxyInfo(ProxyType.HTTP, pHost, pPort, pUser, pPass);
}
public static ProxyInfo forSocks4Proxy(String pHost, int pPort, String pUser,
String pPass)
{
String pPass) {
return new ProxyInfo(ProxyType.SOCKS4, pHost, pPort, pUser, pPass);
}
public static ProxyInfo forSocks5Proxy(String pHost, int pPort, String pUser,
String pPass)
{
String pPass) {
return new ProxyInfo(ProxyType.SOCKS5, pHost, pPort, pUser, pPass);
}
public ProxyType getProxyType()
{
public ProxyType getProxyType() {
return proxyType;
}
public String getProxyAddress()
{
public String getProxyAddress() {
return proxyAddress;
}
public int getProxyPort()
{
public int getProxyPort() {
return proxyPort;
}
public String getProxyUsername()
{
public String getProxyUsername() {
return proxyUsername;
}
public String getProxyPassword()
{
public String getProxyPassword() {
return proxyPassword;
}

View file

@ -33,8 +33,7 @@ import org.jivesoftware.smack.util.StringUtils;
public class Socks4ProxySocketConnection implements ProxySocketConnection {
private final ProxyInfo proxy;
Socks4ProxySocketConnection(ProxyInfo proxy)
{
Socks4ProxySocketConnection(ProxyInfo proxy) {
this.proxy = proxy;
}
@ -47,8 +46,7 @@ public class Socks4ProxySocketConnection implements ProxySocketConnection {
int proxy_port = proxy.getProxyPort();
String user = proxy.getProxyUsername();
try
{
try {
socket.connect(new InetSocketAddress(proxy_host, proxy_port), timeout);
in = socket.getInputStream();
out = socket.getOutputStream();
@ -84,13 +82,11 @@ public class Socks4ProxySocketConnection implements ProxySocketConnection {
InetAddress inetAddress = InetAddress.getByName(proxy_host);
byte[] byteAddress = inetAddress.getAddress();
for (int i = 0; i < byteAddress.length; i++)
{
for (int i = 0; i < byteAddress.length; i++) {
buf[index++] = byteAddress[i];
}
if (user != null)
{
if (user != null) {
byte[] userBytes = user.getBytes(StringUtils.UTF8);
System.arraycopy(userBytes, 0, buf, index, user.length());
index += user.length();
@ -127,29 +123,23 @@ public class Socks4ProxySocketConnection implements ProxySocketConnection {
int len = 6;
int s = 0;
while (s < len)
{
while (s < len) {
int i = in.read(buf, s, len - s);
if (i <= 0)
{
if (i <= 0) {
throw new ProxyException(ProxyInfo.ProxyType.SOCKS4,
"stream is closed");
}
s += i;
}
if (buf[0] != 0)
{
if (buf[0] != 0) {
throw new ProxyException(ProxyInfo.ProxyType.SOCKS4,
"server returns VN " + buf[0]);
}
if (buf[1] != 90)
{
try
{
if (buf[1] != 90) {
try {
socket.close();
}
catch (Exception eee)
{
catch (Exception eee) {
}
String message = "ProxySOCKS4: server returns CD " + buf[1];
throw new ProxyException(ProxyInfo.ProxyType.SOCKS4, message);
@ -157,18 +147,14 @@ public class Socks4ProxySocketConnection implements ProxySocketConnection {
byte[] temp = new byte[2];
in.read(temp, 0, 2);
}
catch (RuntimeException e)
{
catch (RuntimeException e) {
throw e;
}
catch (Exception e)
{
try
{
catch (Exception e) {
try {
socket.close();
}
catch (Exception eee)
{
catch (Exception eee) {
}
throw new ProxyException(ProxyInfo.ProxyType.SOCKS4, e.toString());
}

View file

@ -32,8 +32,7 @@ import org.jivesoftware.smack.util.StringUtils;
public class Socks5ProxySocketConnection implements ProxySocketConnection {
private final ProxyInfo proxy;
Socks5ProxySocketConnection(ProxyInfo proxy)
{
Socks5ProxySocketConnection(ProxyInfo proxy) {
this.proxy = proxy;
}
@ -47,8 +46,7 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
String user = proxy.getProxyUsername();
String passwd = proxy.getProxyPassword();
try
{
try {
socket.connect(new InetSocketAddress(proxy_host, proxy_port), timeout);
in = socket.getInputStream();
out = socket.getOutputStream();
@ -100,14 +98,12 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
fill(in, buf, 2);
boolean check = false;
switch ((buf[1]) & 0xff)
{
switch ((buf[1]) & 0xff) {
case 0: // NO AUTHENTICATION REQUIRED
check = true;
break;
case 2: // USERNAME/PASSWORD
if (user == null || passwd == null)
{
if (user == null || passwd == null) {
break;
}
@ -160,22 +156,18 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
connection.
*/
fill(in, buf, 2);
if (buf[1] == 0)
{
if (buf[1] == 0) {
check = true;
}
break;
default:
}
if (!check)
{
try
{
if (!check) {
try {
socket.close();
}
catch (Exception eee)
{
catch (Exception eee) {
}
throw new ProxyException(ProxyInfo.ProxyType.SOCKS5,
"fail in SOCKS5 proxy");
@ -260,21 +252,17 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
fill(in, buf, 4);
if (buf[1] != 0)
{
try
{
if (buf[1] != 0) {
try {
socket.close();
}
catch (Exception eee)
{
catch (Exception eee) {
}
throw new ProxyException(ProxyInfo.ProxyType.SOCKS5,
"server returns " + buf[1]);
}
switch (buf[3] & 0xff)
{
switch (buf[3] & 0xff) {
case 1:
fill(in, buf, 6);
break;
@ -288,18 +276,14 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
default:
}
}
catch (RuntimeException e)
{
catch (RuntimeException e) {
throw e;
}
catch (Exception e)
{
try
{
catch (Exception e) {
try {
socket.close();
}
catch (Exception eee)
{
catch (Exception eee) {
}
// TODO convert to IOException(e) when minimum Android API level is 9 or higher
throw new IOException(e.getLocalizedMessage());
@ -307,14 +291,11 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
}
private static void fill(InputStream in, byte[] buf, int len)
throws IOException
{
throws IOException {
int s = 0;
while (s < len)
{
while (s < len) {
int i = in.read(buf, s, len - s);
if (i <= 0)
{
if (i <= 0) {
throw new ProxyException(ProxyInfo.ProxyType.SOCKS5, "stream " +
"is closed");
}