/** * Add the headers to the method, and the auth token (which must be set * @param method method to update * @param requestHeaders the list of headers * @throws SwiftInternalStateException not yet authenticated */ private void setHeaders(HttpMethodBase method, Header[] requestHeaders) throws SwiftInternalStateException { for (Header header : requestHeaders) { method.addRequestHeader(header); } setAuthToken(method, getToken()); }
private static <T> T checkNotNull(T reference, String message) throws SwiftInternalStateException { if (reference == null) { throw new SwiftInternalStateException(message); } return reference; }
@Override public synchronized void write(byte[] buffer, int offset, int len) throws IOException { //validate args if (offset < 0 || len < 0 || (offset + len) > buffer.length) { throw new IndexOutOfBoundsException("Invalid offset/length for write"); } //validate the output stream verifyOpen(); SwiftUtils.debug(LOG, " write(offset=%d, len=%d)", offset, len); // if the size of file is greater than the partition limit while (blockOffset + len >= filePartSize) { // - then partition the blob and upload as many partitions // are needed. //how many bytes to write for this partition. int subWriteLen = (int) (filePartSize - blockOffset); if (subWriteLen < 0 || subWriteLen > len) { throw new SwiftInternalStateException("Invalid subwrite len: " + subWriteLen + " -buffer len: " + len); } writeToBackupStream(buffer, offset, subWriteLen); //move the offset along and length down offset += subWriteLen; len -= subWriteLen; //now upload the partition that has just been filled up // (this also sets blockOffset=0) partUpload(false); } //any remaining data is now written writeToBackupStream(buffer, offset, len); }
/** * Performs the HTTP request, validates the response code and returns * the received data. HTTP Status codes are converted into exceptions. * * @param uri URI to source * @param processor HttpMethodProcessor * @param <M> method * @param <R> result type * @return result of HTTP request * @throws IOException IO problems * @throws SwiftBadRequestException the status code indicated "Bad request" * @throws SwiftInvalidResponseException the status code is out of range * for the action (excluding 404 responses) * @throws SwiftInternalStateException the internal state of this client * is invalid * @throws FileNotFoundException a 404 response was returned */ private <M extends HttpMethod, R> R perform(URI uri, HttpMethodProcessor<M, R> processor) throws IOException, SwiftBadRequestException, SwiftInternalStateException, SwiftInvalidResponseException, FileNotFoundException { return perform("",uri, processor); }
/** * Set the auth key header of the method to the token ID supplied * * @param method method * @param accessToken access token * @throws SwiftInternalStateException if the client is not yet authenticated */ private void setAuthToken(HttpMethodBase method, AccessToken accessToken) throws SwiftInternalStateException { checkNotNull(accessToken,"Not authenticated"); method.addRequestHeader(HEADER_AUTH_KEY, accessToken.getId()); }
/** * Ensures that an object reference passed as a parameter to the calling * method is not null. * * @param reference an object reference * @return the non-null reference that was validated * @throws NullPointerException if {@code reference} is null */ private static <T> T checkNotNull(T reference) throws SwiftInternalStateException { return checkNotNull(reference, "Null Reference"); }