import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
-import org.hedgecode.chess.scanner.ChessHogScannerConstants;
import org.hedgecode.chess.scanner.ChessHogScannerException;
import org.hedgecode.chess.scanner.Scanner;
import org.hedgecode.chess.scanner.regex.RegexMatcher;
import org.hedgecode.chess.scanner.regex.RegexType;
import org.hedgecode.chess.scanner.regex.RegexTypeMatcher;
+import static org.hedgecode.chess.scanner.ChessHogScannerConstants.*;
+
/**
* AbstractRequestScanner
*
public abstract class AbstractRequestScanner implements Scanner {
protected String request(String url) throws ChessHogScannerException {
+ return request(url, true);
+ }
+
+ protected String request(String url, boolean withCrlf) throws ChessHogScannerException {
HttpGet request = new HttpGet(url);
CloseableHttpResponse response = null;
StringBuilder sb = new StringBuilder();
response = getClient().execute(request);
try (BufferedReader br = new BufferedReader(
new InputStreamReader(
- response.getEntity().getContent(),
- ChessHogScannerConstants.CHARSET
+ response.getEntity().getContent(), CHARSET
)
)) {
String line;
while ((line = br.readLine()) != null) {
- sb.append(
- line
- ).append(
- ChessHogScannerConstants.CRLF
- );
+ sb.append(line);
+ if (withCrlf) {
+ sb.append(CRLF);
+ }
}
}
} catch (IOException cause) {
return matchRequest(url, matcher, false);
}
- protected String match(String url, String match)
- throws ChessHogScannerException
- {
+ protected String match(String url, String match) throws ChessHogScannerException {
List<String> result = match(url, match, true);
return result.isEmpty() ? null : result.get(0);
}
try (BufferedReader br = new BufferedReader(
new InputStreamReader(
response.getEntity().getContent(),
- ChessHogScannerConstants.CHARSET
+ CHARSET
)
)) {
String line;