@@ -190,8 +190,13 @@ public FileListing listFiles(String bucket, String prefix, String marker, int li
190
190
* @link http://developer.qiniu.com/kodo/api/stat
191
191
*/
192
192
public FileInfo stat (String bucket , String fileKey ) throws QiniuException {
193
- Response r = rsGet (bucket , String .format ("/stat/%s" , encodedEntry (bucket , fileKey )));
194
- return r .jsonToObject (FileInfo .class );
193
+ Response res = rsGet (bucket , String .format ("/stat/%s" , encodedEntry (bucket , fileKey )));
194
+ if (!res .isOK ()) {
195
+ throw new QiniuException (res );
196
+ }
197
+ FileInfo fileInfo = res .jsonToObject (FileInfo .class );
198
+ res .close ();
199
+ return fileInfo ;
195
200
}
196
201
197
202
/**
@@ -330,7 +335,11 @@ public Response copy(String fromBucket, String fromFileKey, String toBucket, Str
330
335
*/
331
336
public void copy (String fromBucket , String fromFileKey , String toBucket , String toFileKey )
332
337
throws QiniuException {
333
- copy (fromBucket , fromFileKey , toBucket , toFileKey , false );
338
+ Response res = copy (fromBucket , fromFileKey , toBucket , toFileKey , false );
339
+ if (!res .isOK ()) {
340
+ throw new QiniuException (res );
341
+ }
342
+ res .close ();
334
343
}
335
344
336
345
/**
@@ -391,8 +400,13 @@ public FetchRet fetch(String url, String bucket, String key) throws QiniuExcepti
391
400
String resource = UrlSafeBase64 .encodeToString (url );
392
401
String to = encodedEntry (bucket , key );
393
402
String path = String .format ("/fetch/%s/to/%s" , resource , to );
394
- Response r = ioPost (bucket , path );
395
- return r .jsonToObject (FetchRet .class );
403
+ Response res = ioPost (bucket , path );
404
+ if (!res .isOK ()) {
405
+ throw new QiniuException (res );
406
+ }
407
+ FetchRet fetchRet = res .jsonToObject (FetchRet .class );
408
+ res .close ();
409
+ return fetchRet ;
396
410
}
397
411
398
412
/**
@@ -470,7 +484,11 @@ public Response checkAsynFetchid(String region, String fetchWorkId) throws Qiniu
470
484
public void prefetch (String bucket , String key ) throws QiniuException {
471
485
String resource = encodedEntry (bucket , key );
472
486
String path = String .format ("/prefetch/%s" , resource );
473
- ioPost (bucket , path );
487
+ Response res = ioPost (bucket , path );
488
+ if (!res .isOK ()) {
489
+ throw new QiniuException (res );
490
+ }
491
+ res .close ();
474
492
}
475
493
476
494
/**
@@ -527,27 +545,31 @@ public Response deleteAfterDays(String bucket, String key, int days) throws Qini
527
545
public void setBucketAcl (String bucket , AclType acl ) throws QiniuException {
528
546
String url = String .format ("%s/private?bucket=%s&private=%s" , configuration .ucHost (), bucket , acl .getType ());
529
547
Response res = post (url , null );
530
- res .close ();
531
548
if (!res .isOK ()) {
532
549
throw new QiniuException (res );
533
550
}
551
+ res .close ();
534
552
}
535
553
536
554
public BucketInfo getBucketInfo (String bucket ) throws QiniuException {
537
555
String url = String .format ("%s/v2/bucketInfo?bucket=%s" , configuration .ucHost (), bucket );
538
556
Response res = post (url , null );
539
557
if (!res .isOK ()) {
540
- res .close ();
541
558
throw new QiniuException (res );
542
559
}
543
560
BucketInfo info = res .jsonToObject (BucketInfo .class );
561
+ res .close ();
544
562
return info ;
545
563
}
546
564
547
565
public void setIndexPage (String bucket , IndexPageType type ) throws QiniuException {
548
566
String url = String .format ("%s/noIndexPage?bucket=%s&noIndexPage=%s" ,
549
567
configuration .ucHost (), bucket , type .getType ());
550
568
Response res = post (url , null );
569
+ if (!res .isOK ()) {
570
+ throw new QiniuException (res );
571
+ }
572
+ res .close ();
551
573
}
552
574
553
575
/*
0 commit comments