use of com.qcloud.cos.request.GetFileInputStreamRequest in project xian by happyyangyuan.
the class CosFileReader method forPath.
public String forPath(String path) {
checkPath(path);
getCosClient();
GetFileInputStreamRequest inputStreamRequest = new GetFileInputStreamRequest(BUCKET, getBase() + path);
// todo 后面可以在v4全面开放之后使用默认开启
inputStreamRequest.setUseCDN(false);
try (InputStream inputStream = cosClient.getFileInputStream(inputStreamRequest)) {
return StringIO.readFully(inputStream);
} catch (Exception e) {
throw new RemoteFileReadFailed(path, e);
}
}
use of com.qcloud.cos.request.GetFileInputStreamRequest in project xian by happyyangyuan.
the class CosFileReader method exists.
public boolean exists(String path) {
checkPath(path);
getCosClient();
GetFileInputStreamRequest inputStreamRequest = new GetFileInputStreamRequest(BUCKET, getBase() + path);
try (InputStream ignored = cosClient.getFileInputStream(inputStreamRequest)) {
} catch (Exception e) {
return false;
}
return true;
}
use of com.qcloud.cos.request.GetFileInputStreamRequest in project xian by happyyangyuan.
the class CosFileWriter method main.
public static void main(String[] args) {
COSClient cosClient = new COSClient(10053621, "AKID5iJcsYewRYIJhqQsoaLQ7Ks1XIO6eYPs", "Gm0nqHOPzUG1MRRJnBLX4UwwQMoh8v4y");
ClientConfig config = new ClientConfig();
config.setRegion("sh");
cosClient.setConfig(config);
UploadFileRequest request = new UploadFileRequest("xian", "/xian_runtime_IDE_happyyangyuan/xian/yy/991.txt", "测试data".getBytes());
request.setInsertOnly(InsertOnly.OVER_WRITE);
String uploadFileRet = cosClient.uploadFile(request);
LOG.info("上传文件返回:" + uploadFileRet);
GetFileInputStreamRequest inputStreamRequest = new GetFileInputStreamRequest("xian", "/xian_runtime_IDE_happyyangyuan/xian/yy/991.txt");
inputStreamRequest.setUseCDN(false);
try (InputStream inputStream = cosClient.getFileInputStream(inputStreamRequest)) {
System.out.println("读文件:" + StringIO.readFully(inputStream));
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations