2424import com .google .api .client .googleapis .batch .json .JsonBatchCallback ;
2525import com .google .api .client .googleapis .json .GoogleJsonError ;
2626import com .google .api .client .http .ByteArrayContent ;
27+ import com .google .api .client .http .EmptyContent ;
2728import com .google .api .client .http .GenericUrl ;
2829import com .google .api .client .http .HttpHeaders ;
2930import com .google .api .client .http .HttpRequest ;
@@ -751,7 +752,8 @@ public void write(
751752 public long getCurrentUploadOffset (String uploadId ) {
752753 try {
753754 GenericUrl url = new GenericUrl (uploadId );
754- HttpRequest httpRequest = storage .getRequestFactory ().buildPutRequest (url , null );
755+ HttpRequest httpRequest =
756+ storage .getRequestFactory ().buildPutRequest (url , new EmptyContent ());
755757
756758 httpRequest .getHeaders ().setContentRange ("bytes */*" );
757759 // Turn off automatic redirects.
@@ -763,7 +765,6 @@ public long getCurrentUploadOffset(String uploadId) {
763765 try {
764766 response = httpRequest .execute ();
765767 int code = response .getStatusCode ();
766- String message = response .getStatusMessage ();
767768 if (code == 201 || code == 200 ) {
768769 throw new StorageException (0 , "Resumable upload is already complete." );
769770 }
@@ -776,11 +777,17 @@ public long getCurrentUploadOffset(String uploadId) {
776777 if (code == 308 && ex .getHeaders ().getRange () == null ) {
777778 // No progress has been made.
778779 return 0 ;
779- } else {
780+ } else if ( code == 308 && ex . getHeaders (). getRange () != null ) {
780781 // API returns last byte received offset
781782 String range = ex .getHeaders ().getRange ();
782783 // Return next byte offset by adding 1 to last byte received offset
783784 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 ());
784791 }
785792 } finally {
786793 if (response != null ) {
0 commit comments