/** * Specifies the Content-Type header, as a string. * The default implementation calls * {@link #setContentType(Header) setContentType(Header)}. * * @param ctString the new Content-Type header, or * <code>null</code> to unset */ public void setContentType(final String ctString) { Header h = null; if (ctString != null) { h = new BasicHeader(HTTP.CONTENT_TYPE, ctString); } setContentType(h); }
/** * Specifies the Content-Encoding header, as a string. * The default implementation calls * {@link #setContentEncoding(Header) setContentEncoding(Header)}. * * @param ceString the new Content-Encoding header, or * <code>null</code> to unset */ public void setContentEncoding(final String ceString) { Header h = null; if (ceString != null) { h = new BasicHeader(HTTP.CONTENT_ENCODING, ceString); } setContentEncoding(h); }
/** * Does not consume anything. * The default implementation does nothing if * {@link HttpEntity#isStreaming isStreaming} * returns <code>false</code>, and throws an exception * if it returns <code>true</code>. * This removes the burden of implementing * an empty method for non-streaming entities. * * @throws IOException in case of an I/O problem * @throws UnsupportedOperationException * if a streaming subclass does not override this method */ public void consumeContent() throws IOException, UnsupportedOperationException{ if (isStreaming()) { throw new UnsupportedOperationException ("streaming entity does not implement consumeContent()"); } } // consumeContent
} else if (this.serializable != null) { e = new SerializableEntity(this.serializable); e.setContentType(ContentType.DEFAULT_BINARY.toString()); } else if (this.file != null) { e = new FileEntity(this.file, getContentOrDefault(ContentType.DEFAULT_BINARY)); e = new BasicHttpEntity(); if (e.getContentType() != null && this.contentType != null) { e.setContentType(this.contentType.toString()); e.setContentEncoding(this.contentEncoding); e.setChunked(this.chunked); if (this.gzipCompress) { return new GzipCompressingEntity(e);
HttpPost request = new HttpPost(SERVICE_URI + uri); AbstractHttpEntity entity = new AbstractHttpEntity() { public boolean isRepeatable() { return true; } public long getContentLength() { return -1; } public boolean isStreaming() { return false; } public InputStream getContent() throws IOException { throw new UnsupportedOperationException(); } public void writeTo(final OutputStream outstream) throws IOException { Writer writer = new OutputStreamWriter(outstream, "UTF-8"); writer.write(arr, 0, arr.length); writer.flush(); } }; entity.setContentType("application/x-www-form-urlencoded"); entity.setContentEncoding(HTTP.UTF_8); request.setEntity(entity); HttpResponse response = null; InputStream bais = null; String result = null; try { response = client.execute(request); HttpEntity he = response.getEntity(); bais = he.getContent(); result = convertStreamToString(bais); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); }
entity = new ByteArrayEntity(content.data()); entity.setContentType(content.mediaType()); entity.setContentEncoding(content.charset()); base.setEntity(entity);
entityToBuild.setChunked(true);
public static HttpEntity buildInputStreamEntity(final ODataClient client, final InputStream input) { AbstractHttpEntity entity; boolean useChunked = client.getConfiguration().isUseChuncked(); if (shouldUseRepeatableHttpBodyEntry(client) || !useChunked) { byte[] bytes = new byte[0]; try { bytes = IOUtils.toByteArray(input); IOUtils.closeQuietly(input); } catch (IOException e) { throw new ODataRuntimeException("While reading input for not chunked encoding", e); } entity = new ByteArrayEntity(bytes); } else { entity = new InputStreamEntity(input, -1); } if (!useChunked && entity.getContentLength() < 0) { useChunked = true; } // both entities can be sent in chunked way or not entity.setChunked(useChunked); return entity; }
@Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append('['); if (contentType != null) { sb.append("Content-Type: "); sb.append(contentType.getValue()); sb.append(','); } if (contentEncoding != null) { sb.append("Content-Encoding: "); sb.append(contentEncoding.getValue()); sb.append(','); } final long len = getContentLength(); if (len >= 0) { sb.append("Content-Length: "); sb.append(len); sb.append(','); } sb.append("Chunked: "); sb.append(chunked); sb.append(']'); return sb.toString(); }
} else if (this.serializable != null) { e = new SerializableEntity(this.serializable); e.setContentType(ContentType.DEFAULT_BINARY.toString()); } else if (this.file != null) { e = new FileEntity(this.file, getContentOrDefault(ContentType.DEFAULT_BINARY)); e = new BasicHttpEntity(); if (e.getContentType() != null && this.contentType != null) { e.setContentType(this.contentType.toString()); e.setContentEncoding(this.contentEncoding); e.setChunked(this.chunked); if (this.gzipCompress) { return new GzipCompressingEntity(e);
httpEntity.setChunked(Boolean.parseBoolean(chunkedRequestEntity));
public static HttpEntity buildInputStreamEntity(final ODataClient client, final InputStream input) { AbstractHttpEntity entity; boolean useChunked = client.getConfiguration().isUseChuncked(); if (shouldUseRepeatableHttpBodyEntry(client) || !useChunked) { byte[] bytes = new byte[0]; try { bytes = IOUtils.toByteArray(input); IOUtils.closeQuietly(input); } catch (IOException e) { throw new ODataRuntimeException("While reading input for not chunked encoding", e); } entity = new ByteArrayEntity(bytes); } else { entity = new InputStreamEntity(input, -1); } if (!useChunked && entity.getContentLength() < 0) { useChunked = true; } // both entities can be sent in chunked way or not entity.setChunked(useChunked); return entity; }
@Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append('['); if (contentType != null) { sb.append("Content-Type: "); sb.append(contentType.getValue()); sb.append(','); } if (contentEncoding != null) { sb.append("Content-Encoding: "); sb.append(contentEncoding.getValue()); sb.append(','); } final long len = getContentLength(); if (len >= 0) { sb.append("Content-Length: "); sb.append(len); sb.append(','); } sb.append("Chunked: "); sb.append(chunked); sb.append(']'); return sb.toString(); }
} else if (this.serializable != null) { e = new SerializableEntity(this.serializable); e.setContentType(ContentType.DEFAULT_BINARY.toString()); } else if (this.file != null) { e = new FileEntity(this.file, getContentOrDefault(ContentType.DEFAULT_BINARY)); e = new BasicHttpEntity(); if (e.getContentType() != null && this.contentType != null) { e.setContentType(this.contentType.toString()); e.setContentEncoding(this.contentEncoding); e.setChunked(this.chunked); if (this.gzipCompress) { return new GzipCompressingEntity(e);
/** * Resolve Content */ protected void resolveContent(HttpEntity entity, HttpRequestBase httpRequest) throws IOException { if (entity != null) { ByteArrayOutputStream os = new ByteArrayOutputStream(); entity.writeTo(os); os.flush(); AbstractHttpEntity httpEntity = new org.apache.http.entity.ByteArrayEntity( os.toByteArray()); os.close(); httpEntity.setContentType(entity.getContentType().toString()); ((HttpEntityEnclosingRequestBase) httpRequest) .setEntity(httpEntity); } }
@Override public void setContentEncoding(final String contentEncoding) { httpEntity.setContentEncoding(contentEncoding); }
httpEntity.setChunked(Boolean.parseBoolean(chunkedRequestEntity));
@Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append('['); if (contentType != null) { sb.append("Content-Type: "); sb.append(contentType.getValue()); sb.append(','); } if (contentEncoding != null) { sb.append("Content-Encoding: "); sb.append(contentEncoding.getValue()); sb.append(','); } final long len = getContentLength(); if (len >= 0) { sb.append("Content-Length: "); sb.append(len); sb.append(','); } sb.append("Chunked: "); sb.append(chunked); sb.append(']'); return sb.toString(); }
/** * Does not consume anything. * The default implementation does nothing if * {@link HttpEntity#isStreaming isStreaming} * returns <code>false</code>, and throws an exception * if it returns <code>true</code>. * This removes the burden of implementing * an empty method for non-streaming entities. * * @throws IOException in case of an I/O problem * @throws UnsupportedOperationException * if a streaming subclass does not override this method */ public void consumeContent() throws IOException, UnsupportedOperationException{ if (isStreaming()) { throw new UnsupportedOperationException ("streaming entity does not implement consumeContent()"); } } // consumeContent
} else if (this.serializable != null) { e = new SerializableEntity(this.serializable); e.setContentType(ContentType.DEFAULT_BINARY.toString()); } else if (this.file != null) { e = new FileEntity(this.file, getContentOrDefault(ContentType.DEFAULT_BINARY)); e = new BasicHttpEntity(); if (e.getContentType() != null && this.contentType != null) { e.setContentType(this.contentType.toString()); e.setContentEncoding(this.contentEncoding); e.setChunked(this.chunked); if (this.gzipCompress) { return new GzipCompressingEntity(e);