use of org.apache.http.client.HttpClient in project PlayerHater by chrisrhoden.
the class PlaylistParser method parsePls.
private static Uri[] parsePls(Uri uri) {
try {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(new HttpGet(uri.toString()));
HttpEntity entity = response.getEntity();
InputStream inputStream = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String header = reader.readLine();
if (header.trim().equalsIgnoreCase("[playlist]")) {
String line;
ArrayList<Uri> uriList = new ArrayList<Uri>();
do {
line = reader.readLine();
if (line != null) {
if (line.startsWith("File")) {
String fileName = line.substring(line.indexOf("=") + 1).trim();
uriList.add(Uri.parse(fileName));
}
}
} while (line != null);
if (uriList.size() > 0) {
Uri[] res = new Uri[uriList.size()];
return uriList.toArray(res);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return new Uri[] { uri };
}
use of org.apache.http.client.HttpClient in project Android by hmkcode.
the class MainActivity method POST.
public static String POST(String url, Person person) {
InputStream inputStream = null;
String result = "";
try {
// 1. create HttpClient
HttpClient httpclient = new DefaultHttpClient();
// 2. make POST request to the given URL
HttpPost httpPost = new HttpPost(url);
String json = "";
// 3. build jsonObject
JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("name", person.getName());
jsonObject.accumulate("country", person.getCountry());
jsonObject.accumulate("twitter", person.getTwitter());
// 4. convert JSONObject to JSON to String
json = jsonObject.toString();
// ** Alternative way to convert Person object to JSON string usin Jackson Lib
// ObjectMapper mapper = new ObjectMapper();
// json = mapper.writeValueAsString(person);
// 5. set json to StringEntity
StringEntity se = new StringEntity(json);
// 6. set httpPost Entity
httpPost.setEntity(se);
// 7. Set some headers to inform server about the type of the content
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
// 8. Execute POST request to the given URL
HttpResponse httpResponse = httpclient.execute(httpPost);
// 9. receive response as inputStream
inputStream = httpResponse.getEntity().getContent();
// 10. convert inputstream to string
if (inputStream != null)
result = convertInputStreamToString(inputStream);
else
result = "Did not work!";
} catch (Exception e) {
Log.d("InputStream", e.getLocalizedMessage());
}
// 11. return result
return result;
}
use of org.apache.http.client.HttpClient in project rainbow by juankysoriano.
the class RainbowIO method createInputRaw.
/**
* Call createInput() without automatic gzip decompression.
*/
public static InputStream createInputRaw(Context context, final String filename) {
InputStream stream = null;
if (filename == null) {
return null;
}
if (filename.length() == 0) {
return null;
}
if (filename.indexOf(":") != -1) {
// at least smells like URL
try {
HttpGet httpRequest = null;
httpRequest = new HttpGet(URI.create(filename));
final HttpClient httpclient = new DefaultHttpClient();
final HttpResponse response = httpclient.execute(httpRequest);
final HttpEntity entity = response.getEntity();
return entity.getContent();
} catch (final MalformedURLException mfue) {
} catch (final FileNotFoundException fnfe) {
} catch (final IOException e) {
e.printStackTrace();
return null;
}
}
// Try the assets folder
final AssetManager assets = context.getAssets();
try {
stream = assets.open(filename);
if (stream != null) {
return stream;
}
} catch (final IOException e) {
}
// Maybe this is an absolute path, didja ever think of that?
final File absFile = new File(filename);
if (absFile.exists()) {
try {
stream = new FileInputStream(absFile);
if (stream != null) {
return stream;
}
} catch (final FileNotFoundException fnfe) {
// fnfe.printStackTrace();
}
}
// Maybe this is a file that was written by the sketch later.
final File sketchFile = new File(sketchPath(context, filename));
if (sketchFile.exists()) {
try {
stream = new FileInputStream(sketchFile);
if (stream != null) {
return stream;
}
} catch (final FileNotFoundException fnfe) {
}
}
// Attempt to load the file more directly. Doesn't like paths.
try {
stream = context.openFileInput(filename);
if (stream != null) {
return stream;
}
} catch (final FileNotFoundException e) {
}
return null;
}
use of org.apache.http.client.HttpClient 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.HttpClient 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;
}
Aggregations