@Override
public Path mkdir(final Path folder, final String region, final TransferStatus status) throws BackgroundException {
try {
if(containerService.isContainer(folder)) {
session.getClient().createContainer(regionService.lookup(
new SwiftLocationFeature.SwiftRegion(region)), folder.getName());
return new Path(folder.getParent(), folder.getName(), folder.getType(),
new SwiftAttributesFinderFeature(session, regionService).find(folder));
}
else {
status.setMime("application/directory");
status.setLength(0L);
final StatusOutputStream<StorageObject> out = writer.write(folder, status, new DisabledConnectionCallback());
new DefaultStreamCloser().close(out);
final StorageObject metadata = out.getStatus();
return new Path(folder.getParent(), folder.getName(), folder.getType(),
new SwiftAttributesFinderFeature(session, regionService).toAttributes(metadata));
}
}
catch(GenericException e) {
throw new SwiftExceptionMappingService().map("Cannot create folder {0}", e, folder);
}
catch(IOException e) {
throw new DefaultIOExceptionMappingService().map("Cannot create folder {0}", e, folder);
}
}