本文整理汇总了Java中org.apache.commons.io.IOUtils.readFully方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtils.readFully方法的具体用法?Java IOUtils.readFully怎么用?Java IOUtils.readFully使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.io.IOUtils
的用法示例。
在下文中一共展示了IOUtils.readFully方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testWriteUmlautZeroLength
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void testWriteUmlautZeroLength() throws Exception {
final OneDriveWriteFeature feature = new OneDriveWriteFeature(session);
final Path container = new OneDriveHomeFinderFeature(session).find();
final byte[] content = RandomUtils.nextBytes(0);
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: readByteArray
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
/**
* @return Byte array read from the stream.
* @throws IOException
*/
private byte[] readByteArray(final InputStream in) throws IOException {
byte[] intArray = new byte[Bytes.SIZEOF_INT];
IOUtils.readFully(in, intArray);
int length = Bytes.toInt(intArray);
byte[] bytes = new byte[length];
IOUtils.readFully(in, bytes);
return bytes;
}
示例3: testWriteUnknownLength
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void testWriteUnknownLength() throws Exception {
final OneDriveBufferWriteFeature feature = new OneDriveBufferWriteFeature(session);
final Path container = new OneDriveHomeFinderFeature(session).find();
final byte[] content = RandomUtils.nextBytes(5 * 1024 * 1024);
final TransferStatus status = new TransferStatus();
status.setLength(-1L);
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();
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());
}
示例4: testWriteZeroLength
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void testWriteZeroLength() throws Exception {
final OneDriveBufferWriteFeature feature = new OneDriveBufferWriteFeature(session);
final Path container = new OneDriveHomeFinderFeature(session).find();
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<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();
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: testWrite
import org.apache.commons.io.IOUtils; //导入方法依赖的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());
}
示例6: parseCell
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
protected Cell parseCell() throws IOException {
byte[] row = readByteArray(this.in);
byte[] family = readByteArray(in);
byte[] qualifier = readByteArray(in);
byte[] longArray = new byte[Bytes.SIZEOF_LONG];
IOUtils.readFully(this.in, longArray);
long timestamp = Bytes.toLong(longArray);
byte type = (byte) this.in.read();
byte[] value = readByteArray(in);
byte[] tags = readByteArray(in);
// Read memstore version
byte[] memstoreTSArray = new byte[Bytes.SIZEOF_LONG];
IOUtils.readFully(this.in, memstoreTSArray);
long memstoreTS = Bytes.toLong(memstoreTSArray);
return CellUtil.createCell(row, family, qualifier, timestamp, type, value, tags, memstoreTS);
}
示例7: testWrite
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void testWrite() throws Exception {
final MantaWriteFeature feature = new MantaWriteFeature(session);
final Path container = new MantaDirectoryFeature(session).mkdir(randomDirectory(), "", new TransferStatus());
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 MantaReadFeature(session).read(file, new TransferStatus().length(content.length), new DisabledConnectionCallback());
IOUtils.readFully(stream, compare);
stream.close();
assertArrayEquals(content, compare);
new MantaDeleteFeature(session).delete(Collections.singletonList(container), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
示例8: testWriteLargeChunk
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void testWriteLargeChunk() throws Exception {
final CryptoVault vault = this.getVault();
final ByteArrayOutputStream cipherText = new ByteArrayOutputStream();
final FileHeader header = vault.getCryptor().fileHeaderCryptor().create();
final CryptoOutputStream<?> stream = new CryptoOutputStream<>(new StatusOutputStream<Void>(cipherText) {
@Override
public Void getStatus() throws BackgroundException {
return null;
}
}, vault.getCryptor(), header, new RandomNonceGenerator(), 0);
final byte[] cleartext = RandomUtils.nextBytes(vault.getCryptor().fileContentCryptor().cleartextChunkSize() + 1);
stream.write(cleartext, 0, cleartext.length);
stream.close();
final byte[] read = new byte[cleartext.length];
final CryptoInputStream cryptoInputStream = new CryptoInputStream(new ByteArrayInputStream(cipherText.toByteArray()), vault.getCryptor(), header, 0);
IOUtils.readFully(cryptoInputStream, read);
cryptoInputStream.close();
assertArrayEquals(cleartext, read);
}
示例9: testReadWrite
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void testReadWrite() throws Exception {
final Host host = new Host(new SDSProtocol(), "duck.ssp-europe.eu", new Credentials(
System.getProperties().getProperty("sds.user"), System.getProperties().getProperty("sds.key")
));
final SDSSession session = new SDSSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager());
session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
final Path room = new SDSDirectoryFeature(session).mkdir(
new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.volume)), null, new TransferStatus());
final byte[] content = RandomUtils.nextBytes(32769);
final TransferStatus status = new TransferStatus();
status.setLength(content.length);
final Path test = new Path(room, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
final SDSWriteFeature writer = new SDSWriteFeature(session);
final HttpResponseOutputStream<VersionId> out = writer.write(test, status, new DisabledConnectionCallback());
assertNotNull(out);
new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
final VersionId version = out.getStatus();
assertNotNull(version);
assertTrue(new DefaultFindFeature(session).find(test));
final byte[] compare = new byte[content.length];
final InputStream stream = new SDSReadFeature(session).read(test, new TransferStatus().length(content.length), new DisabledConnectionCallback());
IOUtils.readFully(stream, compare);
stream.close();
assertArrayEquals(content, compare);
new SDSDeleteFeature(session).delete(Collections.singletonList(room), new DisabledLoginCallback(), new Delete.DisabledCallback());
session.close();
}
示例10: getBody
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private GerritProjectEvent getBody(HttpServletRequest req) throws IOException {
char[] body = new char[req.getContentLength()];
try (InputStreamReader is = new InputStreamReader(req.getInputStream())) {
IOUtils.readFully(is, body);
String bodyString = new String(body);
log.info("Received body: " + bodyString);
return gson.fromJson(bodyString, GerritProjectEvent.class);
}
}
示例11: testReadWrite
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void testReadWrite() throws Exception {
final Host host = new Host(new SDSProtocol(), "duck.ssp-europe.eu", new Credentials(
System.getProperties().getProperty("sds.user"), System.getProperties().getProperty("sds.key")
));
final SDSSession session = new SDSSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager());
session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
final Path room = new SDSDirectoryFeature(session).mkdir(
new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.volume)), null, new TransferStatus());
final byte[] content = RandomUtils.nextBytes(32769);
final TransferStatus status = new TransferStatus();
status.setLength(-1L);
final Path test = new Path(room, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
final SDSMultipartWriteFeature writer = new SDSMultipartWriteFeature(session);
final HttpResponseOutputStream<VersionId> out = writer.write(test, status, new DisabledConnectionCallback());
assertNotNull(out);
new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
final VersionId version = out.getStatus();
assertNotNull(version);
assertTrue(new DefaultFindFeature(session).find(test));
final byte[] compare = new byte[content.length];
final InputStream stream = new SDSReadFeature(session).read(test, new TransferStatus().length(content.length), new DisabledConnectionCallback());
IOUtils.readFully(stream, compare);
stream.close();
assertArrayEquals(content, compare);
new SDSDeleteFeature(session).delete(Collections.singletonList(room), new DisabledLoginCallback(), new Delete.DisabledCallback());
session.close();
}
示例12: testWriteZeroLength
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void testWriteZeroLength() throws Exception {
final B2Session session = new B2Session(
new Host(new B2Protocol(), new B2Protocol().getDefaultHostname(),
new Credentials(
System.getProperties().getProperty("b2.user"), System.getProperties().getProperty("b2.key")
)));
session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
final B2LargeUploadWriteFeature feature = new B2LargeUploadWriteFeature(session);
final Path container = new Path("test-cyberduck", 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 StatusOutputStream<VersionId> 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 B2ReadFeature(session).read(file, new TransferStatus().length(content.length), new DisabledConnectionCallback());
IOUtils.readFully(stream, compare);
stream.close();
assertArrayEquals(content, compare);
new B2DeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
示例13: testWriteZeroLength
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void testWriteZeroLength() throws Exception {
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 S3MultipartWriteFeature feature = new S3MultipartWriteFeature(session);
final Path container = new Path("test-eu-central-1-cyberduck", EnumSet.of(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<MultipartPart>> 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 S3ReadFeature(session).read(file, new TransferStatus().length(content.length), new DisabledConnectionCallback());
IOUtils.readFully(stream, compare);
stream.close();
assertArrayEquals(content, compare);
new S3DefaultDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
示例14: testWrite
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void testWrite() 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 Path home = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.volume, Path.Type.directory));
home.attributes().setRegion("DFW");
final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
final Path test = 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"));
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
final SwiftRegionService regionService = new SwiftRegionService(session);
final CryptoWriteFeature feature = new CryptoWriteFeature<List<StorageObject>>(session, new SwiftLargeUploadWriteFeature(session, regionService,
new SwiftSegmentService(session, ".segments-test/")), cryptomator);
final TransferStatus writeStatus = new TransferStatus();
final Cryptor cryptor = cryptomator.getCryptor();
final FileHeader header = cryptor.fileHeaderCryptor().create();
writeStatus.setHeader(cryptor.fileHeaderCryptor().encryptHeader(header));
writeStatus.setNonces(new RandomNonceGenerator());
writeStatus.setLength(-1L);
final OutputStream out = feature.write(test, writeStatus, new DisabledConnectionCallback());
final byte[] content = RandomUtils.nextBytes(6 * 1024 * 1024);
final ByteArrayInputStream in = new ByteArrayInputStream(content);
final TransferStatus progress = new TransferStatus();
new StreamCopier(new TransferStatus(), progress).transfer(in, out);
assertEquals(content.length, progress.getOffset());
assertTrue(new CryptoFindFeature(session, new SwiftFindFeature(session), cryptomator).find(test));
final byte[] compare = new byte[content.length];
final InputStream stream = new CryptoReadFeature(session, new SwiftReadFeature(session, regionService), cryptomator).read(test, new TransferStatus().length(content.length), new DisabledConnectionCallback());
IOUtils.readFully(stream, compare);
stream.close();
assertArrayEquals(content, compare);
new CryptoDeleteFeature(session, new SwiftDeleteFeature(session), cryptomator).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
session.close();
}
示例15: testWrite
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void testWrite() 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 Checksum checksum;
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);
checksum = new IRODSUploadFeature(session).upload(
test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(),
status,
new DisabledConnectionCallback());
assertTrue(status.isComplete());
assertEquals(content.length, status.getOffset());
assertEquals(checksum, new MD5ChecksumCompute().compute(new FileInputStream(local.getAbsolute()), status));
final byte[] buffer = new byte[content.length];
final InputStream in = new IRODSReadFeature(session).read(test, new TransferStatus().length(content.length), new DisabledConnectionCallback());
IOUtils.readFully(in, buffer);
in.close();
assertArrayEquals(content, buffer);
new IRODSDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
session.close();
}