@@ -80,8 +80,7 @@ public void handle(final HttpExchange exchange) throws IOException {
80
80
try {
81
81
// Request body is closed in the finally block
82
82
final BytesReference requestBody = Streams .readFully (Streams .noCloseStream (exchange .getRequestBody ()));
83
- if (request .equals ("GET /" ) &&
84
- "Google" .equals (exchange .getRequestHeaders ().getFirst ("Metadata-Flavor" ))) {
83
+ if (request .equals ("GET /" ) && "Google" .equals (exchange .getRequestHeaders ().getFirst ("Metadata-Flavor" ))) {
85
84
// the SDK checks this endpoint to determine if it's running within Google Compute Engine
86
85
exchange .getResponseHeaders ().add ("Metadata-Flavor" , "Google" );
87
86
exchange .sendResponseHeaders (RestStatus .OK .getStatus (), 0 );
@@ -118,11 +117,11 @@ public void handle(final HttpExchange exchange) throws IOException {
118
117
}
119
118
}
120
119
121
- byte [] response = ("{\" kind\" :\" storage#objects\" ,\" items\" :[" +
122
- String .join ("," , listOfBlobs ) +
123
- "],\" prefixes\" :[" +
124
- String .join ("," , prefixes ) +
125
- "]}" ).getBytes (UTF_8 );
120
+ byte [] response = ("{\" kind\" :\" storage#objects\" ,\" items\" :["
121
+ + String .join ("," , listOfBlobs )
122
+ + "],\" prefixes\" :["
123
+ + String .join ("," , prefixes )
124
+ + "]}" ).getBytes (UTF_8 );
126
125
127
126
exchange .getResponseHeaders ().add ("Content-Type" , "application/json; charset=utf-8" );
128
127
exchange .sendResponseHeaders (RestStatus .OK .getStatus (), response .length );
@@ -194,8 +193,13 @@ public void handle(final HttpExchange exchange) throws IOException {
194
193
exchange .sendResponseHeaders (RestStatus .OK .getStatus (), response .length );
195
194
exchange .getResponseBody ().write (response );
196
195
} else {
197
- throw new AssertionError ("Could not read multi-part request to [" + request + "] with headers ["
198
- + new HashMap <>(exchange .getRequestHeaders ()) + "]" );
196
+ throw new AssertionError (
197
+ "Could not read multi-part request to ["
198
+ + request
199
+ + "] with headers ["
200
+ + new HashMap <>(exchange .getRequestHeaders ())
201
+ + "]"
202
+ );
199
203
}
200
204
201
205
} else if (Regex .simpleMatch ("POST /upload/storage/v1/b/" + bucket + "/*uploadType=resumable*" , request )) {
@@ -208,14 +212,23 @@ public void handle(final HttpExchange exchange) throws IOException {
208
212
byte [] response = requestBody .utf8ToString ().getBytes (UTF_8 );
209
213
if (Paths .get (blobName ).getFileName ().toString ().startsWith (BlobStoreRepository .UPLOADED_DATA_BLOB_PREFIX ) == false ) {
210
214
final Map <String , Object > parsedBody = XContentHelper .convertToMap (requestBody , false , XContentType .JSON ).v2 ();
211
- assert parsedBody .get ("md5Hash" ) != null :
212
- "file [" + blobName + "] is not a data blob but did not come with a md5 checksum" ;
215
+ assert parsedBody .get ("md5Hash" ) != null
216
+ : "file [" + blobName + "] is not a data blob but did not come with a md5 checksum" ;
213
217
}
214
218
exchange .getResponseHeaders ().add ("Content-Type" , "application/json" );
215
- exchange .getResponseHeaders ().add ("Location" , httpServerUrl (exchange ) + "/upload/storage/v1/b/" + bucket + "/o?"
216
- + "uploadType=resumable"
217
- + "&upload_id=" + UUIDs .randomBase64UUID ()
218
- + "&test_blob_name=" + blobName ); // not a Google Storage parameter, but it allows to pass the blob name
219
+ exchange .getResponseHeaders ()
220
+ .add (
221
+ "Location" ,
222
+ httpServerUrl (exchange )
223
+ + "/upload/storage/v1/b/"
224
+ + bucket
225
+ + "/o?"
226
+ + "uploadType=resumable"
227
+ + "&upload_id="
228
+ + UUIDs .randomBase64UUID ()
229
+ + "&test_blob_name="
230
+ + blobName
231
+ ); // not a Google Storage parameter, but it allows to pass the blob name
219
232
exchange .sendResponseHeaders (RestStatus .OK .getStatus (), response .length );
220
233
exchange .getResponseBody ().write (response );
221
234
@@ -260,10 +273,18 @@ public void handle(final HttpExchange exchange) throws IOException {
260
273
261
274
private String buildBlobInfoJson (String blobName , int size ) {
262
275
return "{\" kind\" :\" storage#object\" ,"
263
- + "\" bucket\" :\" " + bucket + "\" ,"
264
- + "\" name\" :\" " + blobName + "\" ,"
265
- + "\" id\" :\" " + blobName + "\" ,"
266
- + "\" size\" :\" " + size + "\" "
276
+ + "\" bucket\" :\" "
277
+ + bucket
278
+ + "\" ,"
279
+ + "\" name\" :\" "
280
+ + blobName
281
+ + "\" ,"
282
+ + "\" id\" :\" "
283
+ + blobName
284
+ + "\" ,"
285
+ + "\" size\" :\" "
286
+ + size
287
+ + "\" "
267
288
+ "}" ;
268
289
}
269
290
@@ -307,7 +328,9 @@ public static Optional<Tuple<String, BytesReference>> parseMultipartRequestBody(
307
328
} else if (start .startsWith (bucketPrefix )) {
308
329
markAndContinue = true ;
309
330
final String line = fullRequestBody .slice (
310
- startPos + bucketPrefix .length (), endPos - startPos - bucketPrefix .length ()).utf8ToString ();
331
+ startPos + bucketPrefix .length (),
332
+ endPos - startPos - bucketPrefix .length ()
333
+ ).utf8ToString ();
311
334
Matcher matcher = NAME_PATTERN .matcher (line );
312
335
if (matcher .find ()) {
313
336
name = matcher .group (1 );
@@ -326,8 +349,12 @@ public static Optional<Tuple<String, BytesReference>> parseMultipartRequestBody(
326
349
}
327
350
if (content == null ) {
328
351
final InputStream stream = fullRequestBody .streamInput ();
329
- logger .warn (() -> new ParameterizedMessage ("Failed to find multi-part upload in [{}]" , new BufferedReader (
330
- new InputStreamReader (stream )).lines ().collect (Collectors .joining ("\n " ))));
352
+ logger .warn (
353
+ () -> new ParameterizedMessage (
354
+ "Failed to find multi-part upload in [{}]" ,
355
+ new BufferedReader (new InputStreamReader (stream )).lines ().collect (Collectors .joining ("\n " ))
356
+ )
357
+ );
331
358
}
332
359
return Optional .ofNullable (content );
333
360
}
@@ -360,14 +387,18 @@ public static Integer getContentRangeLimit(final String contentRange) {
360
387
}
361
388
362
389
public static int getContentRangeStart (final String contentRange ) {
363
- return parse (PATTERN_CONTENT_RANGE , contentRange ,
364
- (bytes , limit ) -> parse (PATTERN_CONTENT_RANGE_BYTES , bytes ,
365
- (start , end ) -> Integer .parseInt (start )));
390
+ return parse (
391
+ PATTERN_CONTENT_RANGE ,
392
+ contentRange ,
393
+ (bytes , limit ) -> parse (PATTERN_CONTENT_RANGE_BYTES , bytes , (start , end ) -> Integer .parseInt (start ))
394
+ );
366
395
}
367
396
368
397
public static int getContentRangeEnd (final String contentRange ) {
369
- return parse (PATTERN_CONTENT_RANGE , contentRange ,
370
- (bytes , limit ) -> parse (PATTERN_CONTENT_RANGE_BYTES , bytes ,
371
- (start , end ) -> Integer .parseInt (end )));
398
+ return parse (
399
+ PATTERN_CONTENT_RANGE ,
400
+ contentRange ,
401
+ (bytes , limit ) -> parse (PATTERN_CONTENT_RANGE_BYTES , bytes , (start , end ) -> Integer .parseInt (end ))
402
+ );
372
403
}
373
404
}
0 commit comments