List of usage examples for org.apache.http.impl.client RedirectLocations size
@Override public int size()
From source file:com.serphacker.serposcope.scraper.http.ScrapClient.java
public int request(HttpRequestBase request) { synchronized (connManager) { try {//from w w w.j a v a 2s . c om clearPreviousRequest(); executionTimeMS = System.currentTimeMillis(); HttpClientContext context = HttpClientContext.create(); initializeRequest(request, context); response = client.execute(request, context); statusCode = response.getStatusLine().getStatusCode(); RedirectLocations redirects = context.getAttribute(HttpClientContext.REDIRECT_LOCATIONS, RedirectLocations.class); if (redirects != null && !redirects.isEmpty()) { lastRedirect = redirects.get(redirects.size() - 1).toString(); } HttpEntity entity = response.getEntity(); long contentLength = entity.getContentLength(); if (contentLength > maxResponseLength) { throw new ResponseTooBigException("content length (" + contentLength + ") " + "is greater than max response leength (" + maxResponseLength + ")"); } InputStream stream = entity.getContent(); int totalRead = 0; int read = 0; while (totalRead < maxResponseLength && (read = stream.read(buffer, totalRead, maxResponseLength - totalRead)) != -1) { totalRead += read; } if (totalRead == maxResponseLength && read != 0) { throw new ResponseTooBigException("already read " + totalRead + " bytes"); } content = Arrays.copyOfRange(buffer, 0, totalRead); } catch (Exception ex) { content = null; statusCode = -1; exception = ex; } finally { proxyChangedSinceLastRequest = false; closeResponse(); executionTimeMS = System.currentTimeMillis() - executionTimeMS; } return statusCode; } }