use of org.apache.http.HttpEntity 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.HttpEntity in project android-volley by mcxiaoke.
the class HttpClientStack method setEntityIfNonEmptyBody.
private static void setEntityIfNonEmptyBody(HttpEntityEnclosingRequestBase httpRequest, Request<?> request) throws AuthFailureError {
byte[] body = request.getBody();
if (body != null) {
HttpEntity entity = new ByteArrayEntity(body);
httpRequest.setEntity(entity);
}
}
use of org.apache.http.HttpEntity in project pinpoint by naver.
the class DefaultClientExchangeHandlerImplStartMethodInterceptor method recordEntity.
protected void recordEntity(HttpMessage httpMessage, SpanEventRecorder recorder) {
if (httpMessage instanceof HttpEntityEnclosingRequest) {
final HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) httpMessage;
try {
final HttpEntity entity = entityRequest.getEntity();
if (entity != null && entity.isRepeatable() && entity.getContentLength() > 0) {
if (entitySampler.isSampling()) {
final String entityString = entityUtilsToString(entity, "UTF8", 1024);
recorder.recordAttribute(AnnotationKey.HTTP_PARAM_ENTITY, entityString);
}
}
} catch (Exception e) {
logger.debug("HttpEntityEnclosingRequest entity record fail. Caused:{}", e.getMessage(), e);
}
}
}
use of org.apache.http.HttpEntity in project neo4j by neo4j.
the class RetrieveNodeIT method shouldParameteriseUrisInNodeRepresentationWithHostHeaderValue.
@Test
public void shouldParameteriseUrisInNodeRepresentationWithHostHeaderValue() throws Exception {
HttpClient httpclient = new DefaultHttpClient();
try {
HttpGet httpget = new HttpGet(nodeUri);
httpget.setHeader("Accept", "application/json");
httpget.setHeader("Host", "dummy.neo4j.org");
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
String entityBody = IOUtils.toString(entity.getContent(), StandardCharsets.UTF_8);
assertThat(entityBody, containsString("http://dummy.neo4j.org/db/data/node/"));
} finally {
httpclient.getConnectionManager().shutdown();
}
}
use of org.apache.http.HttpEntity in project neo4j by neo4j.
the class RetrieveNodeIT method shouldParameteriseUrisInNodeRepresentationWithoutHostHeaderUsingRequestUri.
@Test
public void shouldParameteriseUrisInNodeRepresentationWithoutHostHeaderUsingRequestUri() throws Exception {
HttpClient httpclient = new DefaultHttpClient();
try {
HttpGet httpget = new HttpGet(nodeUri);
httpget.setHeader("Accept", "application/json");
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
String entityBody = IOUtils.toString(entity.getContent(), StandardCharsets.UTF_8);
assertThat(entityBody, containsString(nodeUri.toString()));
} finally {
httpclient.getConnectionManager().shutdown();
}
}
Aggregations