24
24
import com .google .api .client .googleapis .batch .json .JsonBatchCallback ;
25
25
import com .google .api .client .googleapis .json .GoogleJsonError ;
26
26
import com .google .api .client .http .ByteArrayContent ;
27
+ import com .google .api .client .http .EmptyContent ;
27
28
import com .google .api .client .http .GenericUrl ;
28
29
import com .google .api .client .http .HttpHeaders ;
29
30
import com .google .api .client .http .HttpRequest ;
@@ -751,7 +752,8 @@ public void write(
751
752
public long getCurrentUploadOffset (String uploadId ) {
752
753
try {
753
754
GenericUrl url = new GenericUrl (uploadId );
754
- HttpRequest httpRequest = storage .getRequestFactory ().buildPutRequest (url , null );
755
+ HttpRequest httpRequest =
756
+ storage .getRequestFactory ().buildPutRequest (url , new EmptyContent ());
755
757
756
758
httpRequest .getHeaders ().setContentRange ("bytes */*" );
757
759
// Turn off automatic redirects.
@@ -763,7 +765,6 @@ public long getCurrentUploadOffset(String uploadId) {
763
765
try {
764
766
response = httpRequest .execute ();
765
767
int code = response .getStatusCode ();
766
- String message = response .getStatusMessage ();
767
768
if (code == 201 || code == 200 ) {
768
769
throw new StorageException (0 , "Resumable upload is already complete." );
769
770
}
@@ -776,11 +777,17 @@ public long getCurrentUploadOffset(String uploadId) {
776
777
if (code == 308 && ex .getHeaders ().getRange () == null ) {
777
778
// No progress has been made.
778
779
return 0 ;
779
- } else {
780
+ } else if ( code == 308 && ex . getHeaders (). getRange () != null ) {
780
781
// API returns last byte received offset
781
782
String range = ex .getHeaders ().getRange ();
782
783
// Return next byte offset by adding 1 to last byte received offset
783
784
return Long .parseLong (range .substring (range .indexOf ("-" ) + 1 )) + 1 ;
785
+ } else {
786
+ // Not certain what went wrong
787
+ StringBuilder sb = new StringBuilder ();
788
+ sb .append ("Not sure what occurred. Here's debugging information:\n " );
789
+ sb .append ("Response:\n " ).append (ex .toString ()).append ("\n \n " );
790
+ throw new StorageException (0 , sb .toString ());
784
791
}
785
792
} finally {
786
793
if (response != null ) {
0 commit comments