@Test public void testWrite() throws Exception { final TransferStatus status = new TransferStatus(); status.setMime("text/plain"); final byte[] content = "test".getBytes(StandardCharsets.UTF_8); status.setLength(content.length); final Path container = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume)); container.attributes().setRegion("IAD"); final Path test = new Path(container, UUID.randomUUID().toString() + ".txt", EnumSet.of(Path.Type.file)); final SwiftRegionService regionService = new SwiftRegionService(session); status.setMetadata(Collections.singletonMap("C", "duck")); final OutputStream out = new SwiftWriteFeature(session, regionService).write(test, status, new DisabledConnectionCallback()); assertNotNull(out); new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out); out.close(); assertTrue(new SwiftFindFeature(session).find(test)); final PathAttributes attributes = new SwiftListService(session, regionService).list(test.getParent(), new DisabledListProgressListener()).get(test).attributes(); assertEquals(content.length, attributes.getSize()); final Write.Append append = new SwiftWriteFeature(session, regionService).append(test, status.getLength(), PathCache.empty()); assertTrue(append.override); assertEquals(content.length, append.size, 0L); final byte[] buffer = new byte[content.length]; final InputStream in = new SwiftReadFeature(session, regionService).read(test, new TransferStatus(), new DisabledConnectionCallback()); IOUtils.readFully(in, buffer); in.close(); assertArrayEquals(content, buffer); final Map<String, String> metadata = new SwiftMetadataFeature(session).getMetadata(test); assertFalse(metadata.isEmpty()); assertEquals("text/plain", metadata.get("Content-Type")); assertEquals("duck", metadata.get("X-Object-Meta-C")); final OutputStream overwrite = new SwiftWriteFeature(session, regionService).write(test, new TransferStatus().length(0L), new DisabledConnectionCallback()); overwrite.close(); new SwiftDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
@Override public HttpResponseOutputStream<StorageObject> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { final DelayedHttpEntityCallable<StorageObject> command = new DelayedHttpEntityCallable<StorageObject>() { @Override public StorageObject call(final AbstractHttpEntity entity) throws BackgroundException { try { final HashMap<String, String> headers = new HashMap<>(status.getMetadata()); final Checksum checksum = status.getChecksum(); final String etag = session.getClient().storeObject( regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file), entity, headers, checksum.algorithm == HashAlgorithm.md5 ? checksum.hash : null); if(log.isDebugEnabled()) { log.debug(String.format("Saved object %s with checksum %s", file, etag)); } final StorageObject stored = new StorageObject(containerService.getKey(file)); stored.setMd5sum(etag); stored.setSize(status.getLength()); return stored; } catch(GenericException e) { throw new SwiftExceptionMappingService().map("Upload {0} failed", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Upload {0} failed", e, file); } } @Override public long getContentLength() { return status.getLength(); } }; return this.write(file, status, command); }
SwiftWriteFeature extends AbstractHttpWriteFeature<StorageObject> implements Write<StorageObject> { @Override public HttpResponseOutputStream<StorageObject> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { final DelayedHttpEntityCallable<StorageObject> command = new DelayedHttpEntityCallable<StorageObject>() { @Override public StorageObject call(final AbstractHttpEntity entity) throws BackgroundException { try { final HashMap<String, String> headers = new HashMap<>(status.getMetadata()); final Checksum checksum = status.getChecksum(); final String etag = session.getClient().storeObject( regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file), entity, headers, checksum.algorithm == HashAlgorithm.md5 ? checksum.hash : null); if(log.isDebugEnabled()) { log.debug(String.format("Saved object %s with checksum %s", file, etag)); } final StorageObject stored = new StorageObject(containerService.getKey(file)); stored.setMd5sum(etag); stored.setSize(status.getLength()); return stored; } catch(GenericException e) { throw new SwiftExceptionMappingService().map("Upload {0} failed", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Upload {0} failed", e, file); } } @Override public long getContentLength() { return status.getLength(); } }; return this.write(file, status, command); } }
SwiftWriteFeature extends AbstractHttpWriteFeature<StorageObject> implements Write<StorageObject> { @Override public HttpResponseOutputStream<StorageObject> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { final DelayedHttpEntityCallable<StorageObject> command = new DelayedHttpEntityCallable<StorageObject>() { @Override public StorageObject call(final AbstractHttpEntity entity) throws BackgroundException { try { final HashMap<String, String> headers = new HashMap<>(status.getMetadata()); final Checksum checksum = status.getChecksum(); final String etag = session.getClient().storeObject( regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file), entity, headers, checksum.algorithm == HashAlgorithm.md5 ? checksum.hash : null); if(log.isDebugEnabled()) { log.debug(String.format("Saved object %s with checksum %s", file, etag)); } final StorageObject stored = new StorageObject(containerService.getKey(file)); stored.setMd5sum(etag); stored.setSize(status.getLength()); return stored; } catch(GenericException e) { throw new SwiftExceptionMappingService().map("Upload {0} failed", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Upload {0} failed", e, file); } } @Override public long getContentLength() { return status.getLength(); } }; return this.write(file, status, command); } SwiftWriteFeature(final SwiftSession session, final SwiftRegionService regionService);  SwiftWriteFeature(final SwiftSession session, final SwiftRegionService regionService,
                             final SwiftObjectListService listService,
                             final SwiftSegmentService segmentService);  SwiftWriteFeature(final SwiftSession session, final SwiftRegionService regionService,
                             final SwiftObjectListService listService,
                             final SwiftSegmentService segmentService, final Find finder);  SwiftWriteFeature(final SwiftSession session, final SwiftRegionService regionService,
                             final SwiftObjectListService listService,
                             final SwiftSegmentService segmentService,
                             final Find finder, final AttributesFinder attributes); }
SwiftWriteFeature extends AbstractHttpWriteFeature<StorageObject> implements Write<StorageObject> { @Override public HttpResponseOutputStream<StorageObject> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { final DelayedHttpEntityCallable<StorageObject> command = new DelayedHttpEntityCallable<StorageObject>() { @Override public StorageObject call(final AbstractHttpEntity entity) throws BackgroundException { try { final HashMap<String, String> headers = new HashMap<>(status.getMetadata()); final Checksum checksum = status.getChecksum(); final String etag = session.getClient().storeObject( regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file), entity, headers, checksum.algorithm == HashAlgorithm.md5 ? checksum.hash : null); if(log.isDebugEnabled()) { log.debug(String.format("Saved object %s with checksum %s", file, etag)); } final StorageObject stored = new StorageObject(containerService.getKey(file)); stored.setMd5sum(etag); stored.setSize(status.getLength()); return stored; } catch(GenericException e) { throw new SwiftExceptionMappingService().map("Upload {0} failed", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Upload {0} failed", e, file); } } @Override public long getContentLength() { return status.getLength(); } }; return this.write(file, status, command); } SwiftWriteFeature(final SwiftSession session, final SwiftRegionService regionService);  SwiftWriteFeature(final SwiftSession session, final SwiftRegionService regionService,
                             final SwiftObjectListService listService,
                             final SwiftSegmentService segmentService);  SwiftWriteFeature(final SwiftSession session, final SwiftRegionService regionService,
                             final SwiftObjectListService listService,
                             final SwiftSegmentService segmentService, final Find finder);  SwiftWriteFeature(final SwiftSession session, final SwiftRegionService regionService,
                             final SwiftObjectListService listService,
                             final SwiftSegmentService segmentService,
                             final Find finder, final AttributesFinder attributes); @Override HttpResponseOutputStream<StorageObject> write(final Path file, final TransferStatus status, final ConnectionCallback callback); @Override Append append(final Path file, final Long length, final Cache<Path> cache); @Override boolean temporary(); @Override boolean random(); @Override ChecksumCompute checksum(final Path file, final TransferStatus status); }
SwiftWriteFeature extends AbstractHttpWriteFeature<StorageObject> implements Write<StorageObject> { @Override public HttpResponseOutputStream<StorageObject> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { final DelayedHttpEntityCallable<StorageObject> command = new DelayedHttpEntityCallable<StorageObject>() { @Override public StorageObject call(final AbstractHttpEntity entity) throws BackgroundException { try { final HashMap<String, String> headers = new HashMap<>(status.getMetadata()); final Checksum checksum = status.getChecksum(); final String etag = session.getClient().storeObject( regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file), entity, headers, checksum.algorithm == HashAlgorithm.md5 ? checksum.hash : null); if(log.isDebugEnabled()) { log.debug(String.format("Saved object %s with checksum %s", file, etag)); } final StorageObject stored = new StorageObject(containerService.getKey(file)); stored.setMd5sum(etag); stored.setSize(status.getLength()); return stored; } catch(GenericException e) { throw new SwiftExceptionMappingService().map("Upload {0} failed", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Upload {0} failed", e, file); } } @Override public long getContentLength() { return status.getLength(); } }; return this.write(file, status, command); } SwiftWriteFeature(final SwiftSession session, final SwiftRegionService regionService);  SwiftWriteFeature(final SwiftSession session, final SwiftRegionService regionService,
                             final SwiftObjectListService listService,
                             final SwiftSegmentService segmentService);  SwiftWriteFeature(final SwiftSession session, final SwiftRegionService regionService,
                             final SwiftObjectListService listService,
                             final SwiftSegmentService segmentService, final Find finder);  SwiftWriteFeature(final SwiftSession session, final SwiftRegionService regionService,
                             final SwiftObjectListService listService,
                             final SwiftSegmentService segmentService,
                             final Find finder, final AttributesFinder attributes); @Override HttpResponseOutputStream<StorageObject> write(final Path file, final TransferStatus status, final ConnectionCallback callback); @Override Append append(final Path file, final Long length, final Cache<Path> cache); @Override boolean temporary(); @Override boolean random(); @Override ChecksumCompute checksum(final Path file, final TransferStatus status);  }