use of com.aliyun.oss.integrationtests.TestUtils.genFixedLengthFile in project aliyun-oss-java-sdk by aliyun.
the class CRCChecksumTest method testEmpytObjectCRC.
@Test
public void testEmpytObjectCRC() {
String key = "empty-object-crc";
try {
// put
PutObjectResult putObjectResult = ossClient.putObject(bucketName, key, new ByteArrayInputStream(new String("").getBytes()));
Assert.assertTrue(putObjectResult.getClientCRC() == 0L);
Assert.assertTrue(putObjectResult.getServerCRC() == 0L);
Assert.assertEquals(putObjectResult.getRequestId().length(), REQUEST_ID_LEN);
String localFile = TestUtils.genFixedLengthFile(0);
putObjectResult = ossClient.putObject(bucketName, key, new FileInputStream(localFile));
Assert.assertEquals(putObjectResult.getClientCRC(), putObjectResult.getServerCRC());
Assert.assertTrue(putObjectResult.getClientCRC() == 0L);
Assert.assertTrue(putObjectResult.getServerCRC() == 0L);
Assert.assertEquals(putObjectResult.getRequestId().length(), REQUEST_ID_LEN);
putObjectResult = ossClient.putObject(bucketName, key, new File(localFile));
Assert.assertEquals(putObjectResult.getClientCRC(), putObjectResult.getServerCRC());
Assert.assertTrue(putObjectResult.getClientCRC() == 0L);
Assert.assertTrue(putObjectResult.getServerCRC() == 0L);
Assert.assertEquals(putObjectResult.getRequestId().length(), REQUEST_ID_LEN);
// get
OSSObject ossObject = ossClient.getObject(bucketName, key);
Assert.assertNull(ossObject.getClientCRC());
Assert.assertNotNull(ossObject.getServerCRC());
Assert.assertEquals(ossObject.getRequestId().length(), REQUEST_ID_LEN);
Assert.assertTrue(IOUtils.getCRCValue(ossObject.getObjectContent()) == 0L);
InputStream content = ossObject.getObjectContent();
while (content.read() != -1) {
}
ossObject.setClientCRC(IOUtils.getCRCValue(content));
Assert.assertTrue(putObjectResult.getClientCRC() == 0L);
Assert.assertTrue(putObjectResult.getServerCRC() == 0L);
content.close();
ossClient.deleteObject(bucketName, key);
TestUtils.removeFile(localFile);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
Aggregations