ClaptrapBot/src/main/java/net/Broken/Tools/LimitChecker.java

87 lines
2.5 KiB
Java
Raw Normal View History

package net.Broken.Tools;
2017-03-20 18:36:26 +01:00
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
/**
2018-02-28 17:59:09 +01:00
* Find max webPage for web site like baseURL.com/number-2/
2017-03-20 18:36:26 +01:00
*/
public class LimitChecker {
static Logger logger = LogManager.getLogger();
2018-02-28 17:59:09 +01:00
/**
* Check max page url for web site like baseURL.com/number-2/
* @param baseURL Base url without numbers
* @param minNumber Start number
* @return max Number
* @throws IOException
*/
public static int doYourJob(String baseURL, int minNumber, String suffix) throws IOException {
2017-03-20 18:36:26 +01:00
int number = minNumber;
URL u = null;
2018-11-22 01:59:30 +02:00
boolean redirected = false;
Redirection redirection = new Redirection();
2017-03-20 18:36:26 +01:00
2018-11-22 01:59:30 +02:00
while(!redirected )
2017-03-20 18:36:26 +01:00
{
String origin = baseURL+number+suffix;
2018-11-22 01:59:30 +02:00
String newUrl = redirection.get(origin);
logger.trace("Origin URL: "+origin+" Result: "+newUrl);
if(newUrl.equals(origin))
2017-03-20 18:36:26 +01:00
number += 500;
2018-11-22 01:59:30 +02:00
else
redirected = true;
2017-03-20 18:36:26 +01:00
}
number-=400;
2018-11-22 01:59:30 +02:00
redirected = false;
2018-11-22 15:31:26 +02:00
logger.debug("First pass: "+number);
2018-11-22 01:59:30 +02:00
while(!redirected )
2017-03-20 18:36:26 +01:00
{
String origin = baseURL+number+suffix;
2018-11-22 01:59:30 +02:00
String newUrl = redirection.get(origin);
logger.trace("Origin URL: "+origin+" Result: "+newUrl);
if(newUrl.equals(origin))
2017-03-20 18:36:26 +01:00
number += 100;
2018-11-22 01:59:30 +02:00
else
redirected = true;
2017-03-20 18:36:26 +01:00
}
number-=90;
2018-11-22 01:59:30 +02:00
redirected = false;
2018-11-22 15:31:26 +02:00
logger.debug("Second pass: "+number);
2018-11-22 01:59:30 +02:00
while(!redirected )
2017-03-20 18:36:26 +01:00
{
String origin = baseURL+number+suffix;
2018-11-22 01:59:30 +02:00
String newUrl = redirection.get(origin);
logger.trace("Origin URL: "+origin+" Result: "+newUrl);
if(newUrl.equals(origin))
2017-03-20 18:36:26 +01:00
number += 10;
2018-11-22 01:59:30 +02:00
else
redirected = true;
2017-03-20 18:36:26 +01:00
}
number-=9;
2018-11-22 01:59:30 +02:00
redirected = false;
2018-11-22 15:31:26 +02:00
logger.debug("Third pass: "+number);
2018-11-22 01:59:30 +02:00
while(!redirected )
2017-03-20 18:36:26 +01:00
{
String origin = baseURL+number+suffix;
2018-11-22 01:59:30 +02:00
String newUrl = redirection.get(origin);
logger.trace("Origin URL: "+origin+" Result: "+newUrl);
if(newUrl.equals(origin))
2017-03-20 18:36:26 +01:00
number += 1;
2018-11-22 01:59:30 +02:00
else
redirected = true;
2017-03-20 18:36:26 +01:00
}
number-=1;
2018-11-22 15:31:26 +02:00
logger.debug("Final pass: "+number);
2017-03-20 18:36:26 +01:00
return number;
}
}