List of usage examples for java.io UnsupportedEncodingException printStackTrace
public void printStackTrace()
From source file:Main.java
public static void PostRequest(String url, Map<String, String> params, String userName, String password, Handler messageHandler) { HttpPost postMethod = new HttpPost(url); List<NameValuePair> nvps = null; DefaultHttpClient client = new DefaultHttpClient(); if ((userName != null) && (userName.length() > 0) && (password != null) && (password.length() > 0)) { client.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password)); }// w w w .ja v a 2 s . c o m final Map<String, String> sendHeaders = new HashMap<String, String>(); sendHeaders.put(CONTENT_TYPE, MIME_FORM_ENCODED); client.addRequestInterceptor(new HttpRequestInterceptor() { @Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { for (String key : sendHeaders.keySet()) { if (!request.containsHeader(key)) { request.addHeader(key, sendHeaders.get(key)); } } } }); if ((params != null) && (params.size() > 0)) { nvps = new ArrayList<NameValuePair>(); for (String key : params.keySet()) { nvps.add(new BasicNameValuePair(key, params.get(key))); } } if (nvps != null) { try { postMethod.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } ExecutePostRequest(client, postMethod, GetResponseHandlerInstance(messageHandler)); }
From source file:com.gogh.plugin.easytranslation.TranslationRequest.java
static String getQueryUrl(String query) { String encodedQuery = ""; try {/*w w w .j a v a 2 s.c o m*/ encodedQuery = URLEncoder.encode(query, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } String[] apiKey = ApiConfig.getAPISet(); return IString.BASIC_URL + apiKey[0] + "&key=" + apiKey[1] + "&q=" + encodedQuery; }
From source file:edu.umass.cs.nio.JSONPacket.java
/** * @param bytes/*from w w w.j av a2s .c o m*/ * @return True if this {@code bytes} could be possibly (but not * necessarily) be in JSON format assuming the default * {@link MessageExtractor} encoding. */ public static final boolean couldBeJSON(byte[] bytes) { String str; try { str = MessageExtractor.decode(Arrays.copyOf(bytes, 4)); return str.startsWith("{") || str.startsWith("["); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return bytes[0] == '{' || bytes[0] == '['; }
From source file:edu.umass.cs.nio.JSONPacket.java
/** * @param bytes//from ww w .j a v a2 s.c o m * @param offset * @return True if this {@code bytes} could be possibly (but not * necessarily) be in JSON format assuming the default * {@link MessageExtractor} encoding. */ public static final boolean couldBeJSON(byte[] bytes, int offset) { String str; try { str = MessageExtractor.decode(Arrays.copyOfRange(bytes, offset, offset + 4)); return str.startsWith("{") || str.startsWith("["); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return bytes[offset] == '{' || bytes[offset] == '['; }
From source file:jedi.util.serialization.Pickle.java
/** * Receives a sequence of bytes and returns a object. * /*ww w . j av a 2s . co m*/ * @param s Sequence of bytes. * @return Object */ public static Object loads(String s) { Object o = null; ByteArrayInputStream bais; try { bais = new ByteArrayInputStream(Base64.decodeBase64(s.getBytes())); ObjectInputStream ois = new ObjectInputStream(bais); o = ois.readObject(); ois.close(); bais.close(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return o; }
From source file:es.bsc.demiurge.core.utils.HttpUtils.java
/** * Builds an HTTP Request.//from w w w. ja v a 2s . c o m * * @param methodType Type of the request (GET, POST, etc.). * @param uri URI of the request. * @param header Headers of the request. * @param entity Entity of the request. * @return The HTTP Request built. */ public static HttpRequestBase buildHttpRequest(String methodType, URI uri, Map<String, String> header, String entity) { HttpRequestBase request; //instantiate the request according to its type (GET, POST...) switch (methodType) { case "GET": request = new HttpGet(uri); break; case "POST": request = new HttpPost(uri); break; case "DELETE": request = new HttpDelete(uri); break; default: request = null; break; } if (request == null) { throw new IllegalArgumentException("Method not supported."); } //set the headers of the request for (Map.Entry<String, String> entry : header.entrySet()) { request.setHeader(entry.getKey(), entry.getValue()); } //if the type of the request is POST, set the entity of the request if (request instanceof HttpPost && !entity.equals("")) { try { ((HttpPost) request).setEntity(new StringEntity(entity)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } return request; }
From source file:com.mnt.base.util.SerializeUtil.java
/** * deserialize the source with decode|uncompress flag * decode first and then uncompress later * //ww w .jav a 2 s. c o m * @param source * @param decode * @param uncompress * @return */ public static Object deSerialize(String source, boolean decode, boolean uncompress) { byte[] data = null; try { data = source.getBytes(defaultEncoding); } catch (UnsupportedEncodingException e) { e.printStackTrace(); data = source.getBytes(); } if (decode) { data = Base64Codec.decode(data); } if (uncompress) { data = ZipUtil.decompress(data); } return deSerialize(data); }
From source file:com.mnt.base.util.SerializeUtil.java
/** * deserialize the source with decode|uncompress flag * decode first and then uncompress later * /*from w w w . j a v a2s .co m*/ * @param source * @param encode * @param compress * @return */ public static String serialize(Object source, boolean encode, boolean compress) { byte[] data = serialize(source); if (compress) { data = ZipUtil.compress(data); } if (encode) { data = Base64Codec.encode(data); } String result; try { result = new String(data, defaultEncoding); } catch (UnsupportedEncodingException e) { e.printStackTrace(); result = null; } return result; }
From source file:Main.java
/** * Encrypt and encode message using 256-bit AES with key generated from password. * * * @param password used to generated key * @param message the thing you want to encrypt assumed String UTF-8 * @return Base64 encoded CipherText/*from w w w . j a v a 2 s . co m*/ * @throws GeneralSecurityException if problems occur during encryption */ public static String encrypt(final String password, String message) { log("message", message); byte[] cipherText; try { final SecretKeySpec key = generateKey(password); cipherText = encrypt(key, ivBytes, nullPadString(message).getBytes(CHARSET)); //NO_WRAP is important as was getting \n at the end String encoded = Base64.encodeToString(cipherText, Base64.NO_WRAP); log("Base64.NO_WRAP", encoded); return encoded; } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (GeneralSecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:br.com.pfood.util.StringUtils.java
public static String getMD5(String senha) { String md5 = ""; try {//from ww w . j a v a2 s .c o m md5 = DigestUtils.md5Hex(senha.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return md5; }