use of org.apache.http.client.methods.HttpGet in project FastDev4Android by jiangqqlmj.
the class IoUtils method getInputStream.
/**
* 获取url的InputStream
*
* @param urlStr
* @return
*/
public static InputStream getInputStream(String urlStr) {
Log.d(TAG_LISTLOGIC, "get http input:" + urlStr);
InputStream inpStream = null;
try {
HttpGet http = new HttpGet(urlStr);
HttpClient client = new DefaultHttpClient();
HttpResponse response = (HttpResponse) client.execute(http);
HttpEntity httpEntity = response.getEntity();
BufferedHttpEntity bufferedHttpEntity = new BufferedHttpEntity(httpEntity);
// 获取数据流
inpStream = bufferedHttpEntity.getContent();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (inpStream != null) {
try {
inpStream.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
return inpStream;
}
use of org.apache.http.client.methods.HttpGet in project Talon-for-Twitter by klinker24.
the class VideoFragment method getDoc.
public Document getDoc() {
try {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet((tweetUrl.contains("http") ? "" : "https://") + tweetUrl);
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) sb.append(line + "\n");
String docHtml = sb.toString();
is.close();
return Jsoup.parse(docHtml);
} catch (Exception e) {
return null;
}
}
use of org.apache.http.client.methods.HttpGet in project pinot by linkedin.
the class BackfillControllerAPIs method getAllSegments.
/**
* Fetches the list of all segment names for a table
* @param tableName
* @return
* @throws IOException
*/
public List<String> getAllSegments(String tableName) throws IOException {
List<String> allSegments = new ArrayList<>();
HttpClient controllerClient = new DefaultHttpClient();
HttpGet req = new HttpGet(SEGMENTS_ENDPOINT + URLEncoder.encode(tableName, UTF_8));
HttpResponse res = controllerClient.execute(controllerHttpHost, req);
try {
if (res.getStatusLine().getStatusCode() != 200) {
throw new IllegalStateException(res.getStatusLine().toString());
}
InputStream content = res.getEntity().getContent();
String response = IOUtils.toString(content);
List<String> allSegmentsPaths = getSegmentsFromResponse(response);
for (String segment : allSegmentsPaths) {
allSegments.add(segment.substring(segment.lastIndexOf("/") + 1));
}
LOGGER.info("All segments : {}", allSegments);
} finally {
if (res.getEntity() != null) {
EntityUtils.consume(res.getEntity());
}
}
return allSegments;
}
use of org.apache.http.client.methods.HttpGet in project pinot by linkedin.
the class BackfillControllerAPIs method getSegmentMetadata.
/**
* Returns the metadata of a segment, given the segment name and table name
* @param tableName - table where segment resides
* @param segmentName - name of the segment
* @return
* @throws IOException
*/
public Map<String, String> getSegmentMetadata(String tableName, String segmentName) throws IOException {
Map<String, String> metadata = null;
HttpClient controllerClient = new DefaultHttpClient();
HttpGet req = new HttpGet(TABLES_ENDPOINT + URLEncoder.encode(tableName, UTF_8) + "/" + SEGMENTS_ENDPOINT + URLEncoder.encode(segmentName, UTF_8) + "/" + METADATA_ENDPOINT);
HttpResponse res = controllerClient.execute(controllerHttpHost, req);
try {
if (res.getStatusLine().getStatusCode() != 200) {
throw new IllegalStateException(res.getStatusLine().toString());
}
InputStream content = res.getEntity().getContent();
String metadataResponse = IOUtils.toString(content);
metadata = getMetadataFromResponse(metadataResponse);
} finally {
if (res.getEntity() != null) {
EntityUtils.consume(res.getEntity());
}
}
return metadata;
}
use of org.apache.http.client.methods.HttpGet in project pinot by linkedin.
the class SegmentPushControllerAPIs method deleteSegment.
private boolean deleteSegment(String tablename, String segmentName) throws IOException {
boolean deleteSuccessful = false;
HttpClient controllerClient = new DefaultHttpClient();
HttpGet req = new HttpGet(TABLES_ENDPOINT + URLEncoder.encode(tablename, UTF_8) + "/" + SEGMENTS_ENDPOINT + URLEncoder.encode(segmentName, UTF_8) + DROP_PARAMETERS);
HttpResponse res = controllerClient.execute(controllerHttpHost, req);
try {
if (res == null || res.getStatusLine() == null || res.getStatusLine().getStatusCode() != 200 || !isDeleteSuccessful(tablename, segmentName)) {
LOGGER.info("Exception in deleting segment, trying again {}", res);
} else {
deleteSuccessful = true;
}
} finally {
if (res.getEntity() != null) {
EntityUtils.consume(res.getEntity());
}
}
return deleteSuccessful;
}
Aggregations