Search in sources :

Example 1 with GetFileInputStreamRequest

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);
    }
}
Also used : InputStream(java.io.InputStream) GetFileInputStreamRequest(com.qcloud.cos.request.GetFileInputStreamRequest)

Example 2 with GetFileInputStreamRequest

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;
}
Also used : InputStream(java.io.InputStream) GetFileInputStreamRequest(com.qcloud.cos.request.GetFileInputStreamRequest)

Example 3 with GetFileInputStreamRequest

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();
    }
}
Also used : COSClient(com.qcloud.cos.COSClient) UploadFileRequest(com.qcloud.cos.request.UploadFileRequest) InputStream(java.io.InputStream) ClientConfig(com.qcloud.cos.ClientConfig) GetFileInputStreamRequest(com.qcloud.cos.request.GetFileInputStreamRequest)

Aggregations

GetFileInputStreamRequest (com.qcloud.cos.request.GetFileInputStreamRequest)3 InputStream (java.io.InputStream)3 COSClient (com.qcloud.cos.COSClient)1 ClientConfig (com.qcloud.cos.ClientConfig)1 UploadFileRequest (com.qcloud.cos.request.UploadFileRequest)1