Пример #1
0
  public Response send(final Request.Builder requestBuilder, StringMap headers)
      throws QiniuException {
    if (headers != null) {
      headers.forEach(
          new StringMap.Consumer() {
            @Override
            public void accept(String key, Object value) {
              requestBuilder.header(key, value.toString());
            }
          });
    }

    requestBuilder.header("User-Agent", userAgent());
    long start = System.currentTimeMillis();
    com.squareup.okhttp.Response res = null;
    Response r;
    double duration = (System.currentTimeMillis() - start) / 1000.0;
    IpTag tag = new IpTag();
    try {
      res = httpClient.newCall(requestBuilder.tag(tag).build()).execute();
    } catch (IOException e) {
      e.printStackTrace();
      throw new QiniuException(e);
    }
    r = Response.create(res, tag.ip, duration);
    if (r.statusCode >= 300) {
      throw new QiniuException(r);
    }

    return r;
  }
Пример #2
0
 private static String userAgent() {
   String javaVersion = "Java/" + System.getProperty("java.version");
   String os =
       System.getProperty("os.name")
           + " "
           + System.getProperty("os.arch")
           + " "
           + System.getProperty("os.version");
   String sdk = "QiniuJava/" + Config.VERSION;
   return sdk + " (" + os + ") " + javaVersion;
 }