本文整理匯總了Java中org.apache.commons.lang3.RandomUtils.nextBytes方法的典型用法代碼示例。如果您正苦於以下問題:Java RandomUtils.nextBytes方法的具體用法?Java RandomUtils.nextBytes怎麽用?Java RandomUtils.nextBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.lang3.RandomUtils
的用法示例。
在下文中一共展示了RandomUtils.nextBytes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testWriteUmlaut
import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
@Test
public void testWriteUmlaut() throws Exception {
final OneDriveWriteFeature feature = new OneDriveWriteFeature(session);
final Path container = new OneDriveHomeFinderFeature(session).find();
final byte[] content = RandomUtils.nextBytes(2048);
final TransferStatus status = new TransferStatus();
status.setLength(content.length);
final Path file = new Path(container, String.format("%sä", new AlphanumericRandomStringService().random()), EnumSet.of(Path.Type.file));
final HttpResponseOutputStream<Void> out = feature.write(file, status, new DisabledConnectionCallback());
final ByteArrayInputStream in = new ByteArrayInputStream(content);
assertEquals(content.length, IOUtils.copyLarge(in, out));
in.close();
out.close();
assertNull(out.getStatus());
assertTrue(new DefaultFindFeature(session).find(file));
final byte[] compare = new byte[content.length];
final InputStream stream = new OneDriveReadFeature(session).read(file, new TransferStatus().length(content.length), new DisabledConnectionCallback());
IOUtils.readFully(stream, compare);
stream.close();
assertArrayEquals(content, compare);
new OneDriveDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
示例2: testInterruptStatus
import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
@Test
public void testInterruptStatus() throws Exception {
final ProtocolFactory factory = new ProtocolFactory(new HashSet<>(Collections.singleton(new IRODSProtocol())));
final Profile profile = new ProfilePlistReader(factory).read(
new Local("../profiles/iRODS (iPlant Collaborative).cyberduckprofile"));
final Host host = new Host(profile, profile.getDefaultHostname(), new Credentials(
System.getProperties().getProperty("irods.key"), System.getProperties().getProperty("irods.secret")
));
final IRODSSession session = new IRODSSession(host);
session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
final int length = 32770;
final byte[] content = RandomUtils.nextBytes(length);
final OutputStream out = local.getOutputStream(false);
IOUtils.write(content, out);
out.close();
final Path test = new Path(new IRODSHomeFinderService(session).find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
final TransferStatus status = new TransferStatus().length(content.length);
final Checksum checksum = new IRODSUploadFeature(session).upload(
test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener() {
@Override
public void sent(final long bytes) {
super.sent(bytes);
status.setCanceled();
}
},
status,
new DisabledConnectionCallback());
assertTrue(status.isCanceled());
assertFalse(status.isComplete());
session.close();
}
示例3: testCopyFile
import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
@Test
public void testCopyFile() throws Exception {
final Path home = new OneDriveHomeFinderFeature(session).find();
final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
final Path source = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final Path target = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore());
cryptomator.create(session, null, new VaultCredentials("test"));
final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator);
session.withRegistry(registry);
final byte[] content = RandomUtils.nextBytes(40500);
final TransferStatus status = new TransferStatus();
new CryptoBulkFeature<>(session, new DisabledBulkFeature(), new OneDriveDeleteFeature(session), cryptomator).pre(Transfer.Type.upload, Collections.singletonMap(source, status), new DisabledConnectionCallback());
new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), new CryptoWriteFeature<>(session, new OneDriveWriteFeature(session), cryptomator).write(source, status.length(content.length), new DisabledConnectionCallback()));
assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(source));
final CopyWorker worker = new CopyWorker(Collections.singletonMap(source, target), new TestSessionPool(session, registry), PathCache.empty(), new DisabledProgressListener(), new DisabledConnectionCallback());
worker.run(session);
assertTrue(new CryptoFindFeature(session, new OneDriveFindFeature(session), cryptomator).find(source));
assertTrue(new CryptoFindFeature(session, new OneDriveFindFeature(session), cryptomator).find(target));
final ByteArrayOutputStream out = new ByteArrayOutputStream(content.length);
assertEquals(content.length, IOUtils.copy(new CryptoReadFeature(session, new OneDriveReadFeature(session), cryptomator).read(target, new TransferStatus().length(content.length), new DisabledConnectionCallback()), out));
assertArrayEquals(content, out.toByteArray());
new DeleteWorker(new DisabledLoginCallback(), Collections.singletonList(vault), PathCache.empty(), new DisabledProgressListener()).run(session);
session.close();
}
示例4: testWrite
import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
@Test
public void testWrite() throws Exception {
final OneDriveWriteFeature feature = new OneDriveWriteFeature(session);
final Path container = new OneDriveHomeFinderFeature(session).find();
final byte[] content = RandomUtils.nextBytes(5 * 1024 * 1024);
final TransferStatus status = new TransferStatus();
status.setLength(content.length);
final Path file = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final HttpResponseOutputStream<Void> out = feature.write(file, status, new DisabledConnectionCallback());
final ByteArrayInputStream in = new ByteArrayInputStream(content);
final byte[] buffer = new byte[32 * 1024];
assertEquals(content.length, IOUtils.copyLarge(in, out, buffer));
in.close();
out.close();
assertNull(out.getStatus());
assertTrue(new DefaultFindFeature(session).find(file));
final byte[] compare = new byte[content.length];
final InputStream stream = new OneDriveReadFeature(session).read(file, new TransferStatus().length(content.length), new DisabledConnectionCallback());
IOUtils.readFully(stream, compare);
stream.close();
assertArrayEquals(content, compare);
new OneDriveDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
示例5: testCopy3
import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
@Test
public void testCopy3() throws Exception {
final ByteArrayOutputStream proxy = new ByteArrayOutputStream(40500);
final MemorySegementingOutputStream out = new MemorySegementingOutputStream(proxy, 32768);
final byte[] content = RandomUtils.nextBytes(40500);
out.write(content, 0, 32767);
assertEquals(0, proxy.toByteArray().length);
out.write(content, 32767, 2);
assertEquals(32768, proxy.toByteArray().length);
out.write(content, 32769, 7731);
out.close();
assertArrayEquals(content, proxy.toByteArray());
}
示例6: testReadRange
import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
@Test
public void testReadRange() throws Exception {
final Path drive = new MantaDirectoryFeature(session).mkdir(randomDirectory(), "", new TransferStatus());
final Path test = new Path(drive, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
new MantaTouchFeature(session).touch(test, new TransferStatus());
final Local local = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());
final int BYTES_TOTAL = 10;//00;
final int BYTES_OFFSET = 1;//00;
final byte[] content = RandomUtils.nextBytes(BYTES_TOTAL);
final OutputStream out = local.getOutputStream(false);
assertNotNull(out);
IOUtils.write(content, out);
out.close();
new DefaultUploadFeature<Void>(new MantaWriteFeature(session)).upload(
test,
local,
new BandwidthThrottle(BandwidthThrottle.UNLIMITED),
new DisabledStreamListener(),
new TransferStatus().length(content.length),
new DisabledConnectionCallback());
final TransferStatus status = new TransferStatus();
status.setLength(content.length);
status.setAppend(true);
status.setOffset(BYTES_OFFSET);
final MantaReadFeature read = new MantaReadFeature(session);
assertTrue(read.offset(test));
final InputStream in = read.read(test, status.length(content.length - BYTES_OFFSET), new DisabledConnectionCallback());
assertNotNull(in);
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length - BYTES_OFFSET);
new StreamCopier(status, status).transfer(in, buffer);
final byte[] reference = new byte[content.length - BYTES_OFFSET];
System.arraycopy(content, BYTES_OFFSET, reference, 0, content.length - BYTES_OFFSET);
assertArrayEquals(reference, buffer.toByteArray());
in.close();
new MantaDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
示例7: testWriteDesktopIni
import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
@Test(expected = AccessDeniedException.class)
public void testWriteDesktopIni() throws Exception {
final DropboxWriteFeature write = new DropboxWriteFeature(session);
final TransferStatus status = new TransferStatus();
final byte[] content = RandomUtils.nextBytes(0);
status.setLength(content.length);
final Path test = new Path(new DefaultHomeFinderService(session).find(), "desktop.ini", EnumSet.of(Path.Type.file));
final OutputStream out = write.write(test, status, new DisabledConnectionCallback());
new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out);
}
示例8: testCopyFile
import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
@Test
public void testCopyFile() throws Exception {
final Host host = new Host(new FTPTLSProtocol(), "test.cyberduck.ch", new Credentials(
System.getProperties().getProperty("ftp.user"), System.getProperties().getProperty("ftp.password")
));
final FTPSession session = new FTPSession(host);
session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
final Path home = new DefaultHomeFinderService(session).find();
final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
final Path source = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final Path target = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore());
cryptomator.create(session, null, new VaultCredentials("test"));
final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator);
session.withRegistry(registry);
final byte[] content = RandomUtils.nextBytes(40500);
final TransferStatus status = new TransferStatus();
new CryptoBulkFeature<>(session, new DisabledBulkFeature(), new FTPDeleteFeature(session), cryptomator).pre(Transfer.Type.upload, Collections.singletonMap(source, status), new DisabledConnectionCallback());
new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), new CryptoWriteFeature<>(session, new FTPWriteFeature(session), cryptomator).write(source, status.length(content.length), new DisabledConnectionCallback()));
assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(source));
final FTPSession copySession = new FTPSession(host);
copySession.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
copySession.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
final CopyWorker worker = new CopyWorker(Collections.singletonMap(source, target), new TestSessionPool(copySession, registry), PathCache.empty(), new DisabledProgressListener(), new DisabledConnectionCallback());
worker.run(session);
assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(source));
assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(target));
final ByteArrayOutputStream out = new ByteArrayOutputStream(content.length);
final InputStream in = new CryptoReadFeature(session, new FTPReadFeature(session), cryptomator).read(target, new TransferStatus().length(content.length), new DisabledConnectionCallback());
assertEquals(content.length, IOUtils.copy(in, out));
assertArrayEquals(content, out.toByteArray());
in.close();
new DeleteWorker(new DisabledLoginCallback(), Collections.singletonList(vault), PathCache.empty(), new DisabledProgressListener()).run(session);
session.close();
}
示例9: testCopyFile
import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
@Test
public void testCopyFile() throws Exception {
final Host host = new Host(new SFTPProtocol(), "test.cyberduck.ch", new Credentials(
System.getProperties().getProperty("sftp.user"), System.getProperties().getProperty("sftp.password")
));
final SFTPSession session = new SFTPSession(host);
session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
final Path home = new SFTPHomeDirectoryService(session).find();
final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
final Path source = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final Path target = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore());
cryptomator.create(session, null, new VaultCredentials("test"));
final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator);
session.withRegistry(registry);
final byte[] content = RandomUtils.nextBytes(40500);
final TransferStatus status = new TransferStatus();
new CryptoBulkFeature<>(session, new DisabledBulkFeature(), new SFTPDeleteFeature(session), cryptomator).pre(Transfer.Type.upload, Collections.singletonMap(source, status), new DisabledConnectionCallback());
new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), new CryptoWriteFeature<>(session, new SFTPWriteFeature(session), cryptomator).write(source, status.length(content.length), new DisabledConnectionCallback()));
assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(source));
assertEquals(content.length, new CryptoAttributesFeature(session, new SFTPAttributesFinderFeature(session), cryptomator).find(source).getSize());
final CopyWorker worker = new CopyWorker(Collections.singletonMap(source, target), new TestSessionPool(session, registry), PathCache.empty(), new DisabledProgressListener(), new DisabledConnectionCallback());
worker.run(session);
assertTrue(new CryptoFindFeature(session, new SFTPFindFeature(session), cryptomator).find(source));
assertTrue(new CryptoFindFeature(session, new SFTPFindFeature(session), cryptomator).find(target));
final ByteArrayOutputStream out = new ByteArrayOutputStream(content.length);
assertEquals(content.length, IOUtils.copy(new CryptoReadFeature(session, new SFTPReadFeature(session), cryptomator).read(target, new TransferStatus().length(content.length), new DisabledConnectionCallback()), out));
assertArrayEquals(content, out.toByteArray());
new DeleteWorker(new DisabledLoginCallback(), Collections.singletonList(vault), PathCache.empty(), new DisabledProgressListener()).run(session);
session.close();
}
示例10: testMultiplePartsWithSHA256Checksum
import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
@Test
public void testMultiplePartsWithSHA256Checksum() throws Exception {
// 5L * 1024L * 1024L
final S3Session session = new S3Session(
new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
new Credentials(
System.getProperties().getProperty("s3.key"), System.getProperties().getProperty("s3.secret")
))) {
};
session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
final S3MultipartUploadService m = new S3MultipartUploadService(session, new S3WriteFeature(session, new S3DisabledMultipartService()), 5242880L, 5);
final Path container = new Path("test-eu-central-1-cyberduck", 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 int length = 5242881;
final byte[] content = RandomUtils.nextBytes(length);
IOUtils.write(content, local.getOutputStream(false));
final TransferStatus status = new TransferStatus();
status.setLength(content.length);
m.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), status, null);
assertEquals((long) content.length, status.getOffset(), 0L);
assertTrue(status.isComplete());
assertTrue(new S3FindFeature(session).find(test));
assertEquals(content.length, new S3AttributesFinderFeature(session).find(test).getSize());
new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
local.delete();
session.close();
}
示例11: testRead
import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
@Test
public void testRead() throws Exception {
final ProtocolFactory factory = new ProtocolFactory(new HashSet<>(Collections.singleton(new IRODSProtocol())));
final Profile profile = new ProfilePlistReader(factory).read(
new Local("../profiles/iRODS (iPlant Collaborative).cyberduckprofile"));
final Host host = new Host(profile, profile.getDefaultHostname(), new Credentials(
System.getProperties().getProperty("irods.key"), System.getProperties().getProperty("irods.secret")
));
final IRODSSession session = new IRODSSession(host);
session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
final Path test = new Path(new IRODSHomeFinderService(session).find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
assertFalse(session.getFeature(Find.class).find(test));
final byte[] content = RandomUtils.nextBytes(2048);
final TransferStatus status = new TransferStatus();
status.setLength(content.length);
status.setAppend(false);
final OutputStream out = new IRODSWriteFeature(session).write(test, status, new DisabledConnectionCallback());
assertNotNull(out);
new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
out.close();
assertTrue(session.getFeature(Find.class).find(test));
final InputStream in = new IRODSReadFeature(session).read(test, status, new DisabledConnectionCallback());
assertNotNull(in);
in.close();
session.getFeature(Delete.class).delete(Arrays.asList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
assertFalse(session.getFeature(Find.class).find(test));
session.close();
}
示例12: testWrite
import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
@Test
public void testWrite() throws Exception {
final TransferStatus status = new TransferStatus();
final int length = 1048576;
final byte[] content = RandomUtils.nextBytes(length);
status.setLength(content.length);
final Path home = DriveHomeFinderService.MYDRIVE_FOLDER;
final CryptoVault cryptomator = new CryptoVault(
new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new DisabledPasswordStore());
final Path vault = cryptomator.create(session, null, new VaultCredentials("test"));
final Path test = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
final CryptoWriteFeature<Void> writer = new CryptoWriteFeature<Void>(session, new DriveWriteFeature(session), cryptomator);
final Cryptor cryptor = cryptomator.getCryptor();
final FileHeader header = cryptor.fileHeaderCryptor().create();
status.setHeader(cryptor.fileHeaderCryptor().encryptHeader(header));
status.setNonces(new RotatingNonceGenerator(cryptomator.numberOfChunks(content.length)));
status.setChecksum(writer.checksum(test).compute(new ByteArrayInputStream(content), status));
final OutputStream out = writer.write(test, status, new DisabledConnectionCallback());
Assert.assertNotNull(out);
new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
out.close();
Assert.assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(test));
Assert.assertEquals(content.length, new CryptoAttributesFeature(session, new DefaultAttributesFinderFeature(session), cryptomator).find(test).getSize());
Assert.assertEquals(content.length, writer.append(test, status.getLength(), PathCache.empty()).size, 0L);
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
final InputStream in = new CryptoReadFeature(session, new DriveReadFeature(session), cryptomator).read(test, new TransferStatus().length(content.length), new DisabledConnectionCallback());
new StreamCopier(status, status).transfer(in, buffer);
Assert.assertArrayEquals(content, buffer.toByteArray());
new CryptoDeleteFeature(session, new DriveDeleteFeature(session), cryptomator).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
示例13: testWrite
import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
@Test
public void testWrite() throws Exception {
final OneDriveBufferWriteFeature feature = new OneDriveBufferWriteFeature(session);
final Path container = new OneDriveHomeFinderFeature(session).find();
final byte[] content = RandomUtils.nextBytes(5 * 1024);
final TransferStatus status = new TransferStatus();
status.setLength(content.length);
final Path file = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final HttpResponseOutputStream<Void> out = feature.write(file, status, new DisabledConnectionCallback());
final ByteArrayInputStream in = new ByteArrayInputStream(content);
new StreamCopier(status, status).transfer(in, out);
in.close();
out.flush();
assertEquals(content.length, status.getOffset());
assertEquals(content.length, status.getLength());
out.close();
assertEquals(content.length, status.getOffset());
assertEquals(content.length, status.getLength());
assertNull(out.getStatus());
assertTrue(new DefaultFindFeature(session).find(file));
final byte[] compare = new byte[content.length];
final InputStream stream = new OneDriveReadFeature(session).read(file, new TransferStatus().length(content.length), new DisabledConnectionCallback());
IOUtils.readFully(stream, compare);
stream.close();
assertArrayEquals(content, compare);
new OneDriveDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
示例14: testAbortPartialRead
import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
@Test
public void testAbortPartialRead() throws Exception {
final Host host = new Host(new FTPTLSProtocol(), "test.cyberduck.ch", new Credentials(
System.getProperties().getProperty("ftp.user"), System.getProperties().getProperty("ftp.password")
));
final FTPSession session = new FTPSession(host);
session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
final Path test = new Path(new FTPWorkdirService(session).find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
session.getFeature(Touch.class).touch(test, new TransferStatus());
final OutputStream out = new FTPWriteFeature(session).write(test, new TransferStatus().length(20L), new DisabledConnectionCallback());
assertNotNull(out);
final byte[] content = RandomUtils.nextBytes(2048);
new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out);
out.close();
final TransferStatus status = new TransferStatus();
status.setLength(20L);
final Path workdir = new FTPWorkdirService(session).find();
final InputStream in = new FTPReadFeature(session).read(test, status, new DisabledConnectionCallback());
assertNotNull(in);
assertTrue(in.read() > 0);
// Send ABOR because stream was not read completly
in.close();
// Make sure subsequent PWD command works
assertEquals(workdir, new FTPWorkdirService(session).find());
new FTPDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
session.close();
}
示例15: testWriteZeroLength
import org.apache.commons.lang3.RandomUtils; //導入方法依賴的package包/類
@Test
public void testWriteZeroLength() throws Exception {
final Host host = new Host(new SwiftProtocol(), "identity.api.rackspacecloud.com", new Credentials(
System.getProperties().getProperty("rackspace.key"), System.getProperties().getProperty("rackspace.secret")
));
final SwiftSession session = new SwiftSession(host);
session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
final SwiftRegionService regionService = new SwiftRegionService(session);
final SwiftLargeUploadWriteFeature feature = new SwiftLargeUploadWriteFeature(session, regionService,
new SwiftSegmentService(session, ".segments-test/"));
final Path container = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume));
final byte[] content = RandomUtils.nextBytes(0);
final TransferStatus status = new TransferStatus();
status.setLength(-1L);
final Path file = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final HttpResponseOutputStream<List<StorageObject>> out = feature.write(file, status, new DisabledConnectionCallback());
final ByteArrayInputStream in = new ByteArrayInputStream(content);
assertEquals(content.length, IOUtils.copyLarge(in, out));
in.close();
out.close();
assertNotNull(out.getStatus());
assertTrue(new DefaultFindFeature(session).find(file));
final byte[] compare = new byte[content.length];
final InputStream stream = new SwiftReadFeature(session, regionService).read(file, new TransferStatus().length(content.length), new DisabledConnectionCallback());
IOUtils.readFully(stream, compare);
stream.close();
assertArrayEquals(content, compare);
new SwiftDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}