com.qiniu.http.Response.bodyString()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(112)

本文整理了Java中com.qiniu.http.Response.bodyString方法的一些代码示例,展示了Response.bodyString的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.bodyString方法的具体详情如下:
包路径:com.qiniu.http.Response
类名称:Response
方法名:bodyString

Response.bodyString介绍

暂无

代码示例

代码示例来源:origin: nice-swa/my-site

public String upload(MultipartFile file, String fileName) {
  //构造一个带指定Zone对象的配置类
  Configuration cfg = new Configuration(Zone.zone0());
  //...其他参数参考类注释
  UploadManager uploadManager = new UploadManager(cfg);
  //默认不指定key的情况下,以文件内容的hash值作为文件名
  String key = null;
  Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY);
  String upToken = auth.uploadToken(BUCKET);
  try {
    Response response = null;
    response = uploadManager.put(file.getInputStream(), fileName, upToken, null, null);
    //解析上传成功的结果
    DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
    System.out.println(putRet.key);
    System.out.println(putRet.hash);
    return putRet.key;
  } catch (QiniuException ex) {
    Response r = ex.response;
    System.err.println(r.toString());
    try {
      System.err.println(r.bodyString());
    } catch (QiniuException ex2) {
      //ignore
    }
  } catch (IOException e) {
    e.printStackTrace();
  }
  return null;
}

代码示例来源:origin: Exrick/x-boot

/**
 * 文件流上传
 * @param file
 * @param key  文件名
 * @return
 */
public String qiniuInputStreamUpload(FileInputStream file, String key) {
  Auth auth = Auth.create(accessKey, secretKey);
  String upToken = auth.uploadToken(bucket);
  try {
    Response response = getUploadManager(getConfiguration()).put(file, key, upToken, null, null);
    DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
    return domain + "/" + putRet.key;
  } catch (QiniuException ex) {
    Response r = ex.response;
    throw new XbootException("上传文件出错,请检查七牛云配置," + r.toString());
  }
}

代码示例来源:origin: Exrick/x-boot

/**
 * 文件路径上传
 * @param filePath
 * @param key   文件名
 * @return
 */
public String qiniuUpload(String filePath, String key) {
  Auth auth = Auth.create(accessKey, secretKey);
  String upToken = auth.uploadToken(bucket);
  try {
    Response response = getUploadManager(getConfiguration()).put(filePath, key, upToken);
    DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
    return domain + "/" + putRet.key;
  } catch (QiniuException ex) {
    Response r = ex.response;
    throw new XbootException("上传文件出错,请检查七牛云配置," + r.toString());
  }
}

代码示例来源:origin: scruel/ClipIt

private static String parserQiniuResponseResult(Response response) throws QiniuException {
    //解析上传成功的结果
    DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
    String prefix = properties.getProperty("markdown.prefix");
    String suffix = properties.getProperty("markdown.suffix");
    String result;
    String key = putRet.key;
    String fileName = key.substring(key.indexOf("_", key.indexOf("_") + 1) + 1);
    if (!fileName.startsWith("clipboard")) {
      prefix = prefix.replace("image", fileName);
    }
    try {
      result = String.format("%s%s%s", prefix, bucketDomain + "/" + URLEncoder.encode(key, "utf-8").replace("+", "%20"), suffix);

    } catch (UnsupportedEncodingException e) {
      // e.printStackTrace();
      result = String.format("%s%s%s", prefix, bucketDomain + "/" + key, suffix);
    }
    // System.out.println(result);
    return result;
  }
}

代码示例来源:origin: qiniu/java-sdk

public StringMap jsonToMap() throws QiniuException {
  if (!isJson()) {
    return null;
  }
  String b = bodyString();
  return Json.decode(b);
}

代码示例来源:origin: com.qiniu/qiniu-java-sdk

public <T> T jsonToObject(Class<T> classOfT) throws QiniuException {
  if (!isJson()) {
    return null;
  }
  String b = bodyString();
  return Json.decode(b, classOfT);
}

代码示例来源:origin: qiniu/java-sdk

public FileListing listFilesV2(String bucket, String prefix, String marker, int limit, String delimiter)
    throws QiniuException {
  Response response = listV2(bucket, prefix, marker, limit, delimiter);
  final String result = response.bodyString();
  response.close();
  List<String> lineList = Arrays.asList(result.split("\n"));
  FileListing fileListing = new FileListing();
  List<FileInfo> fileInfoList = new ArrayList<>();
  Set<String> commonPrefixSet = new HashSet<>();
  for (int i = 0; i < lineList.size(); i++) {
    String line = lineList.get(i);
    JsonObject jsonObject = Json.decode(line, JsonObject.class);
    if (!(jsonObject.get("item") instanceof JsonNull))
      fileInfoList.add(Json.decode(jsonObject.get("item"), FileInfo.class));
    String dir = jsonObject.get("dir").getAsString();
    if (!"".equals(dir)) commonPrefixSet.add(dir);
    if (i == lineList.size() - 1)
      fileListing.marker = jsonObject.get("marker").getAsString();
  }
  fileListing.items = fileInfoList.toArray(new FileInfo[]{});
  fileListing.commonPrefixes = commonPrefixSet.toArray(new String[]{});
  return fileListing;
}

代码示例来源:origin: qiniu/java-sdk

public <T> T jsonToObject(Class<T> classOfT) throws QiniuException {
  if (!isJson()) {
    return null;
  }
  String b = bodyString();
  return Json.decode(b, classOfT);
}

代码示例来源:origin: com.qiniu/qiniu-java-sdk

public StringMap jsonToMap() throws QiniuException {
  if (!isJson()) {
    return null;
  }
  String b = bodyString();
  return Json.decode(b);
}

代码示例来源:origin: com.qiniu/qiniu-java-sdk

public FileListing listFilesV2(String bucket, String prefix, String marker, int limit, String delimiter)
    throws QiniuException {
  Response response = listV2(bucket, prefix, marker, limit, delimiter);
  final String result = response.bodyString();
  response.close();
  List<String> lineList = Arrays.asList(result.split("\n"));
  FileListing fileListing = new FileListing();
  List<FileInfo> fileInfoList = new ArrayList<>();
  Set<String> commonPrefixSet = new HashSet<>();
  for (int i = 0; i < lineList.size(); i++) {
    String line = lineList.get(i);
    JsonObject jsonObject = Json.decode(line, JsonObject.class);
    if (!(jsonObject.get("item") instanceof JsonNull))
      fileInfoList.add(Json.decode(jsonObject.get("item"), FileInfo.class));
    String dir = jsonObject.get("dir").getAsString();
    if (!"".equals(dir)) commonPrefixSet.add(dir);
    if (i == lineList.size() - 1)
      fileListing.marker = jsonObject.get("marker").getAsString();
  }
  fileListing.items = fileInfoList.toArray(new FileInfo[]{});
  fileListing.commonPrefixes = commonPrefixSet.toArray(new String[]{});
  return fileListing;
}

代码示例来源:origin: scruel/ClipIt

public static String fileUpload(File file) {
  String localFilePath = file.getPath();
  //默认不指定key的情况下,以文件内容的hash值作为文件名
  String key = getDateKey() + file.getName();
  try {
    Response response = uploadManager.put(localFilePath, key, getToken());
    return parserQiniuResponseResult(response);
  } catch (QiniuException ex) {
    Response r = ex.response;
    System.err.println(r.toString());
    try {
      System.err.println(r.bodyString());
    } catch (QiniuException ignore) {
      return "";
    }
    return "";
  }
}

代码示例来源:origin: qiniu/java-sdk

public String getInfo() {
    String[] msg = new String[3];
    try {
      msg[0] = url();
    } catch (Throwable t) {
    }
    try {
      msg[1] = toString();
    } catch (Throwable t) {
    }
    try {
      msg[2] = bodyString();
    } catch (Throwable t) {

    }

    return StringUtils.join(msg, "  \n");
  }
}

代码示例来源:origin: com.qiniu/qiniu-java-sdk

public String getInfo() {
    String[] msg = new String[3];
    try {
      msg[0] = url();
    } catch (Throwable t) {
    }
    try {
      msg[1] = toString();
    } catch (Throwable t) {
    }
    try {
      msg[2] = bodyString();
    } catch (Throwable t) {

    }

    return StringUtils.join(msg, "  \n");
  }
}

代码示例来源:origin: vakinge/jeesuite-libs

private void processUploadException(String fileKey, QiniuException e) {
  Response r = e.response;
  String message;
  try {
    message = r.bodyString();
  } catch (Exception e2) {
    message = r.toString();
  }
  throw new FSOperErrorException(name(), e.code(), message);
}

代码示例来源:origin: wuyouzhuguli/FEBS-Security

public static String upload(FileInputStream file, String fileName) {
  // 构造一个带指定Zone对象的配置类
  Configuration cfg = new Configuration(Zone.zone0());
  // 其他参数参考类注释
  UploadManager uploadManager = new UploadManager(cfg);
  try {
    Auth auth = Auth.create(properies.getOss().getQiniu().getAccessKey(), properies.getOss().getQiniu().getSecretKey());
    String upToken = auth.uploadToken(properies.getOss().getQiniu().getBucket());
    try {
      Response response = uploadManager.put(file, fileName, upToken, null, null);
      // 解析上传成功的结果
      DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
      return properies.getOss().getQiniu().getPath() + "/" + putRet.key;
    } catch (QiniuException ex) {
      Response r = ex.response;
      logger.error(r.toString());
      try {
        logger.error(r.bodyString());
      } catch (QiniuException ignore) {
      }
    }
  } catch (Exception e) {
    logger.error("error", e);
  }
  return null;
}

代码示例来源:origin: xkcoding/spring-boot-demo

Response response = qiNiuService.uploadFile(new File(localFilePath));
if (response.isOK()) {
  JSONObject jsonObject = JSONUtil.parseObj(response.bodyString());

代码示例来源:origin: qiniu/java-sdk

} catch (QiniuException e) {
  try {
    assertEquals("_", e.response.bodyString());
  } catch (QiniuException e1) {
    e1.printStackTrace();

代码示例来源:origin: elunez/eladmin

Response response = uploadManager.put(file.getBytes(), QiNiuUtil.getKey(file.getOriginalFilename()), upToken);
DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);

代码示例来源:origin: qiniu/java-sdk

assertEquals(etag, ret.hash);
} catch (QiniuException e) {
  assertEquals("", e.response == null ? "e.response is null" : e.response.bodyString());
  fail();

代码示例来源:origin: qiniu/java-sdk

public void testSizeMin() {
  String[] buckets = new String[]{TestConfig.testBucket_z0, TestConfig.testBucket_na0};
  for (String bucket : buckets) {
    final String expectKey = "世/界";
    File f = null;
    try {
      f = TempFile.createFile(1);
    } catch (IOException e) {
      e.printStackTrace();
    }
    assert f != null;
    StringMap params = new StringMap().put("x:foo", "foo_val");
    String token = TestConfig.testAuth.uploadToken(bucket, expectKey, 3600,
        new StringMap().put("fsizeMin", 1024 * 1025));
    try {
      Response res = uploadManager.put(f, expectKey, token, params, null, true);
    } catch (QiniuException e) {
      Response res = e.response;
      try {
        assertEquals("{\"error\":\"request entity size is smaller than FsizeMin\"}", res.bodyString());
      } catch (QiniuException e1) {
        e1.printStackTrace();
      }
    } finally {
      TempFile.remove(f);
    }
  }
}

相关文章