当前位置: 首页>>代码示例>>Java>>正文


Java MimeUtil.parseCharset方法代码示例

本文整理汇总了Java中retrofit.mime.MimeUtil.parseCharset方法的典型用法代码示例。如果您正苦于以下问题:Java MimeUtil.parseCharset方法的具体用法?Java MimeUtil.parseCharset怎么用?Java MimeUtil.parseCharset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在retrofit.mime.MimeUtil的用法示例。


在下文中一共展示了MimeUtil.parseCharset方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getResponseString

import retrofit.mime.MimeUtil; //导入方法依赖的package包/类
/**
 * Here we take the RetroFit Response and convert it to a String
 *
 * TODO: use gson instead
 *
 * @param response Response object
 * @return The Response body converted to a String
 */
public static String getResponseString(Response response) {
    try {
        TypedInput body = response.getBody();
        byte[] bodyBytes = ((TypedByteArray) body).getBytes();
        String bodyMime = body.mimeType();
        String bodyCharset = MimeUtil.parseCharset(bodyMime, "UTF-8");
        return new String(bodyBytes, bodyCharset);
    } catch (UnsupportedEncodingException ue) {
        Log.e("Exception", ue.getMessage());
        return "Error";
    } catch (NullPointerException npe) {
        Log.e("Exception", npe.getMessage());
        return "Error";
    }

}
 
开发者ID:stinsonga,项目名称:GSApp,代码行数:25,代码来源:GeoUtils.java

示例2: fromBody

import retrofit.mime.MimeUtil; //导入方法依赖的package包/类
@Override
public Object fromBody(TypedInput body, Type type) throws ConversionException {
    String charset = "UTF-8";
    if (body.mimeType() != null) {
        charset = MimeUtil.parseCharset(body.mimeType());
    }
    InputStreamReader isr = null;
    try {
        isr = new InputStreamReader(body.in(), charset);
        return gson.fromJson(isr, type);
    } catch (IOException | JsonParseException e) {
        throw new ConversionException(e);
    } finally {
        if (isr != null) {
            try {
                isr.close();
            } catch (IOException ex) {
                // Ignored
            }
        }
    }
}
 
开发者ID:phil-lopreiato,项目名称:tba-apiv2-java,代码行数:23,代码来源:RetrofitConverter.java

示例3: fromBody

import retrofit.mime.MimeUtil; //导入方法依赖的package包/类
@Override
public Object fromBody(TypedInput body, Type type) throws ConversionException {
    String charset = "UTF-8";
    if (body.mimeType() != null) {
        charset = MimeUtil.parseCharset(body.mimeType());
    }

    InputStreamReader isr = null;
    try {
        isr = new InputStreamReader(body.in(), charset);

        // Need a Class instance here, as using the Type in serializer.read(...) doesn't work
        Class<?> typeClass = (Class<?>) type;

        return serializer.read((Class<?>) type, isr);
    } catch (Exception e) {
        throw new ConversionException(e);
    }
}
 
开发者ID:aegis123,项目名称:retrofit-simplexmlconverter,代码行数:20,代码来源:SimpleXmlConverter.java

示例4: getString

import retrofit.mime.MimeUtil; //导入方法依赖的package包/类
private String getString(TypedInput body) throws ConversionException {
    String charset = CHARSET_DEFAULT;
    if (body.mimeType() != null) {
        charset = MimeUtil.parseCharset(body.mimeType(), charset);
    }
    InputStreamReader isr = null;
    String result;
    try {
        isr = new InputStreamReader(body.in(), charset);
        StringBuilder sb = new StringBuilder();
        char[] buf = new char[BUFFER_SIZE];
        for (; ; ) {
            int res = isr.read(buf, 0, buf.length);
            if (res < 0) {
                break;
            }
            sb.append(buf, 0, res);
        }
        result = sb.toString();
        return result;
    } catch (IOException e) {
        throw new ConversionException(e);
    } finally {
        if (isr != null) {
            try {
                isr.close();
            } catch (IOException ignored) {
            }
        }
    }
}
 
开发者ID:Jude95,项目名称:Fishing,代码行数:32,代码来源:WrapperConverter.java

示例5: getBodyString

import retrofit.mime.MimeUtil; //导入方法依赖的package包/类
public static String getBodyString(Response response) throws IOException {
    TypedInput body = response.getBody();
    if (body != null) {
        byte[] bodyBytes = ((TypedByteArray) body).getBytes();
        String bodyMime = body.mimeType();
        String bodyCharset = MimeUtil.parseCharset(bodyMime);
        return new String(bodyBytes, bodyCharset);
    }
    return null;
}
 
开发者ID:padc,项目名称:DevConSummit,代码行数:11,代码来源:Util.java

示例6: logAndReplaceRequest

import retrofit.mime.MimeUtil; //导入方法依赖的package包/类
/**
 * Log request headers and body. Consumes request body and returns identical replacement.
 */
private Request logAndReplaceRequest(Request request) throws IOException {
    log.log(String.format("---> HTTP %s %s", request.getMethod(), request.getUrl()));

    if (logLevel.ordinal() >= LogLevel.HEADERS.ordinal()) {
        for (Header header : request.getHeaders()) {
            log.log(header.getName() + ": " + header.getValue());
        }

        long bodySize = 0;
        TypedOutput body = request.getBody();
        if (body != null) {
            bodySize = body.length();
            String bodyMime = body.mimeType();

            if (bodyMime != null) {
                log.log("Content-Type: " + bodyMime);
            }
            if (bodySize != -1) {
                log.log("Content-Length: " + bodySize);
            }

            if (logLevel.ordinal() >= LogLevel.FULL.ordinal()) {
                if (!request.getHeaders().isEmpty()) {
                    log.log("");
                }
                if (!(body instanceof TypedByteArray)) {
                    // Read the entire response body to we can log it and replace the original response
                    request = Utils.readBodyToBytesIfNecessary(request);
                    body = request.getBody();
                }

                byte[] bodyBytes = ((TypedByteArray) body).getBytes();
                bodySize = bodyBytes.length;
                String bodyCharset = MimeUtil.parseCharset(bodyMime);
                String bodyString = new String(bodyBytes, bodyCharset);
                for (int i = 0, len = bodyString.length(); i < len; i += LOG_CHUNK_SIZE) {
                    int end = Math.min(len, i + LOG_CHUNK_SIZE);
                    log.log(bodyString.substring(i, end));
                }
            }
        }

        log.log(String.format("---> END HTTP (%s-byte body)", bodySize));
    }

    return request;
}
 
开发者ID:goodev,项目名称:android-discourse,代码行数:51,代码来源:RestAdapter.java

示例7: logAndReplaceResponse

import retrofit.mime.MimeUtil; //导入方法依赖的package包/类
/**
 * Log response headers and body. Consumes response body and returns identical replacement.
 */
private Response logAndReplaceResponse(String url, Response response, long elapsedTime) throws IOException {
    log.log(String.format("<--- HTTP %s %s (%sms)", response.getStatus(), url, elapsedTime));

    if (logLevel.ordinal() >= LogLevel.HEADERS.ordinal()) {
        for (Header header : response.getHeaders()) {
            log.log(header.getName() + ": " + header.getValue());
        }

        long bodySize = 0;
        TypedInput body = response.getBody();
        if (body != null) {
            bodySize = body.length();

            if (logLevel.ordinal() >= LogLevel.FULL.ordinal()) {
                if (!response.getHeaders().isEmpty()) {
                    log.log("");
                }

                if (!(body instanceof TypedByteArray)) {
                    // Read the entire response body to we can log it and replace the original response
                    response = Utils.readBodyToBytesIfNecessary(response);
                    body = response.getBody();
                }

                byte[] bodyBytes = ((TypedByteArray) body).getBytes();
                bodySize = bodyBytes.length;
                String bodyMime = body.mimeType();
                String bodyCharset = MimeUtil.parseCharset(bodyMime);
                String bodyString = new String(bodyBytes, bodyCharset);
                for (int i = 0, len = bodyString.length(); i < len; i += LOG_CHUNK_SIZE) {
                    int end = Math.min(len, i + LOG_CHUNK_SIZE);
                    log.log(bodyString.substring(i, end));
                }
            }
        }

        log.log(String.format("<--- END HTTP (%s-byte body)", bodySize));
    }

    return response;
}
 
开发者ID:goodev,项目名称:android-discourse,代码行数:45,代码来源:RestAdapter.java

示例8: convertToString

import retrofit.mime.MimeUtil; //导入方法依赖的package包/类
private static String convertToString(TypedInput body) throws UnsupportedEncodingException {
    byte[] bodyBytes = ((TypedByteArray) body).getBytes();
    return new String(bodyBytes, MimeUtil.parseCharset(body.mimeType()));
}
 
开发者ID:dpreussler,项目名称:android-gluten,代码行数:5,代码来源:TracedRetrofitClient.java

示例9: logAndReplaceRequest

import retrofit.mime.MimeUtil; //导入方法依赖的package包/类
/**
 * Log request headers and body. Consumes request body and returns identical replacement.
 */
Request logAndReplaceRequest(String name, Request request) throws IOException
{
  log.log(String.format("---> %s %s %s", name, request.getMethod(), request.getUrl()));

  if (logLevel.ordinal() >= LogLevel.HEADERS.ordinal())
  {
    for (Header header : request.getHeaders())
    {
      log.log(header.toString());
    }

    long bodySize = 0;
    TypedOutput body = request.getBody();
    if (body != null)
    {
      bodySize = body.length();
      String bodyMime = body.mimeType();

      if (bodyMime != null)
      {
        log.log("Content-Type: " + bodyMime);
      }
      if (bodySize != -1)
      {
        log.log("Content-Length: " + bodySize);
      }

      if (logLevel.ordinal() >= LogLevel.FULL.ordinal())
      {
        if (!request.getHeaders().isEmpty())
        {
          log.log("");
        }
        if (!(body instanceof TypedByteArray))
        {
          // Read the entire response body to we can log it and replace the original response
          request = Utils.readBodyToBytesIfNecessary(request);
          body = request.getBody();
        }

        byte[] bodyBytes = ((TypedByteArray) body).getBytes();
        bodySize = bodyBytes.length;
        String bodyCharset = MimeUtil.parseCharset(bodyMime);
        log.log(new String(bodyBytes, bodyCharset));
      }
    }

    log.log(String.format("---> END %s (%s-byte body)", name, bodySize));
  }

  return request;
}
 
开发者ID:toadzky,项目名称:retrofit-jaxrs,代码行数:56,代码来源:RestAdapter.java

示例10: logAndReplaceResponse

import retrofit.mime.MimeUtil; //导入方法依赖的package包/类
/**
 * Log response headers and body. Consumes response body and returns identical replacement.
 */
private Response logAndReplaceResponse(String url, Response response, long elapsedTime)
    throws IOException
{
  log.log(String.format("<--- HTTP %s %s (%sms)", response.getStatus(), url, elapsedTime));

  if (logLevel.ordinal() >= LogLevel.HEADERS.ordinal())
  {
    for (Header header : response.getHeaders())
    {
      log.log(header.toString());
    }

    long bodySize = 0;
    TypedInput body = response.getBody();
    if (body != null)
    {
      bodySize = body.length();

      if (logLevel.ordinal() >= LogLevel.FULL.ordinal())
      {
        if (!response.getHeaders().isEmpty())
        {
          log.log("");
        }

        if (!(body instanceof TypedByteArray))
        {
          // Read the entire response body so we can log it and replace the original response
          response = Utils.readBodyToBytesIfNecessary(response);
          body = response.getBody();
        }

        byte[] bodyBytes = ((TypedByteArray) body).getBytes();
        bodySize = bodyBytes.length;
        String bodyMime = body.mimeType();
        String bodyCharset = MimeUtil.parseCharset(bodyMime);
        log.log(new String(bodyBytes, bodyCharset));
      }
    }

    log.log(String.format("<--- END HTTP (%s-byte body)", bodySize));
  }

  return response;
}
 
开发者ID:toadzky,项目名称:retrofit-jaxrs,代码行数:49,代码来源:RestAdapter.java


注:本文中的retrofit.mime.MimeUtil.parseCharset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。