List of usage examples for org.apache.http.protocol HTTP PLAIN_TEXT_TYPE
String PLAIN_TEXT_TYPE
To view the source code for org.apache.http.protocol HTTP PLAIN_TEXT_TYPE.
Click Source Link
From source file:Main.java
public static Intent shareText(String text) { return share(text, HTTP.PLAIN_TEXT_TYPE); }
From source file:im.delight.android.baselib.Social.java
/** * Constructs an Intent for sharing/sending plain text and starts Activity chooser for that Intent * * @param context Context reference to start the Activity chooser from * @param windowTitle the string to be used as the window title for the Activity chooser * @param messageText the body text for the message to be shared * @param messageTitle the title/subject for the message to be shared, if supported by the target app *//*from www . ja v a2 s. co m*/ public static void shareText(Context context, String windowTitle, String messageText, String messageTitle) { Intent intentInvite = new Intent(Intent.ACTION_SEND); intentInvite.setType(HTTP.PLAIN_TEXT_TYPE); intentInvite.putExtra(Intent.EXTRA_SUBJECT, messageTitle); intentInvite.putExtra(Intent.EXTRA_TEXT, messageText); context.startActivity(Intent.createChooser(intentInvite, windowTitle)); }
From source file:com.facebook.stetho.dumpapp.RawDumpappHandler.java
private static HttpEntity createResponseEntity(byte[] data) { ByteArrayEntity entity = new ByteArrayEntity(data); if (isProbablyBinaryData(data)) { entity.setContentType(HTTP.OCTET_STREAM_TYPE); } else {/* w w w . j ava2 s. com*/ entity.setContentType(HTTP.PLAIN_TEXT_TYPE); } return entity; }
From source file:im.delight.android.commons.Social.java
/** * Displays an application chooser and shares the specified plain text and subject line using the selected application * * @param context a context reference//from w ww . ja va2 s . c o m * @param windowTitle the title for the application chooser's window * @param bodyTextToShare the body text to be shared * @param subjectTextToShare the title or subject for the message to be shared, if supported by the target application */ public static void shareText(final Context context, final String windowTitle, final String bodyTextToShare, final String subjectTextToShare) { final Intent intentInvite = new Intent(Intent.ACTION_SEND); intentInvite.setType(HTTP.PLAIN_TEXT_TYPE); intentInvite.putExtra(Intent.EXTRA_SUBJECT, subjectTextToShare); intentInvite.putExtra(Intent.EXTRA_TEXT, bodyTextToShare); context.startActivity(Intent.createChooser(intentInvite, windowTitle)); }
From source file:com.nesscomputing.httpclient.factory.httpclient4.BetterStringEntity.java
/** * Creates a StringEntity with the specified content and charset * * @param string content to be used. Not {@code null}. * @param charset character set to be used. May be {@code null}, in which case the default is {@link HTTP#DEFAULT_CONTENT_CHARSET} i.e. "ISO-8859-1" * * @throws IllegalArgumentException if the string parameter is null *///from ww w. j a v a2s .c om BetterStringEntity(final String string, Charset charset) { super(); Preconditions.checkArgument(string != null, "Source string may not be null"); final Charset charsetObj = ObjectUtils.firstNonNull(charset, Charsets.ISO_8859_1); this.content = string.getBytes(charsetObj); setContentType(HTTP.PLAIN_TEXT_TYPE + HTTP.CHARSET_PARAM + charsetObj.name()); }
From source file:com.artqueen.knowu.PersonalityInsights.java
public String getProfile(String text) { if (text == null) throw new IllegalArgumentException("text can not be null"); HttpRequestBase request = Request.Post("/v2/profile").withContent(text, HTTP.PLAIN_TEXT_TYPE).build(); HttpResponse response = execute(request); try {/*from w w w. j a v a 2s .c o m*/ return ResponseUtil.getString(response); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.cloudbase.CBStringPart.java
/** * @param name String - name of parameter (may not be <code>null</code>). * @param value String - value of parameter (may not be <code>null</code>). * @param charset String, if null is passed then default "ISO-8859-1" charset is used. * //w w w.jav a 2 s. c o m * @throws IllegalArgumentException if either <code>value</code> * or <code>name</code> is <code>null</code>. * @throws RuntimeException if <code>charset</code> is unsupported by OS. */ public CBStringPart(String name, String value, String charset) { if (name == null) { throw new IllegalArgumentException("Name may not be null"); //$NON-NLS-1$ } if (value == null) { throw new IllegalArgumentException("Value may not be null"); //$NON-NLS-1$ } final String partName = CBUrlEncodingHelper.encode(name, HTTP.DEFAULT_PROTOCOL_CHARSET); if (charset == null) { charset = HTTP.DEFAULT_CONTENT_CHARSET; } final String partCharset = charset; try { this.valueBytes = value.getBytes(partCharset); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } headersProvider = new IHeadersProvider() { public String getContentDisposition() { return "Content-Disposition: form-data; name=\"" + partName + '"'; //$NON-NLS-1$ } public String getContentType() { return "Content-Type: " + HTTP.PLAIN_TEXT_TYPE + HTTP.CHARSET_PARAM + partCharset; //$NON-NLS-1$ } public String getContentTransferEncoding() { return "Content-Transfer-Encoding: 8bit"; //$NON-NLS-1$ } }; }
From source file:com.strato.hidrive.api.utils.multipart.StringPart.java
/** * @param name/*from w w w .j av a 2 s .c om*/ * String - name of parameter (may not be <code>null</code>). * @param value * String - value of parameter (may not be <code>null</code>). * @param charset * String, if null is passed then default "ISO-8859-1" charset is * used. * * @throws IllegalArgumentException * if either <code>value</code> or <code>name</code> is * <code>null</code>. * @throws RuntimeException * if <code>charset</code> is unsupported by OS. */ public StringPart(String name, String value, String charset) { if (name == null) { throw new IllegalArgumentException("Name may not be null"); //$NON-NLS-1$ } if (value == null) { throw new IllegalArgumentException("Value may not be null"); //$NON-NLS-1$ } final String partName = UrlEncodingHelper.encode(name, HTTP.DEFAULT_PROTOCOL_CHARSET); if (charset == null) { charset = HTTP.DEFAULT_CONTENT_CHARSET; } final String partCharset = charset; try { this.valueBytes = value.getBytes(partCharset); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } headersProvider = new IHeadersProvider() { public String getContentDisposition() { return "Content-Disposition: form-data; name=\"" + partName + '"'; //$NON-NLS-1$ } public String getContentType() { return "Content-Type: " + HTTP.PLAIN_TEXT_TYPE + HTTP.CHARSET_PARAM + partCharset; //$NON-NLS-1$ } public String getContentTransferEncoding() { return "Content-Transfer-Encoding: 8bit"; //$NON-NLS-1$ } }; }
From source file:org.andstatus.app.net.http.HttpConnectionApacheCommon.java
private void fillMultiPartPost(HttpPost postMethod, JSONObject formParams) throws ConnectionException { MultipartEntityBuilder builder = MultipartEntityBuilder.create(); Uri mediaUri = null;/* w w w .j av a 2 s .com*/ String mediaPartName = ""; Iterator<String> iterator = formParams.keys(); ContentType contentType = ContentType.create(HTTP.PLAIN_TEXT_TYPE, HTTP.UTF_8); while (iterator.hasNext()) { String name = iterator.next(); String value = formParams.optString(name); if (HttpConnection.KEY_MEDIA_PART_NAME.equals(name)) { mediaPartName = value; } else if (HttpConnection.KEY_MEDIA_PART_URI.equals(name)) { mediaUri = UriUtils.fromString(value); } else { // see http://stackoverflow.com/questions/19292169/multipartentitybuilder-and-charset builder.addTextBody(name, value, contentType); } } if (!TextUtils.isEmpty(mediaPartName) && !UriUtils.isEmpty(mediaUri)) { try { InputStream ins = MyContextHolder.get().context().getContentResolver().openInputStream(mediaUri); ContentType contentType2 = ContentType.create(MyContentType.uri2MimeType(mediaUri, null)); builder.addBinaryBody(mediaPartName, ins, contentType2, mediaUri.getPath()); } catch (SecurityException e) { throw new ConnectionException("mediaUri='" + mediaUri + "'", e); } catch (FileNotFoundException e) { throw new ConnectionException("mediaUri='" + mediaUri + "'", e); } } postMethod.setEntity(builder.build()); }
From source file:com.googlecode.osde.internal.igoogle.IgCredentials.java
private IgCredentials(String username, String password) throws IgException { // Retrieve sid. // TODO: Support captcha. sid = retrieveSid(username, password, null, null); validateSid();/*from w w w .j av a2 s .c o m*/ // Retrieve publidId. publicId = retrievePublicId(sid); validatePublicId(); // Prepare HttpGet for retrieving pref and editToken. HttpGet httpGet = new HttpGet(URL_IG_PREF_EDIT_TOKEN); httpGet.setHeader(HTTP.CONTENT_TYPE, HTTP.PLAIN_TEXT_TYPE); httpGet.addHeader(IgHttpUtil.HTTP_HEADER_COOKIE, "SID=" + sid); HttpClient httpClient = new DefaultHttpClient(); HttpResponse httpResponse; try { httpResponse = httpClient.execute(httpGet); } catch (ClientProtocolException e) { throw new IgException(e); } catch (IOException e) { throw new IgException(e); } logger.fine("status line: " + httpResponse.getStatusLine()); // Retrieve pref from headers. pref = retrievePref(httpResponse); validatePref(); // Retrieve editToken from response content. editToken = retrieveEditToken(httpClient, httpGet, httpResponse); validateEditToken(); }