@Test public void testDirectory() throws Exception { final Path bucket = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume)); final Path test = new GoogleStorageDirectoryFeature(session).mkdir(new Path(bucket, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), null, new TransferStatus()); assertTrue(new GoogleStorageFindFeature(session).find(test)); assertTrue(new DefaultFindFeature(session).find(test)); new GoogleStorageDeleteFeature(session).delete(Collections.<Path>singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
@Override public Path mkdir(final Path folder, final String location, final TransferStatus status) throws BackgroundException { try { if(containerService.isContainer(folder)) { final Bucket bucket = session.getClient().buckets().insert(session.getHost().getCredentials().getUsername(), new Bucket() .setLocation(location) .setStorageClass(status.getStorageClass()) .setName(new GoogleStoragePathContainerService().getContainer(folder).getName())).execute(); final EnumSet<Path.Type> type = EnumSet.copyOf(folder.getType()); type.add(Path.Type.volume); return new Path(folder.getParent(), folder.getName(), type, new GoogleStorageAttributesFinderFeature(session).toAttributes(bucket)); } else { status.setMime(MIMETYPE); final EnumSet<Path.Type> type = EnumSet.copyOf(folder.getType()); type.add(Path.Type.placeholder); final StatusOutputStream<VersionId> out = writer.write(new Path(folder.getParent(), folder.getName(), type, new PathAttributes(folder.attributes())), status, new DisabledConnectionCallback()); new DefaultStreamCloser().close(out); return new Path(folder.getParent(), folder.getName(), type, folder.attributes().withVersionId(out.getStatus().id)); } } catch(IOException e) { throw new GoogleStorageExceptionMappingService().map("Cannot create folder {0}", e, folder); } }
GoogleStorageDirectoryFeature implements Directory<VersionId> { @Override public Path mkdir(final Path folder, final String location, final TransferStatus status) throws BackgroundException { try { if(containerService.isContainer(folder)) { final Bucket bucket = session.getClient().buckets().insert(session.getHost().getCredentials().getUsername(), new Bucket() .setLocation(location) .setStorageClass(status.getStorageClass()) .setName(new GoogleStoragePathContainerService().getContainer(folder).getName())).execute(); final EnumSet<Path.Type> type = EnumSet.copyOf(folder.getType()); type.add(Path.Type.volume); return new Path(folder.getParent(), folder.getName(), type, new GoogleStorageAttributesFinderFeature(session).toAttributes(bucket)); } else { status.setMime(MIMETYPE); final EnumSet<Path.Type> type = EnumSet.copyOf(folder.getType()); type.add(Path.Type.placeholder); final StatusOutputStream<VersionId> out = writer.write(new Path(folder.getParent(), folder.getName(), type, new PathAttributes(folder.attributes())), status, new DisabledConnectionCallback()); new DefaultStreamCloser().close(out); return new Path(folder.getParent(), folder.getName(), type, folder.attributes().withVersionId(out.getStatus().id)); } } catch(IOException e) { throw new GoogleStorageExceptionMappingService().map("Cannot create folder {0}", e, folder); } } }
GoogleStorageDirectoryFeature implements Directory<VersionId> { @Override public Path mkdir(final Path folder, final String location, final TransferStatus status) throws BackgroundException { try { if(containerService.isContainer(folder)) { final Bucket bucket = session.getClient().buckets().insert(session.getHost().getCredentials().getUsername(), new Bucket() .setLocation(location) .setStorageClass(status.getStorageClass()) .setName(new GoogleStoragePathContainerService().getContainer(folder).getName())).execute(); final EnumSet<Path.Type> type = EnumSet.copyOf(folder.getType()); type.add(Path.Type.volume); return new Path(folder.getParent(), folder.getName(), type, new GoogleStorageAttributesFinderFeature(session).toAttributes(bucket)); } else { status.setMime(MIMETYPE); final EnumSet<Path.Type> type = EnumSet.copyOf(folder.getType()); type.add(Path.Type.placeholder); final StatusOutputStream<VersionId> out = writer.write(new Path(folder.getParent(), folder.getName(), type, new PathAttributes(folder.attributes())), status, new DisabledConnectionCallback()); new DefaultStreamCloser().close(out); return new Path(folder.getParent(), folder.getName(), type, folder.attributes().withVersionId(out.getStatus().id)); } } catch(IOException e) { throw new GoogleStorageExceptionMappingService().map("Cannot create folder {0}", e, folder); } } GoogleStorageDirectoryFeature(final GoogleStorageSession session); }
GoogleStorageDirectoryFeature implements Directory<VersionId> { @Override public Path mkdir(final Path folder, final String location, final TransferStatus status) throws BackgroundException { try { if(containerService.isContainer(folder)) { final Bucket bucket = session.getClient().buckets().insert(session.getHost().getCredentials().getUsername(), new Bucket() .setLocation(location) .setStorageClass(status.getStorageClass()) .setName(new GoogleStoragePathContainerService().getContainer(folder).getName())).execute(); final EnumSet<Path.Type> type = EnumSet.copyOf(folder.getType()); type.add(Path.Type.volume); return new Path(folder.getParent(), folder.getName(), type, new GoogleStorageAttributesFinderFeature(session).toAttributes(bucket)); } else { status.setMime(MIMETYPE); final EnumSet<Path.Type> type = EnumSet.copyOf(folder.getType()); type.add(Path.Type.placeholder); final StatusOutputStream<VersionId> out = writer.write(new Path(folder.getParent(), folder.getName(), type, new PathAttributes(folder.attributes())), status, new DisabledConnectionCallback()); new DefaultStreamCloser().close(out); return new Path(folder.getParent(), folder.getName(), type, folder.attributes().withVersionId(out.getStatus().id)); } } catch(IOException e) { throw new GoogleStorageExceptionMappingService().map("Cannot create folder {0}", e, folder); } } GoogleStorageDirectoryFeature(final GoogleStorageSession session); @Override Path mkdir(final Path folder, final String location, final TransferStatus status); @Override Directory<VersionId> withWriter(final Write<VersionId> writer); }
GoogleStorageDirectoryFeature implements Directory<VersionId> { @Override public Path mkdir(final Path folder, final String location, final TransferStatus status) throws BackgroundException { try { if(containerService.isContainer(folder)) { final Bucket bucket = session.getClient().buckets().insert(session.getHost().getCredentials().getUsername(), new Bucket() .setLocation(location) .setStorageClass(status.getStorageClass()) .setName(new GoogleStoragePathContainerService().getContainer(folder).getName())).execute(); final EnumSet<Path.Type> type = EnumSet.copyOf(folder.getType()); type.add(Path.Type.volume); return new Path(folder.getParent(), folder.getName(), type, new GoogleStorageAttributesFinderFeature(session).toAttributes(bucket)); } else { status.setMime(MIMETYPE); final EnumSet<Path.Type> type = EnumSet.copyOf(folder.getType()); type.add(Path.Type.placeholder); final StatusOutputStream<VersionId> out = writer.write(new Path(folder.getParent(), folder.getName(), type, new PathAttributes(folder.attributes())), status, new DisabledConnectionCallback()); new DefaultStreamCloser().close(out); return new Path(folder.getParent(), folder.getName(), type, folder.attributes().withVersionId(out.getStatus().id)); } } catch(IOException e) { throw new GoogleStorageExceptionMappingService().map("Cannot create folder {0}", e, folder); } } GoogleStorageDirectoryFeature(final GoogleStorageSession session); @Override Path mkdir(final Path folder, final String location, final TransferStatus status); @Override Directory<VersionId> withWriter(final Write<VersionId> writer);  }