out.beginSlice();
out.write(ByteBuffer.wrap(content));
out.endSlice();
out.endShard();
}
GoogleCloudStorageFileSet files = creator.finish(writers);
assertEquals(NUM_SHARDS, files.getNumFiles());
ByteBuffer expectedContent = ByteBuffer.allocate(content.length * 2);
expectedContent.put(content);
expectedContent.put(content);
for (int i = 0; i < NUM_SHARDS; i++) {
expectedContent.rewind();
ByteBuffer actualContent = ByteBuffer.allocate(content.length * 2 + 1);
GcsFileMetadata metadata = gcsService.getMetadata(files.getFile(i));
assertNotNull(metadata);
assertEquals(expectedContent.capacity(), metadata.getLength());
assertEquals(MIME_TYPE, metadata.getOptions().getMimeType());
try (ReadableByteChannel readChannel = gcsService.openReadChannel(files.getFile(i), 0)) {
int read = readChannel.read(actualContent);
assertEquals(read, content.length * 2);
actualContent.limit(actualContent.position());
actualContent.rewind();
assertEquals(expectedContent, actualContent);