当前位置: 首页>>代码示例>>Java>>正文


Java DropboxServerException类代码示例

本文整理汇总了Java中com.dropbox.client2.exception.DropboxServerException的典型用法代码示例。如果您正苦于以下问题:Java DropboxServerException类的具体用法?Java DropboxServerException怎么用?Java DropboxServerException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DropboxServerException类属于com.dropbox.client2.exception包,在下文中一共展示了DropboxServerException类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createPhotoFolder

import com.dropbox.client2.exception.DropboxServerException; //导入依赖的package包/类
/**
 * Creates a directory for photos if one does not already exist. If the folder already exists, this call will
 * do nothing.
 *
 * @param dropboxApi the {@link DropboxAPI}.
 * @return true if the directory is created or it already exists; false otherwise.
 */
private boolean createPhotoFolder(DropboxAPI<AndroidAuthSession> dropboxApi) {
    boolean folderCreated = false;
    if (dropboxApi != null) {
        try {
            dropboxApi.createFolder(mContext.getString(R.string.wings_dropbox__photo_folder));
            folderCreated = true;
        } catch (DropboxException e) {
            // Consider the folder created if the folder already exists.
            if (e instanceof DropboxServerException) {
                folderCreated = DropboxServerException._403_FORBIDDEN == ((DropboxServerException) e).error;
            }
        }
    }
    return folderCreated;
}
 
开发者ID:groundupworks,项目名称:wings,代码行数:23,代码来源:DropboxEndpoint.java

示例2: notFoundException

import com.dropbox.client2.exception.DropboxServerException; //导入依赖的package包/类
private DropboxServerException notFoundException() {
    HttpResponseFactory factory = new DefaultHttpResponseFactory();
    HttpResponse response = factory.newHttpResponse(new BasicStatusLine(
            HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_FOUND, null), null);
    return new DropboxServerException(response);
}
 
开发者ID:GoogleCloudPlatform,项目名称:endpoints-codelab-android,代码行数:7,代码来源:DropboxFileDownloaderTest.java

示例3: upload

import com.dropbox.client2.exception.DropboxServerException; //导入依赖的package包/类
/**
 * Uploads multiple chunks of data to the server until the upload is complete or an
 * error occurs.
 *
 * This method makes multiple requests to Dropbox, uploading multiple chunks of data
 * from the given ChunkedUploader's input stream. In the event of a network error or
 * a server error, an IOException or DropboxServerException respectively will be thrown.
 * This gives the user an opportunity to resume the upload by calling this method again,
 * or aborting and abandoning it.
 *
 * @param listener A ProgressListener (can be {@code null}) that will be notified of upload
 *                 progress.  The progress notifications will be for the entire file.
 *
 * @throws DropboxException If there was a transmission error
 * @throws IOException If there was a problem reading from the given InputStream.
 * @throws DropboxPartialFileException if the request was canceled before completion.
 */
public void upload(ProgressListener listener) throws DropboxException, IOException {
    while (offset < targetLength) {

        int nextChunkSize = (int)Math.min(chunkSize, targetLength - offset);

        ProgressListener adjustedListener = null;
        if (listener != null) {
            adjustedListener = new ProgressListener.Adjusted(listener, offset, targetLength);
        }

        if (lastChunk == null) {
            lastChunk = new byte[nextChunkSize];
            int bytesRead = stream.read(lastChunk);
            if (bytesRead < lastChunk.length) {
                throw new IllegalStateException("InputStream ended after " + (offset + bytesRead) + " bytes, expecting " + targetLength + " bytes.");
            }
        }
        try {
            synchronized(this) {
                if(!active) {
                    throw new DropboxPartialFileException(0);
                }
                lastRequest = chunkedUploadRequest(new ByteArrayInputStream(lastChunk), lastChunk.length, adjustedListener, offset, uploadId);
            }

            ChunkedUploadResponse resp = lastRequest.upload();

            this.offset = resp.getOffset();
            this.uploadId = resp.getUploadId();
            lastChunk = null;
        } catch (DropboxServerException e) {
            if (e.body.fields.containsKey("offset")) {
                long newOffset = (Long)e.body.fields.get("offset");
                if (newOffset > offset) {
                    lastChunk = null;
                    offset = newOffset;
                } else {
                    throw e;
                }
            } else {
                throw e;
            }
        }
    }



}
 
开发者ID:timezra,项目名称:dropbox-java-sdk,代码行数:66,代码来源:DropboxAPI.java


注:本文中的com.dropbox.client2.exception.DropboxServerException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。