use of ch.cyberduck.core.onedrive.features.GraphDeleteFeature in project cyberduck by iterate-ch.
the class GraphReadFeatureTest method testReadInterrupt.
@Test
public void testReadInterrupt() throws Exception {
final Path drive = new OneDriveHomeFinderService().find();
final Path test = new Path(drive, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
new GraphTouchFeature(session, fileid).touch(test, new TransferStatus());
// Unknown length in status
final TransferStatus status = new TransferStatus();
// Read a single byte
{
final InputStream in = new GraphReadFeature(session, fileid).read(test, status, new DisabledConnectionCallback());
assertNotNull(in.read());
in.close();
}
{
final InputStream in = new GraphReadFeature(session, fileid).read(test, status, new DisabledConnectionCallback());
assertNotNull(in);
in.close();
}
new GraphDeleteFeature(session, fileid).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.onedrive.features.GraphDeleteFeature in project cyberduck by iterate-ch.
the class GraphReadFeatureTest method testReadRange.
@Test
public void testReadRange() throws Exception {
final Path drive = new OneDriveHomeFinderService().find();
final Path test = new Path(drive, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
new GraphTouchFeature(session, fileid).touch(test, new TransferStatus());
final Local local = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());
final byte[] content = RandomUtils.nextBytes(1000);
final OutputStream out = local.getOutputStream(false);
assertNotNull(out);
IOUtils.write(content, out);
out.close();
new DefaultUploadFeature<>(new GraphWriteFeature(session, fileid)).upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
final TransferStatus status = new TransferStatus();
status.setLength(content.length);
status.setAppend(true);
status.setOffset(100L);
final GraphReadFeature read = new GraphReadFeature(session, fileid);
assertTrue(read.offset(test));
final InputStream in = read.read(test, status.withLength(content.length - 100), new DisabledConnectionCallback());
assertNotNull(in);
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length - 100);
new StreamCopier(status, status).transfer(in, buffer);
final byte[] reference = new byte[content.length - 100];
System.arraycopy(content, 100, reference, 0, content.length - 100);
assertArrayEquals(reference, buffer.toByteArray());
in.close();
new GraphDeleteFeature(session, fileid).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.onedrive.features.GraphDeleteFeature in project cyberduck by iterate-ch.
the class GraphWriteFeatureTest method testWriteSingleByte.
@Test
public void testWriteSingleByte() throws Exception {
final GraphWriteFeature feature = new GraphWriteFeature(session, fileid);
final Path container = new OneDriveHomeFinderService().find();
final byte[] content = RandomUtils.nextBytes(1);
final TransferStatus status = new TransferStatus();
status.setLength(content.length);
final Path file = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final StatusOutputStream<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 GraphReadFeature(session, fileid).read(file, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
IOUtils.readFully(stream, compare);
stream.close();
assertArrayEquals(content, compare);
new GraphDeleteFeature(session, fileid).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.onedrive.features.GraphDeleteFeature in project cyberduck by iterate-ch.
the class GraphWriteFeatureTest method testWriteUmlautZeroLength.
@Test
public void testWriteUmlautZeroLength() throws Exception {
final GraphWriteFeature feature = new GraphWriteFeature(session, fileid);
final Path container = new OneDriveHomeFinderService().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 StatusOutputStream<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 GraphReadFeature(session, fileid).read(file, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
IOUtils.readFully(stream, compare);
stream.close();
assertArrayEquals(content, compare);
new GraphDeleteFeature(session, fileid).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.onedrive.features.GraphDeleteFeature in project cyberduck by iterate-ch.
the class GraphWriteFeatureTest method testWriteZeroLength.
@Test
public void testWriteZeroLength() throws Exception {
final GraphWriteFeature feature = new GraphWriteFeature(session, fileid);
final Path container = new OneDriveHomeFinderService().find();
final byte[] content = RandomUtils.nextBytes(0);
final TransferStatus status = new TransferStatus();
status.setLength(content.length);
final Path file = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final StatusOutputStream<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 GraphReadFeature(session, fileid).read(file, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
IOUtils.readFully(stream, compare);
stream.close();
assertArrayEquals(content, compare);
new GraphDeleteFeature(session, fileid).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Aggregations