Java 类android.net.ParseException 实例源码

项目:MoligyMvpArms    文件:ResponseErrorListenerImpl.java   
@Override
public void handleResponseError(Context context, Throwable t) {
    Timber.tag("Catch-Error").w(t.getMessage());
    //这里不光是只能打印错误,还可以根据不同的错误作出不同的逻辑处理
    String msg = "未知错误";
    if (t instanceof UnknownHostException) {
        msg = "网络不可用";
    } else if (t instanceof SocketTimeoutException) {
        msg = "请求网络超时";
    } else if (t instanceof HttpException) {
        HttpException httpException = (HttpException) t;
        msg = convertStatusCode(httpException);
    } else if (t instanceof JsonParseException || t instanceof ParseException || t instanceof JSONException || t instanceof JsonIOException) {
        msg = "数据解析错误";
    }
    ArmsUtils.snackbarText(msg);
}
项目:amap    文件:InfoComparator.java   
public static Date stringToDate(String strTime)

    throws ParseException
{

    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    Date date = null;

    try
    {
        date = formatter.parse(strTime);
    }
    catch (java.text.ParseException e)
    {
        e.printStackTrace();
    }

    return date;

}
项目:amap    文件:GWSPInfoComparator.java   
public static Date stringToDate(String strTime)

    throws ParseException
{

    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    Date date = null;

    try
    {
        date = formatter.parse(strTime);
    }
    catch (java.text.ParseException e)
    {
        e.printStackTrace();
    }

    return date;

}
项目:GmArchMvvm    文件:ResponseErrorListenerImpl.java   
@Override
public void handleResponseError(Context context, Throwable t) {
    //Used to provide a monitor for handling all errors
    //rxjava need to use ErrorHandleSubscriber (the default implementation of Subscriber's onError method), this monitor to take effect
    Timber.tag("Catch-Error").w(t.getMessage());
    //Here is not only print errors, but also according to different errors to make different logical processing
    String msg = "Unknown";
    if (t instanceof UnknownHostException) {
        msg = "The network is not available";
    } else if (t instanceof SocketTimeoutException) {
        msg = "Network timeout";
    } else if (t instanceof HttpException) {
        HttpException httpException = (HttpException) t;
        msg = convertStatusCode(httpException);
    } else if (t instanceof JsonParseException || t instanceof ParseException || t instanceof JSONException || t instanceof JsonIOException) {
        msg = "Data parsing error";
    }
    UiUtils.snackbarText(msg);
}
项目:MVVMArms    文件:ResponseErrorListenerImpl.java   
@Override
public void handleResponseError(Context context, Throwable t) {
    //用来提供处理所有错误的监听
    //rxjava必要要使用ErrorHandleSubscriber(默认实现Subscriber的onError方法),此监听才生效
    Timber.tag("Catch-Error").w(t.getMessage());
    //这里不光是只能打印错误,还可以根据不同的错误作出不同的逻辑处理
    String msg = "未知错误";
    if (t instanceof UnknownHostException) {
        msg = "网络不可用";
    } else if (t instanceof SocketTimeoutException) {
        msg = "请求网络超时";
    } else if (t instanceof HttpException) {
        HttpException httpException = (HttpException) t;
        msg = convertStatusCode(httpException);
    } else if (t instanceof JsonParseException || t instanceof ParseException || t instanceof JSONException) {
        msg = "数据解析错误";
    }
    UiUtils.snackbarText(msg);
}
项目:MVPArms    文件:ResponseErrorListenerImpl.java   
@Override
public void handleResponseError(Context context, Throwable t) {
    Timber.tag("Catch-Error").w(t.getMessage());
    //这里不光是只能打印错误,还可以根据不同的错误作出不同的逻辑处理
    String msg = "未知错误";
    if (t instanceof UnknownHostException) {
        msg = "网络不可用";
    } else if (t instanceof SocketTimeoutException) {
        msg = "请求网络超时";
    } else if (t instanceof HttpException) {
        HttpException httpException = (HttpException) t;
        msg = convertStatusCode(httpException);
    } else if (t instanceof JsonParseException || t instanceof ParseException || t instanceof JSONException || t instanceof JsonIOException) {
        msg = "数据解析错误";
    }
    ArmsUtils.snackbarText(msg);
}
项目:deeplink-referrer    文件:AnalyticsApplication.java   
/** Returns the referrer on devices running SDK versions lower than 22. */
private Uri getReferrerCompatible(Activity activity) {
    Intent intent = activity.getIntent();
    Uri referrerUri = intent.getParcelableExtra(Intent.EXTRA_REFERRER);
    if (referrerUri != null) {
        return referrerUri;
    }
    String referrer = intent.getStringExtra(REFERRER_NAME);
    if (referrer != null) {
        // Try parsing the referrer URL; if it's invalid, return null
        try {
            return Uri.parse(referrer);
        } catch (ParseException e) {
            return null;
        }
    }
    return null;
}
项目:LabCam    文件:BaseSubscriber.java   
@Override
    public void onError(Throwable e) {
        if (baseView != null) {
            baseView.hideLoading();
        }
        if (e instanceof BusinessException) {

        } else if (e instanceof ConnectException
                || e instanceof SocketTimeoutException) {// 超时
            baseView.onError("网络不畅,请稍后再试!");
        } else if (e instanceof HttpException) {// server 异常
            httpExceptionHandling(e);
        } else if (e instanceof JSONException
                || e instanceof ParseException) {
            baseView.onError("数据解析异常");
        } else {
//            baseView.onError("出了点小问题");
            onOtherError(e);
        }
        e.printStackTrace();

    }
项目:quickmark    文件:FragmentPage3.java   
static String gofordate(String s) {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    Date date = null;
    try {
        date = format.parse(s);
    } catch (java.text.ParseException e) {
        e.printStackTrace();
    }
    String[] weekDays = { "周日", "周一", "周二", "周三", "周四", "周五", "周六" };
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
    if (w < 0)
        w = 0;
    System.out.println("date" + date + " weekDays " + weekDays[w]);
    return weekDays[w];
}
项目:synergykit-sdk-android    文件:ResultObjectBuilder.java   
public static SynergykitObject buildObject(int statusCode,BufferedReader data,Type type){

    // Param check
    if(data == null || statusCode!= HttpStatus.SC_OK)
        return null;


    // Build object
    try {   
        return (SynergykitObject) GsonWrapper.getGson().fromJson(data, type);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return null;
}
项目:synergykit-sdk-android    文件:ResultObjectBuilder.java   
public static SynergykitObject[] buildObjects(int statusCode, BufferedReader data, Type type){
    SynergykitObject[] baseObjects;

    // Param check
    if(data == null || statusCode!=HttpStatus.SC_OK)
        return null;

    // Build objects
    try {
        baseObjects = (SynergykitObject[]) GsonWrapper.getGson().fromJson(data, type);

        return baseObjects;

    } catch (ParseException e) {
        e.printStackTrace();
    }

    return null;
}
项目:synergykit-sdk-android    文件:ResultObjectBuilder.java   
public static SynergykitError buildError(int statusCode, BufferedReader data){
    SynergykitError errorObject;

    // Param check
    if(data == null)
        return null;


    // Build error
    try {
        errorObject =  (SynergykitError) GsonWrapper.getGson().fromJson(data, SynergykitError.class);
        errorObject.setStatusCode(statusCode);
        return errorObject;

    } catch (ParseException e) {
        e.printStackTrace();
    }

    return null;
}
项目:unicef_gis_mobile    文件:SyncAdapter.java   
private void handleException(String authtoken, Exception e,
        SyncResult syncResult) {
    if (e instanceof AuthenticatorException) {
        syncResult.stats.numParseExceptions++;
        Log.e("SyncAdapter", "AuthenticatorException", e);
    } else if (e instanceof OperationCanceledException) {
        Log.e("SyncAdapter", "OperationCanceledExcepion", e);
    } else if (e instanceof IOException) {
        Log.e("SyncAdapter", "IOException", e);
        syncResult.stats.numIoExceptions++;
    } else if (e instanceof AuthenticationException) {
        accountManager.invalidateAuthToken(Authenticator.ACCOUNT_TYPE, authtoken);
        syncResult.stats.numIoExceptions++;
        if (authtoken != null)
            Log.e("SyncAdapter", "Auth failed, invalidating token: " + authtoken);
        Log.e("SyncAdapter", "AuthenticationException", e);
    } else if (e instanceof ParseException) {
        syncResult.stats.numParseExceptions++;
        Log.e("SyncAdapter", "ParseException", e);
    } else if (e instanceof JsonParseException) {
        syncResult.stats.numParseExceptions++;
        Log.e("SyncAdapter", "JSONException", e);
    } else if (e instanceof ServerUrlPreferenceNotSetException) {
        Log.e("SyncAdapter", "ServerUrlPreferenceNotSetException", e);
    }
}
项目:nl.fhict.intellicloud.answers.android    文件:AnswerSync.java   
private ContentValues getAnswerContentValues(JSONObject answer) throws AuthenticationException, ParseException, OperationCanceledException, AuthenticatorException, JSONException, IOException
{
    ContentValues values = new ContentValues();
    values.put(AnswersEntry.COLUMN_TIMESTAMP, answer.optString("LastChangedTime"));
    values.put(AnswersEntry.COLUMN_ANSWER, answer.optString("Content"));
    values.put(AnswersEntry.COLUMN_DATE, SyncHelper.getUnixMillisecondsFromJsonDate(answer.optString("Date")));
    values.put(AnswersEntry.COLUMN_ANSWERSTATE, getAnswerStateForId(answer.optInt("answerState")).toString());//TODO

    String backendid = answer.optString("Id");
    if (backendid != null)
    {
        values.put(AnswersEntry.COLUMN_BACKEND_ID, SyncHelper.getIdFromURI(backendid));
    }
    String answerer = answer.optString("Answerer");
    if (answerer != null && !answerer.equals("null") && answerer.length() > 0)
    {
        values.put(AnswersEntry.COLUMN_ANSWERER_ID, SyncHelper.getRealIdForObjectURI(answerer, context));
    }
    return values;
}
项目:FriendBook    文件:AppException.java   
public static String getExceptionMessage(Throwable throwable) {
    String message;
    if (throwable instanceof ApiException) {
        message = throwable.getMessage();
    } else if (throwable instanceof SocketTimeoutException) {
        message = "网络连接超时,请稍后再试";
    } else if (throwable instanceof ConnectException) {
        message = "网络连接失败,请稍后再试";
    } else if (throwable instanceof HttpException||throwable instanceof retrofit2.HttpException) {
        message = "网络出错,请稍后再试";
    } else if (throwable instanceof UnknownHostException || throwable instanceof NetNotConnectedException) {
        message = "当前无网络,请检查网络设置";
    } else if (throwable instanceof SecurityException) {
        message = "系统权限不足";
    } else if (throwable instanceof JsonParseException
            || throwable instanceof JSONException
            || throwable instanceof ParseException) {
        message = "数据解析错误";
    } else if (throwable instanceof javax.net.ssl.SSLHandshakeException) {
        message = "网络证书验证失败";
    } else {
        message = throwable.getMessage();
        if (message==null||message.length() <= 40) {
            message = "出错了 ≥﹏≤ ,请稍后再试";
        }
    }
    return message;
}
项目:RetrofitSample    文件:BaseObserver.java   
@Override
public void onError(Throwable throwable) {

    if (throwable instanceof IOException) {
        if (throwable instanceof UnknownHostException) {
            //服务器异常
            handleError(INTERRUPTED_IOEXCEPTION, "网络异常,请稍后重试");
        } else if (throwable instanceof InterruptedIOException) {
            //超时异常
            handleError(INTERRUPTED_IOEXCEPTION, "网络异常,请稍后重试");
        } else {
            handleError(OTHER_IOEXCEPTION, "网络异常,请稍后重试");
        }
    } else if (throwable instanceof HttpException) {
        //retrofit请求木有返回
        handleError(HTTP_EXCEPTION, "网络异常,请稍后重试");
    } else if (throwable instanceof JsonParseException
            || throwable instanceof JSONException
            || throwable instanceof ParseException) {
        //解释数据错误
        handleError(EXCHANGE_DATA_ERROR, "解释数据错误");
    } else if (throwable instanceof DlException) {
        DlException dlException = (DlException) throwable;
        handleError(dlException.getErrorCode(), dlException.getErrorMessage());
    } else {
        handleError(UNKONW_EXCEPTION, "网络异常,请稍后重试");
    }
}
项目:camera    文件:AppUtil.java   
public static String gzipToString(final HttpEntity entity, final String defaultCharset) throws IOException, ParseException {
    if (entity == null) {
        throw new IllegalArgumentException("HTTP entity may not be null");
    }
    InputStream instream = entity.getContent();
    if (instream == null) {
        return "";
    }
    // gzip logic start
    if (entity.getContentEncoding().getValue().contains("gzip")) {
        instream = new GZIPInputStream(instream);
    }
    // gzip logic end
    if (entity.getContentLength() > Integer.MAX_VALUE) {
        throw new IllegalArgumentException("HTTP entity too large to be buffered in memory");
    }
    int i = (int)entity.getContentLength();
    if (i < 0) {
        i = 4096;
    }
    String charset = EntityUtils.getContentCharSet(entity);
    if (charset == null) {
        charset = defaultCharset;
    }
    if (charset == null) {
        charset = HTTP.DEFAULT_CONTENT_CHARSET;
    }
    Reader reader = new InputStreamReader(instream, charset);
    CharArrayBuffer buffer = new CharArrayBuffer(i);
    try {
        char[] tmp = new char[1024];
        int l;
        while((l = reader.read(tmp)) != -1) {
            buffer.append(tmp, 0, l);
        }
    } finally {
        reader.close();
    }
    return buffer.toString();
}
项目:ZzuNews    文件:AppUtil.java   
public static String gzipToString(final HttpEntity entity, final String defaultCharset) throws IOException, ParseException {
    if (entity == null) {
        throw new IllegalArgumentException("HTTP entity may not be null");
    }
    InputStream instream = entity.getContent();
    if (instream == null) {
        return "";
    }
    // gzip logic start
    if (entity.getContentEncoding().getValue().contains("gzip")) {
        instream = new GZIPInputStream(instream);
    }
    // gzip logic end
    if (entity.getContentLength() > Integer.MAX_VALUE) {
        throw new IllegalArgumentException("HTTP entity too large to be buffered in memory");
    }
    int i = (int)entity.getContentLength();
    if (i < 0) {
        i = 4096;
    }
    String charset = EntityUtils.getContentCharSet(entity);
    if (charset == null) {
        charset = defaultCharset;
    }
    if (charset == null) {
        charset = HTTP.DEFAULT_CONTENT_CHARSET;
    }
    Reader reader = new InputStreamReader(instream, charset);
    CharArrayBuffer buffer = new CharArrayBuffer(i);
    try {
        char[] tmp = new char[1024];
        int l;
        while((l = reader.read(tmp)) != -1) {
            buffer.append(tmp, 0, l);
        }
    } finally {
        reader.close();
    }
    return buffer.toString();
}
项目:ZzuNews    文件:AppUtil.java   
public static String gzipToString(final HttpEntity entity, final String defaultCharset) throws IOException, ParseException {
    if (entity == null) {
        throw new IllegalArgumentException("HTTP entity may not be null");
    }
    InputStream instream = entity.getContent();
    if (instream == null) {
        return "";
    }
    // gzip logic start
    if (entity.getContentEncoding().getValue().contains("gzip")) {
        instream = new GZIPInputStream(instream);
    }
    // gzip logic end
    if (entity.getContentLength() > Integer.MAX_VALUE) {
        throw new IllegalArgumentException("HTTP entity too large to be buffered in memory");
    }
    int i = (int)entity.getContentLength();
    if (i < 0) {
        i = 4096;
    }
    String charset = EntityUtils.getContentCharSet(entity);
    if (charset == null) {
        charset = defaultCharset;
    }
    if (charset == null) {
        charset = HTTP.DEFAULT_CONTENT_CHARSET;
    }
    Reader reader = new InputStreamReader(instream, charset);
    CharArrayBuffer buffer = new CharArrayBuffer(i);
    try {
        char[] tmp = new char[1024];
        int l;
        while((l = reader.read(tmp)) != -1) {
            buffer.append(tmp, 0, l);
        }
    } finally {
        reader.close();
    }
    return buffer.toString();
}
项目:chromium_webview    文件:CookieManagerAdapter.java   
@Override
public void setCookie(String url, String value) {
    try {
        mChromeCookieManager.setCookie(fixupUrl(url), value);
    } catch (ParseException e) {
        Log.e(LOGTAG, "Not setting cookie due to error parsing URL: " + url, e);
    }
}
项目:chromium_webview    文件:CookieManagerAdapter.java   
@Override
public String getCookie(String url) {
    try {
        return mChromeCookieManager.getCookie(fixupUrl(url));
    } catch (ParseException e) {
        Log.e(LOGTAG, "Unable to get cookies due to error parsing URL: " + url, e);
        return null;
    }
}
项目:chromium_webview    文件:CookieManagerAdapter.java   
private static String fixupUrl(String url) throws ParseException {
        // WebAddress is a private API in the android framework and a "quirk"
        // of the Classic WebView implementation that allowed embedders to
        // be relaxed about what URLs they passed into the CookieManager, so we
        // do the same normalisation before entering the chromium stack.
// TODO(alex): fixupUrl
//        return new WebAddress(url).toString();
        return url;
    }
项目:nl.fhict.intellicloud.answers.android    文件:SyncHelper.java   
public static JSONArray performNetworkPostRequest(String uri, JSONObject params, Context context)
        throws JSONException, ParseException, IOException, AuthenticationException, OperationCanceledException, AuthenticatorException
{
    final JSONArray serverArray;
    StringEntity entity = new StringEntity(params.toString());
    HttpPost request = new HttpPost(uri);
    request.setEntity(entity);
    request.addHeader(HTTP.CONTENT_TYPE, "application/json; charset=UTF-8");
       request.addHeader(AUTHORIZATION_HEADER, getBase64AuthorizationHeader(context));


       final HttpResponse resp = getHttpClient().execute(request);
       final String response = EntityUtils.toString(resp.getEntity());
       if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {

           serverArray = new JSONArray(response);
           Log.d(TAG, response);

       } else {
           if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
               Log.e(TAG, "Authentication exception in sending request");
               throw new AuthenticationException();
           } else {
               Log.e(TAG, "Server error in sending request: " + resp.getStatusLine());
               throw new IOException();
           }
       }

    return serverArray;
}
项目:nl.fhict.intellicloud.answers.android    文件:ServerAccessor.java   
public void syncQuestions() throws AuthenticationException, ParseException, OperationCanceledException, AuthenticatorException, JSONException, IOException, RemoteException
{
    JSONArray questionResultArray = SyncHelper.performNetworkGetRequest(URI_GET_QUESTIONS, context);
    if (questionResultArray != null)
    {
        //Log.d("ServerAccessor", questionIdArray.toString());
        QuestionsSync questionsSync = new QuestionsSync(context, contentProviderClient);
        questionsSync.syncQuestions(questionResultArray);
    }
}
项目:nl.fhict.intellicloud.answers.android    文件:ServerAccessor.java   
public void syncUsers() throws AuthenticationException, ParseException, OperationCanceledException, AuthenticatorException, JSONException, IOException, RemoteException
{
    JSONArray userResultArray = SyncHelper.performNetworkGetRequest(URI_GET_USERS, context);
    if (userResultArray != null)
    {
        UserSync userSync = new UserSync(context, contentProviderClient);
        userSync.syncUsers(userResultArray);
    }
}
项目:nl.fhict.intellicloud.answers.android    文件:ServerAccessor.java   
public void syncAnswers() throws AuthenticationException, ParseException, OperationCanceledException, AuthenticatorException, JSONException, IOException, RemoteException
{
    JSONArray answerResultArray = SyncHelper.performNetworkGetRequest(URI_GET_ANSWERS, context);
    if (answerResultArray != null)
    {
        AnswerSync answerSync = new AnswerSync(context, contentProviderClient);
        ArrayList<JSONObject> newAnswers = answerSync.syncAnswers(answerResultArray);
        for (JSONObject sendObject : newAnswers)
        {
            SyncHelper.performNetworkPostRequest(URI_POST_ANSWERS, sendObject, context);
        }
    }

}
项目:nl.fhict.intellicloud.answers.android    文件:ServerAccessor.java   
public void syncReviews() throws AuthenticationException, ParseException, OperationCanceledException, AuthenticatorException, JSONException, IOException, RemoteException
{
    JSONArray answerResultArray = SyncHelper.performNetworkGetRequest(URI_GET_REVIEWS, context);

    ReviewSync reviewSync = new ReviewSync(context, contentProviderClient);
    ArrayList<JSONObject> newAnswers = reviewSync.syncReviews(answerResultArray);
    for (JSONObject sendObject : newAnswers)
    {
        SyncHelper.performNetworkPostRequest(URI_POST_REVIEWS, sendObject, context);
    }

}
项目:nl.fhict.intellicloud.answers.android    文件:ReviewSync.java   
private ContentValues getReviewContentValues(JSONObject review) throws AuthenticationException, ParseException, OperationCanceledException, AuthenticatorException, JSONException, IOException
{
    ContentValues values = new ContentValues();
    values.put(ReviewsEntry.COLUMN_TIMESTAMP, review.optString("LastChangedTime"));
    //values.put(ReviewsEntry.COLUMN_DATE, review.optString("Date"));
    values.put(ReviewsEntry.COLUMN_REVIEW, review.optString("Review"));
    values.put(ReviewsEntry.COLUMN_REVIEWSTATE, review.optInt("ReviewState"));


    String answer = review.optString("Answer");
    if (answer != null && !answer.equals("null") && answer.length() > 0)
    {
        values.put(ReviewsEntry.COLUMN_ANSWER_ID, SyncHelper.getRealIdForObjectURI(answer, context));
    }
    String reviewer = review.optString("Reviewer");
    if (reviewer != null && !reviewer.equals("null") && reviewer.length() > 0)
    {
        values.put(ReviewsEntry.COLUMN_REVIEWER_ID, SyncHelper.getRealIdForObjectURI(reviewer,context));

    }
    String backendid = review.optString("Id");
    if (backendid != null)
    {
        values.put(ReviewsEntry.COLUMN_BACKEND_ID, SyncHelper.getIdFromURI(backendid));
    }
    return values;
}
项目:nl.fhict.intellicloud.answers.android    文件:QuestionsSync.java   
private ContentValues getQuestionContentValues(JSONObject question) throws RemoteException, AuthenticationException, ParseException, OperationCanceledException, AuthenticatorException, JSONException, IOException
    {
        Log.d("QuestionSync", question.toString());
        ContentValues values = new ContentValues();
        values.put(QuestionsEntry.COLUMN_TIMESTAMP, SyncHelper.getUnixMillisecondsFromJsonDate(question.optString("LastChangedTime")));
        values.put(QuestionsEntry.COLUMN_QUESTION, question.optString("Content"));
        values.put(QuestionsEntry.COLUMN_DATE, SyncHelper.getUnixMillisecondsFromJsonDate(question.optString("CreationTime")));

        values.put(QuestionsEntry.COLUMN_TITLE, question.optString("Title"));
        values.put(QuestionsEntry.COLUMN_IS_PRIVATE, question.optString("IsPrivate"));
        values.put(QuestionsEntry.COLUMN_QUESTIONSTATE, getQuestionState(question.optInt("QuestionState")).toString());

        String backendid = question.optString("Id");
        if (backendid != null)
        {
            values.put(QuestionsEntry.COLUMN_BACKEND_ID, SyncHelper.getIdFromURI(backendid));
        }

        String answer = question.optString("AnswerId");
        if (answer != null && !answer.equals("null") && answer.length() > 0)
        {
            int answerId = Integer.parseInt(answer);
            values.put(QuestionsEntry.COLUMN_ANSWER_ID, answerId);
            addQuestionIdToAnswer(answerId, SyncHelper.getIdFromURI(backendid));
        }
        String answerer = question.optString("Answerer");
        //NOTE: This returns a badrequest.
//      if (answerer != null && !answerer.equals("null") && answerer.length() > 0) 
//      {
//          values.put(QuestionsEntry.COLUMN_ANSWERER_ID, SyncHelper.getRealIdForObjectURI(answerer,context));
//      }
        String asker = question.optString("User");
        if (asker != null && !asker.equals("null") && asker.length() > 0)
        {
            values.put(QuestionsEntry.COLUMN_ASKER_ID, SyncHelper.getRealIdForObjectURI(asker,context));
        }

        return values;
    }
项目:android_xcore    文件:HttpAndroidDataSource.java   
@Override
public void statusHandle(HttpAndroidDataSource dataSource, HttpUriRequest request, HttpResponse response) throws ParseException,
        IOException {
    int statusCode = response.getStatusLine().getStatusCode();
    HttpEntity httpEntity = response.getEntity();
    if (statusCode != HttpStatus.SC_OK) {
        String entityValue = EntityUtils.toString(httpEntity);
        Log.e(TAG, response.getStatusLine().getReasonPhrase() + " " + entityValue);
        throw new IOStatusException(response.getStatusLine().getReasonPhrase(), statusCode, entityValue);
    }
}
项目:XSnow    文件:ApiException.java   
public static ApiException handleException(Throwable e) {
    ApiException ex;
    if (e instanceof HttpException) {
        HttpException httpException = (HttpException) e;
        ex = new ApiException(e, ApiCode.Request.HTTP_ERROR);
        switch (httpException.code()) {
            case ApiCode.Http.UNAUTHORIZED:
            case ApiCode.Http.FORBIDDEN:
            case ApiCode.Http.NOT_FOUND:
            case ApiCode.Http.REQUEST_TIMEOUT:
            case ApiCode.Http.GATEWAY_TIMEOUT:
            case ApiCode.Http.INTERNAL_SERVER_ERROR:
            case ApiCode.Http.BAD_GATEWAY:
            case ApiCode.Http.SERVICE_UNAVAILABLE:
            default:
                ex.message = "NETWORK_ERROR";
                break;
        }
        return ex;
    } else if (e instanceof JsonParseException || e instanceof JSONException || e instanceof ParseException) {
        ex = new ApiException(e, ApiCode.Request.PARSE_ERROR);
        ex.message = "PARSE_ERROR";
        return ex;
    } else if (e instanceof ConnectException) {
        ex = new ApiException(e, ApiCode.Request.NETWORK_ERROR);
        ex.message = "NETWORK_ERROR";
        return ex;
    } else if (e instanceof javax.net.ssl.SSLHandshakeException) {
        ex = new ApiException(e, ApiCode.Request.SSL_ERROR);
        ex.message = "SSL_ERROR";
        return ex;
    } else if (e instanceof SocketTimeoutException) {
        ex = new ApiException(e, ApiCode.Request.TIMEOUT_ERROR);
        ex.message = "TIMEOUT_ERROR";
        return ex;
    } else {
        ex = new ApiException(e, ApiCode.Request.UNKNOWN);
        ex.message = "UNKNOWN";
        return ex;
    }
}
项目:AndroidBasicLibs    文件:ApiException.java   
public static ApiException handleException(Throwable e) {
    ApiException ex;
    if (e instanceof HttpException) {
        HttpException httpException = (HttpException) e;
        ex = new ApiException(e, ApiCode.Request.HTTP_ERROR);
        switch (httpException.code()) {
            case ApiCode.Http.UNAUTHORIZED:
            case ApiCode.Http.FORBIDDEN:
            case ApiCode.Http.NOT_FOUND:
            case ApiCode.Http.REQUEST_TIMEOUT:
            case ApiCode.Http.GATEWAY_TIMEOUT:
            case ApiCode.Http.INTERNAL_SERVER_ERROR:
            case ApiCode.Http.BAD_GATEWAY:
            case ApiCode.Http.SERVICE_UNAVAILABLE:
            default:
                ex.message = "NETWORK_ERROR";
                break;
        }
        return ex;
    } else if (e instanceof JsonParseException || e instanceof JSONException || e instanceof ParseException) {
        ex = new ApiException(e, ApiCode.Request.PARSE_ERROR);
        ex.message = "PARSE_ERROR";
        return ex;
    } else if (e instanceof ConnectException) {
        ex = new ApiException(e, ApiCode.Request.NETWORK_ERROR);
        ex.message = "NETWORK_ERROR";
        return ex;
    } else if (e instanceof javax.net.ssl.SSLHandshakeException) {
        ex = new ApiException(e, ApiCode.Request.SSL_ERROR);
        ex.message = "SSL_ERROR";
        return ex;
    } else if (e instanceof SocketTimeoutException) {
        ex = new ApiException(e, ApiCode.Request.TIMEOUT_ERROR);
        ex.message = "TIMEOUT_ERROR";
        return ex;
    } else {
        ex = new ApiException(e, ApiCode.Request.UNKNOWN);
        ex.message = "UNKNOWN";
        return ex;
    }
}
项目:RxEasyHttp    文件:ApiException.java   
public static ApiException handleException(Throwable e) {
    ApiException ex;
    if (e instanceof HttpException) {
        HttpException httpException = (HttpException) e;
        ex = new ApiException(httpException, httpException.code());
        /*switch (httpException.code()) {
            case BADREQUEST:
            case UNAUTHORIZED:
            case FORBIDDEN:
            case NOT_FOUND:
            case REQUEST_TIMEOUT:
            case GATEWAY_TIMEOUT:
            case INTERNAL_SERVER_ERROR:
            case BAD_GATEWAY:
            case SERVICE_UNAVAILABLE:
            default:
                ex.message = "网络错误,Code:"+httpException.code()+" ,err:"+httpException.getMessage();
                break;
        }*/
        ex.message = httpException.getMessage();
        return ex;
    } else if (e instanceof ServerException) {
        ServerException resultException = (ServerException) e;
        ex = new ApiException(resultException, resultException.getErrCode());
        ex.message = resultException.getMessage();
        return ex;
    } else if (e instanceof JsonParseException
            || e instanceof JSONException
            || e instanceof JsonSyntaxException
            || e instanceof JsonSerializer
            || e instanceof NotSerializableException
            || e instanceof ParseException) {
        ex = new ApiException(e, ERROR.PARSE_ERROR);
        ex.message = "解析错误";
        return ex;
    } else if (e instanceof ClassCastException) {
        ex = new ApiException(e, ERROR.CAST_ERROR);
        ex.message = "类型转换错误";
        return ex;
    } else if (e instanceof ConnectException) {
        ex = new ApiException(e, ERROR.NETWORD_ERROR);
        ex.message = "连接失败";
        return ex;
    } else if (e instanceof javax.net.ssl.SSLHandshakeException) {
        ex = new ApiException(e, ERROR.SSL_ERROR);
        ex.message = "证书验证失败";
        return ex;
    } else if (e instanceof ConnectTimeoutException) {
        ex = new ApiException(e, ERROR.TIMEOUT_ERROR);
        ex.message = "连接超时";
        return ex;
    } else if (e instanceof java.net.SocketTimeoutException) {
        ex = new ApiException(e, ERROR.TIMEOUT_ERROR);
        ex.message = "连接超时";
        return ex;
    } else if (e instanceof UnknownHostException) {
        ex = new ApiException(e, ERROR.UNKNOWNHOST_ERROR);
        ex.message = "无法解析该域名";
        return ex;
    } else if (e instanceof NullPointerException) {
        ex = new ApiException(e, ERROR.NULLPOINTER_EXCEPTION);
        ex.message = "NullPointerException";
        return ex;
    } else {
        ex = new ApiException(e, ERROR.UNKNOWN);
        ex.message = "未知错误";
        return ex;
    }
}
项目:MvpRxJavaRetrofitOkhttp    文件:ExceptionEngine.java   
public static ApiException handleException(Throwable e) {
    ApiException ex;
    if (e instanceof ServerException) { // HTTP错误
        ServerException httpException = (ServerException) e;
        ex = new ApiException(e, ErrorType.HTTP_ERROR);
        switch (httpException.code) {
            case FAIL:
                ex.message = "userName or passWord is error!";
                break;
            case UNAUTHORIZED:
                ex.message = "当前请求需要用户验证";
                break;
            case FORBIDDEN:
                ex.message = "服务器已经理解请求,但是拒绝执行它";
                break;
            case NOT_FOUND:
                ex.message = "服务器异常,请稍后再试";
                break;
            case REQUEST_TIMEOUT:
                ex.message = "请求超时";
                break;
            case GATEWAY_TIMEOUT:
                ex.message = "作为网关或者代理工作的服务器尝试执行请求时,未能及时从上游服务器(URI标识出的服务器,例如HTTP、FTP、LDAP" +
                        ")或者辅助服务器(例如DNS)收到响应";
                break;
            case INTERNAL_SERVER_ERROR:
                ex.message = "服务器遇到了一个未曾预料的状况,导致了它无法完成对请求的处理";
                break;
            case BAD_GATEWAY:
                ex.message = "作为网关或者代理工作的服务器尝试执行请求时,从上游服务器接收到无效的响应";
                break;
            case SERVICE_UNAVAILABLE:
                ex.message = "由于临时的服务器维护或者过载,服务器当前无法处理请求";
                break;
            default:
                ex.message = "网络错误"; // 其它均视为网络错误
                break;
        }
        return ex;
    } else if (e instanceof ServerException) { // 服务器返回的错误
        ServerException resultException = (ServerException) e;
        ex = new ApiException(resultException, resultException.code);
        ex.message = resultException.message;
        return ex;
    } else if (e instanceof JSONException
            || e instanceof ParseException) {
        ex = new ApiException(e, ErrorType.PARSE_ERROR);
        ex.message = "解析错误"; // 均视为解析错误
        return ex;
    } else if (e instanceof ConnectException || e instanceof SocketTimeoutException || e
            instanceof ConnectTimeoutException) {
        ex = new ApiException(e, ErrorType.NETWORK_ERROR);
        ex.message = "连接失败"; // 均视为网络错误
        return ex;
    } else if (e instanceof HttpException) {
        if ("HTTP 404 Not Found".equals(e.getMessage())) {
            ex = new ApiException(e, ErrorType.NETWORK_ERROR);
            ex.message = "没有连接服务器";
        } else {
            ex = new ApiException(e, ErrorType.NETWORK_ERROR);
            ex.message = "其他连接服务器错误";
        }
        return ex;

    } else {
        ex = new ApiException(e, ErrorType.UNKONW);
        ex.message = "未知错误"; // 未知错误
        return ex;
    }
}
项目:MeiLa_GNN    文件:ExceptionHandle.java   
public static ResponeThrowable handleException(Throwable e) {
    ResponeThrowable ex;
    if (e instanceof HttpException) {
        HttpException httpException = (HttpException) e;
        ex = new ResponeThrowable(e, ERROR.HTTP_ERROR);
        switch (httpException.code()) {
            case UNAUTHORIZED:
            case FORBIDDEN:
            case NOT_FOUND:
            case REQUEST_TIMEOUT:
            case GATEWAY_TIMEOUT:
            case INTERNAL_SERVER_ERROR:
            case BAD_GATEWAY:
            case SERVICE_UNAVAILABLE:
            default:
                ex.message = "网络错误";
                break;
        }
        return ex;
    } else if (e instanceof ServerException) {
        ServerException resultException = (ServerException) e;
        ex = new ResponeThrowable(resultException, resultException.code);
        ex.message = resultException.message;
        return ex;
    } else if (e instanceof JsonParseException
            || e instanceof JSONException
            || e instanceof ParseException) {
        ex = new ResponeThrowable(e, ERROR.PARSE_ERROR);
        ex.message = "解析错误";
        return ex;
    } else if (e instanceof ConnectException) {
        ex = new ResponeThrowable(e, ERROR.NETWORD_ERROR);
        ex.message = "连接失败";
        return ex;
    } else if (e instanceof javax.net.ssl.SSLHandshakeException) {
        ex = new ResponeThrowable(e, ERROR.SSL_ERROR);
        ex.message = "证书验证失败";
        return ex;
    } else if (e instanceof ConnectTimeoutException) {
        ex = new ResponeThrowable(e, ERROR.TIMEOUT_ERROR);
        ex.message = "连接超时";
        return ex;
    } else if (e instanceof java.net.SocketTimeoutException) {
        ex = new ResponeThrowable(e, ERROR.TIMEOUT_ERROR);
        ex.message = "连接超时";
        return ex;
    } else {
        ex = new ResponeThrowable(e, ERROR.UNKNOWN);
        ex.message = "未知错误";
        return ex;
    }
}
项目:DereHelper    文件:ExceptionHandler.java   
public static void handleException(Throwable e) {
    ResponseThrowable ex;
    @StringRes int msg = R.string.network_error_0;
    if (e instanceof HttpException) {
        HttpException httpException = (HttpException) e;
        ex = new ResponseThrowable(e, ERROR.HTTP_ERROR);
        switch (httpException.code()) {
            case UNAUTHORIZED:
            case FORBIDDEN:
            case NOT_FOUND:
            case REQUEST_TIMEOUT:
            case GATEWAY_TIMEOUT:
            case INTERNAL_SERVER_ERROR:
            case BAD_GATEWAY:
            case SERVICE_UNAVAILABLE:
            default:
                ex.message = "网络错误";
                msg = R.string.network_error_0;
                break;
        }
    } else if (e instanceof ServerException) {
        ServerException resultException = (ServerException) e;
        ex = new ResponseThrowable(resultException, resultException.code);
        ex.message = resultException.message;
    } else if (e instanceof JsonParseException
            || e instanceof JSONException
            || e instanceof ParseException) {
        ex = new ResponseThrowable(e, ERROR.PARSE_ERROR);
        ex.message = "解析错误";
        msg = R.string.network_error_2;
    } else if (e instanceof ConnectException) {
        ex = new ResponseThrowable(e, ERROR.NETWORK_ERROR);
        ex.message = "连接失败";
        msg = R.string.network_error_1;
    } else if (e instanceof javax.net.ssl.SSLHandshakeException) {
        ex = new ResponseThrowable(e, ERROR.SSL_ERROR);
        ex.message = "证书验证失败";
        msg = R.string.network_error_3;
    } else if (e instanceof ConnectTimeoutException){
        ex = new ResponseThrowable(e, ERROR.TIMEOUT_ERROR);
        ex.message = "连接超时";
        msg = R.string.network_error_4;
    } else if (e instanceof java.net.SocketTimeoutException) {
        ex = new ResponseThrowable(e, ERROR.TIMEOUT_ERROR);
        ex.message = "连接超时";
        msg = R.string.network_error_4;
    }
    else {
        ex = new ResponseThrowable(e, ERROR.UNKNOWN);
        ex.message = "未知错误";
        msg = R.string.network_error_5;

    }
    if (msg != R.string.network_error_5){
        Toast.makeText(Base.getTopContext(), msg, Toast.LENGTH_SHORT).show();
    }
    ex.printStackTrace();
}
项目:SuperHttp    文件:ApiException.java   
public static ApiException handleException(Throwable e) {
    ApiException ex;
    if (e instanceof HttpException) {
        HttpException httpException = (HttpException) e;
        ex = new ApiException(e, ApiCode.Request.HTTP_ERROR);
        switch (httpException.code()) {
            case ApiCode.Http.UNAUTHORIZED:
            case ApiCode.Http.FORBIDDEN:
            case ApiCode.Http.NOT_FOUND:
            case ApiCode.Http.REQUEST_TIMEOUT:
            case ApiCode.Http.GATEWAY_TIMEOUT:
            case ApiCode.Http.INTERNAL_SERVER_ERROR:
            case ApiCode.Http.BAD_GATEWAY:
            case ApiCode.Http.SERVICE_UNAVAILABLE:
            default:
                ex.message = "NETWORK_ERROR";
                break;
        }
        return ex;
    } else if (e instanceof JsonParseException || e instanceof JSONException || e instanceof ParseException) {
        ex = new ApiException(e, ApiCode.Request.PARSE_ERROR);
        ex.message = "PARSE_ERROR";
        return ex;
    } else if (e instanceof ConnectException) {
        ex = new ApiException(e, ApiCode.Request.NETWORK_ERROR);
        ex.message = "NETWORK_ERROR";
        return ex;
    } else if (e instanceof javax.net.ssl.SSLHandshakeException) {
        ex = new ApiException(e, ApiCode.Request.SSL_ERROR);
        ex.message = "SSL_ERROR";
        return ex;
    } else if (e instanceof SocketTimeoutException) {
        ex = new ApiException(e, ApiCode.Request.TIMEOUT_ERROR);
        ex.message = "TIMEOUT_ERROR";
        return ex;
    } else {
        ex = new ApiException(e, ApiCode.Request.UNKNOWN);
        ex.message = "UNKNOWN";
        return ex;
    }
}
项目:RLibrary    文件:ExceptionHandle.java   
public static ResponseThrowable handleException(Throwable e) {
    ResponseThrowable ex;
    if (e instanceof HttpException) {
        HttpException httpException = (HttpException) e;
        ex = new ResponseThrowable(e, ERROR.HTTP_ERROR);
        switch (httpException.code()) {
            case UNAUTHORIZED:
            case FORBIDDEN:
            case NOT_FOUND:
            case REQUEST_TIMEOUT:
            case GATEWAY_TIMEOUT:
            case INTERNAL_SERVER_ERROR:
            case BAD_GATEWAY:
            case SERVICE_UNAVAILABLE:
            default:
                ex.message = "网络错误";
                break;
        }
        return ex;
    } else if (e instanceof ServerException) {
        ServerException resultException = (ServerException) e;
        ex = new ResponseThrowable(resultException, resultException.code);
        ex.message = resultException.message;
        return ex;
    } else if (e instanceof JsonParseException
            || e instanceof JSONException
            || e instanceof ParseException) {
        ex = new ResponseThrowable(e, ERROR.PARSE_ERROR);
        ex.message = "解析错误";
        return ex;
    } else if (e instanceof ConnectException) {
        ex = new ResponseThrowable(e, ERROR.NETWORK_ERROR);
        ex.message = "连接失败";
        return ex;
    } else if (e instanceof javax.net.ssl.SSLHandshakeException) {
        ex = new ResponseThrowable(e, ERROR.SSL_ERROR);
        ex.message = "证书验证失败";
        return ex;
    } else {
        ex = new ResponseThrowable(e, ERROR.UNKNOWN);
        ex.message = "未知错误";
        return ex;
    }
}
项目:camera    文件:AppUtil.java   
public static String gzipToString(final HttpEntity entity)
    throws IOException, ParseException {
    return gzipToString(entity, null);
}
项目:RetrofitClient    文件:ExceptionHandle.java   
public static ResponeThrowable handleException(Throwable e) {
    ResponeThrowable ex;
    if (e instanceof HttpException) {
        HttpException httpException = (HttpException) e;
        ex = new ResponeThrowable(e, ERROR.HTTP_ERROR);
        switch (httpException.code()) {
            case UNAUTHORIZED:
            case FORBIDDEN:
            case NOT_FOUND:
            case REQUEST_TIMEOUT:
            case GATEWAY_TIMEOUT:
            case INTERNAL_SERVER_ERROR:
            case BAD_GATEWAY:
            case SERVICE_UNAVAILABLE:
            default:
                ex.message = "网络错误";
                break;
        }
        return ex;
    } else if (e instanceof ServerException) {
        ServerException resultException = (ServerException) e;
        ex = new ResponeThrowable(resultException, resultException.code);
        ex.message = resultException.message;
        return ex;
    } else if (e instanceof JsonParseException
            || e instanceof JSONException
            || e instanceof ParseException) {
        ex = new ResponeThrowable(e, ERROR.PARSE_ERROR);
        ex.message = "解析错误";
        return ex;
    } else if (e instanceof ConnectException) {
        ex = new ResponeThrowable(e, ERROR.NETWORD_ERROR);
        ex.message = "连接失败";
        return ex;
    } else if (e instanceof javax.net.ssl.SSLHandshakeException) {
        ex = new ResponeThrowable(e, ERROR.SSL_ERROR);
        ex.message = "证书验证失败";
        return ex;
    } else if (e instanceof ConnectTimeoutException){
        ex = new ResponeThrowable(e, ERROR.TIMEOUT_ERROR);
        ex.message = "连接超时";
        return ex;
    } else if (e instanceof java.net.SocketTimeoutException) {
        ex = new ResponeThrowable(e, ERROR.TIMEOUT_ERROR);
        ex.message = "连接超时";
        return ex;
    }
    else {
        ex = new ResponeThrowable(e, ERROR.UNKNOWN);
        ex.message = "未知错误";
        return ex;
    }
}