Java tutorial
package ch.cyberduck.core.googlestorage; /* * Copyright (c) 2002-2016 iterate GmbH. All rights reserved. * https://cyberduck.io/ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ import ch.cyberduck.core.DisabledListProgressListener; import ch.cyberduck.core.DisabledLoginCallback; import ch.cyberduck.core.Local; import ch.cyberduck.core.Path; import ch.cyberduck.core.PathAttributes; import ch.cyberduck.core.features.Delete; import ch.cyberduck.core.io.BandwidthThrottle; import ch.cyberduck.core.io.DisabledStreamListener; import ch.cyberduck.core.s3.S3DefaultDeleteFeature; import ch.cyberduck.core.s3.S3DisabledMultipartService; import ch.cyberduck.core.s3.S3FindFeature; import ch.cyberduck.core.s3.S3SingleUploadService; import ch.cyberduck.core.s3.S3WriteFeature; import ch.cyberduck.core.transfer.TransferStatus; import ch.cyberduck.test.IntegrationTest; import org.apache.commons.io.IOUtils; import org.apache.commons.text.RandomStringGenerator; import org.junit.Test; import org.junit.experimental.categories.Category; import java.io.OutputStream; import java.nio.charset.Charset; import java.util.Collections; import java.util.EnumSet; import java.util.UUID; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @Category(IntegrationTest.class) public class S3SingleUploadServiceTest extends AbstractGoogleStorageTest { @Test public void testUpload() throws Exception { final S3SingleUploadService m = new S3SingleUploadService(session, new S3WriteFeature(session, new S3DisabledMultipartService())); final Path container = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume)); final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()); final String random = new RandomStringGenerator.Builder().build().generate(1000); final OutputStream out = local.getOutputStream(false); IOUtils.write(random, out, Charset.defaultCharset()); out.close(); final TransferStatus status = new TransferStatus(); status.setLength(random.getBytes().length); m.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), status, new DisabledLoginCallback()); assertTrue(new S3FindFeature(session).find(test)); final PathAttributes attributes = session.list(container, new DisabledListProgressListener()).get(test) .attributes(); assertEquals(random.getBytes().length, attributes.getSize()); new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); local.delete(); } }