use of com.joyent.manta.client.MantaObject in project cyberduck by iterate-ch.
the class MantaListService method list.
@Override
public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException {
if (directory.isRoot()) {
return new AttributedList<Path>(Collections.singletonList(new MantaAccountHomeInfo(session.getHost().getCredentials().getUsername(), session.getHost().getDefaultPath()).getNormalizedHomePath()));
}
final AttributedList<Path> children = new AttributedList<>();
final Iterator<MantaObject> objectsIter;
try {
objectsIter = session.getClient().listObjects(directory.getAbsolute()).iterator();
} catch (MantaObjectException e) {
throw new MantaExceptionMappingService().map("Listing directory {0} failed", e, directory);
} catch (MantaClientHttpResponseException e) {
throw new MantaHttpExceptionMappingService().map("Listing directory {0} failed", e, directory);
} catch (IOException e) {
throw new DefaultIOExceptionMappingService().map("Listing directory {0} failed", e);
}
final MantaObjectAttributeAdapter adapter = new MantaObjectAttributeAdapter(session);
while (objectsIter.hasNext()) {
MantaObject o = objectsIter.next();
final Path file = new Path(directory, PathNormalizer.name(o.getPath()), EnumSet.of(o.isDirectory() ? Path.Type.directory : Path.Type.file), adapter.toAttributes(o));
children.add(file);
listener.chunk(directory, children);
}
return children;
}
use of com.joyent.manta.client.MantaObject in project cyberduck by iterate-ch.
the class MantaReadFeature method read.
@Override
public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback connectionCallback) throws BackgroundException {
final MantaHttpHeaders headers = new MantaHttpHeaders();
try {
try {
if (status.isAppend()) {
final HttpRange range = HttpRange.withStatus(status);
headers.setByteRange(range.getStart(), range.getEnd() < 0 ? null : range.getEnd());
}
// see https://github.com/joyent/java-manta/issues/248
return session.getClient().getAsInputStream(file.getAbsolute(), headers);
} catch (UnsupportedOperationException e) {
final MantaObject probablyEmptyFile = session.getClient().head(file.getAbsolute());
if (probablyEmptyFile.getContentLength() != 0) {
throw new AccessDeniedException();
}
return new NullInputStream(0L);
}
} catch (MantaException e) {
throw new MantaExceptionMappingService().map("Download {0} failed", e, file);
} catch (MantaClientHttpResponseException e) {
throw new MantaHttpExceptionMappingService().map("Download {0} failed", e, file);
} catch (IOException e) {
throw new DefaultIOExceptionMappingService().map("Download {0} failed", e, file);
}
}
Aggregations