Search in sources :

Example 1 with MantaHttpHeaders

use of com.joyent.manta.http.MantaHttpHeaders 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);
    }
}
Also used : AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) MantaObject(com.joyent.manta.client.MantaObject) MantaHttpHeaders(com.joyent.manta.http.MantaHttpHeaders) IOException(java.io.IOException) DefaultIOExceptionMappingService(ch.cyberduck.core.DefaultIOExceptionMappingService) MantaClientHttpResponseException(com.joyent.manta.exception.MantaClientHttpResponseException) MantaException(com.joyent.manta.exception.MantaException) HttpRange(ch.cyberduck.core.http.HttpRange) NullInputStream(org.apache.commons.io.input.NullInputStream)

Aggregations

DefaultIOExceptionMappingService (ch.cyberduck.core.DefaultIOExceptionMappingService)1 AccessDeniedException (ch.cyberduck.core.exception.AccessDeniedException)1 HttpRange (ch.cyberduck.core.http.HttpRange)1 MantaObject (com.joyent.manta.client.MantaObject)1 MantaClientHttpResponseException (com.joyent.manta.exception.MantaClientHttpResponseException)1 MantaException (com.joyent.manta.exception.MantaException)1 MantaHttpHeaders (com.joyent.manta.http.MantaHttpHeaders)1 IOException (java.io.IOException)1 NullInputStream (org.apache.commons.io.input.NullInputStream)1