@Test(expected = InteroperabilityException.class) public void testBucketExists() throws Exception { final Path bucket = new Path("/test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); try { new B2DirectoryFeature(session, new B2FileidProvider(session).withCache(cache)).mkdir(bucket, null, new TransferStatus()); } catch(InteroperabilityException e) { assertEquals("Bucket name is already in use. Please contact your web hosting service provider for assistance.", e.getDetail()); assertEquals("Cannot create folder test-cyberduck.", e.getMessage()); throw e; } }
@Override public Path mkdir(final Path folder, final String region, final TransferStatus status) throws BackgroundException { try { if(containerService.isContainer(folder)) { final B2BucketResponse response = session.getClient().createBucket(containerService.getContainer(folder).getName(), null == region ? BucketType.valueOf(PreferencesFactory.get().getProperty("b2.bucket.acl.default")) : BucketType.valueOf(region)); switch(response.getBucketType()) { case allPublic: folder.attributes().setAcl(new Acl(new Acl.GroupUser(Acl.GroupUser.EVERYONE, false), new Acl.Role(Acl.Role.READ))); } return new Path(folder.getParent(), folder.getName(), folder.getType(), new PathAttributes(folder.attributes())); } else { status.setChecksum(writer.checksum(folder, status).compute(new NullInputStream(0L), status)); status.setMime(MimeTypeService.DEFAULT_CONTENT_TYPE); final StatusOutputStream<BaseB2Response> out = writer.write(folder, status, new DisabledConnectionCallback()); new DefaultStreamCloser().close(out); final EnumSet<Path.Type> type = EnumSet.copyOf(folder.getType()); type.add(Path.Type.placeholder); return new Path(folder.getParent(), folder.getName(), type, new B2AttributesFinderFeature(session, fileid).toAttributes((B2FileResponse) out.getStatus())); } } catch(B2ApiException e) { throw new B2ExceptionMappingService().map("Cannot create folder {0}", e, folder); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } }
B2DirectoryFeature implements Directory<BaseB2Response> { @Override public Path mkdir(final Path folder, final String region, final TransferStatus status) throws BackgroundException { try { if(containerService.isContainer(folder)) { final B2BucketResponse response = session.getClient().createBucket(containerService.getContainer(folder).getName(), null == region ? BucketType.valueOf(PreferencesFactory.get().getProperty("b2.bucket.acl.default")) : BucketType.valueOf(region)); switch(response.getBucketType()) { case allPublic: folder.attributes().setAcl(new Acl(new Acl.GroupUser(Acl.GroupUser.EVERYONE, false), new Acl.Role(Acl.Role.READ))); } return new Path(folder.getParent(), folder.getName(), folder.getType(), new PathAttributes(folder.attributes())); } else { status.setChecksum(writer.checksum(folder, status).compute(new NullInputStream(0L), status)); status.setMime(MimeTypeService.DEFAULT_CONTENT_TYPE); final StatusOutputStream<BaseB2Response> out = writer.write(folder, status, new DisabledConnectionCallback()); new DefaultStreamCloser().close(out); final EnumSet<Path.Type> type = EnumSet.copyOf(folder.getType()); type.add(Path.Type.placeholder); return new Path(folder.getParent(), folder.getName(), type, new B2AttributesFinderFeature(session, fileid).toAttributes((B2FileResponse) out.getStatus())); } } catch(B2ApiException e) { throw new B2ExceptionMappingService().map("Cannot create folder {0}", e, folder); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } }
B2DirectoryFeature implements Directory<BaseB2Response> { @Override public Path mkdir(final Path folder, final String region, final TransferStatus status) throws BackgroundException { try { if(containerService.isContainer(folder)) { final B2BucketResponse response = session.getClient().createBucket(containerService.getContainer(folder).getName(), null == region ? BucketType.valueOf(PreferencesFactory.get().getProperty("b2.bucket.acl.default")) : BucketType.valueOf(region)); switch(response.getBucketType()) { case allPublic: folder.attributes().setAcl(new Acl(new Acl.GroupUser(Acl.GroupUser.EVERYONE, false), new Acl.Role(Acl.Role.READ))); } return new Path(folder.getParent(), folder.getName(), folder.getType(), new PathAttributes(folder.attributes())); } else { status.setChecksum(writer.checksum(folder, status).compute(new NullInputStream(0L), status)); status.setMime(MimeTypeService.DEFAULT_CONTENT_TYPE); final StatusOutputStream<BaseB2Response> out = writer.write(folder, status, new DisabledConnectionCallback()); new DefaultStreamCloser().close(out); final EnumSet<Path.Type> type = EnumSet.copyOf(folder.getType()); type.add(Path.Type.placeholder); return new Path(folder.getParent(), folder.getName(), type, new B2AttributesFinderFeature(session, fileid).toAttributes((B2FileResponse) out.getStatus())); } } catch(B2ApiException e) { throw new B2ExceptionMappingService().map("Cannot create folder {0}", e, folder); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } B2DirectoryFeature(final B2Session session, final B2FileidProvider fileid);  B2DirectoryFeature(final B2Session session, final B2FileidProvider fileid, final B2WriteFeature writer); }
B2DirectoryFeature implements Directory<BaseB2Response> { @Override public Path mkdir(final Path folder, final String region, final TransferStatus status) throws BackgroundException { try { if(containerService.isContainer(folder)) { final B2BucketResponse response = session.getClient().createBucket(containerService.getContainer(folder).getName(), null == region ? BucketType.valueOf(PreferencesFactory.get().getProperty("b2.bucket.acl.default")) : BucketType.valueOf(region)); switch(response.getBucketType()) { case allPublic: folder.attributes().setAcl(new Acl(new Acl.GroupUser(Acl.GroupUser.EVERYONE, false), new Acl.Role(Acl.Role.READ))); } return new Path(folder.getParent(), folder.getName(), folder.getType(), new PathAttributes(folder.attributes())); } else { status.setChecksum(writer.checksum(folder, status).compute(new NullInputStream(0L), status)); status.setMime(MimeTypeService.DEFAULT_CONTENT_TYPE); final StatusOutputStream<BaseB2Response> out = writer.write(folder, status, new DisabledConnectionCallback()); new DefaultStreamCloser().close(out); final EnumSet<Path.Type> type = EnumSet.copyOf(folder.getType()); type.add(Path.Type.placeholder); return new Path(folder.getParent(), folder.getName(), type, new B2AttributesFinderFeature(session, fileid).toAttributes((B2FileResponse) out.getStatus())); } } catch(B2ApiException e) { throw new B2ExceptionMappingService().map("Cannot create folder {0}", e, folder); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } B2DirectoryFeature(final B2Session session, final B2FileidProvider fileid);  B2DirectoryFeature(final B2Session session, final B2FileidProvider fileid, final B2WriteFeature writer); @Override Path mkdir(final Path folder, final String region, final TransferStatus status); @Override boolean isSupported(final Path workdir, final String name); @Override B2DirectoryFeature withWriter(final Write<BaseB2Response> writer); }
B2DirectoryFeature implements Directory<BaseB2Response> { @Override public Path mkdir(final Path folder, final String region, final TransferStatus status) throws BackgroundException { try { if(containerService.isContainer(folder)) { final B2BucketResponse response = session.getClient().createBucket(containerService.getContainer(folder).getName(), null == region ? BucketType.valueOf(PreferencesFactory.get().getProperty("b2.bucket.acl.default")) : BucketType.valueOf(region)); switch(response.getBucketType()) { case allPublic: folder.attributes().setAcl(new Acl(new Acl.GroupUser(Acl.GroupUser.EVERYONE, false), new Acl.Role(Acl.Role.READ))); } return new Path(folder.getParent(), folder.getName(), folder.getType(), new PathAttributes(folder.attributes())); } else { status.setChecksum(writer.checksum(folder, status).compute(new NullInputStream(0L), status)); status.setMime(MimeTypeService.DEFAULT_CONTENT_TYPE); final StatusOutputStream<BaseB2Response> out = writer.write(folder, status, new DisabledConnectionCallback()); new DefaultStreamCloser().close(out); final EnumSet<Path.Type> type = EnumSet.copyOf(folder.getType()); type.add(Path.Type.placeholder); return new Path(folder.getParent(), folder.getName(), type, new B2AttributesFinderFeature(session, fileid).toAttributes((B2FileResponse) out.getStatus())); } } catch(B2ApiException e) { throw new B2ExceptionMappingService().map("Cannot create folder {0}", e, folder); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } B2DirectoryFeature(final B2Session session, final B2FileidProvider fileid);  B2DirectoryFeature(final B2Session session, final B2FileidProvider fileid, final B2WriteFeature writer); @Override Path mkdir(final Path folder, final String region, final TransferStatus status); @Override boolean isSupported(final Path workdir, final String name); @Override B2DirectoryFeature withWriter(final Write<BaseB2Response> writer);  }