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


Java TransferObserver类代码示例

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


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

示例1: onError

import com.amazonaws.mobileconnectors.s3.transferutility.TransferObserver; //导入依赖的package包/类
@Override
public synchronized void onError(final int id, final Exception ex) {
    final ContentProgressListener listener = progressListeners.get(id);
    final TransferObserver observer = transfersInProgress.get(id);
    Log.d(LOG_TAG, ex.getMessage(), ex);

    if (listener != null) {
        ThreadUtils.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                listener.onError(getRelativeFilePath(observer.getAbsoluteFilePath()), ex);
            }
        });
    }

    // The transfer is not cleaned up here, since it is handled when
    // the state changes to failed above in onStateChanged().
}
 
开发者ID:jtran064,项目名称:PlatePicks-Android,代码行数:19,代码来源:S3TransferHelper.java

示例2: uploadFile

import com.amazonaws.mobileconnectors.s3.transferutility.TransferObserver; //导入依赖的package包/类
/**
 * @param key      the S3 Key. Note that the value provided as 'bucketPath' in
 *                 {@link #provideCredentials(String, String, String, String, String)}
 *                 will be prepended to this value
 * @param contents the file contents to upload
 * @param metadata any additional metadata, like caching headers
 */
private void uploadFile(@NonNull String key,
                        @NonNull File contents,
                        @NonNull ObjectMetadata metadata) {
    String absoluteKey = new File(bucketPath, key).getPath();
    TransferObserver observer = transferUtility.upload(
            bucket,
            absoluteKey,
            contents,
            metadata
    );
    // TODO: destination URL via S3 SDK?
    String destinationUrl = String.format("https://%s.s3.amazonaws.com/%s", bucket, absoluteKey);
    activeUploadMap.put(observer.getId(), new ActiveUpload(contents, destinationUrl));
    observer.setTransferListener(this);
    Timber.d("Beginning upload of %s to %s",
            contents.getAbsolutePath(),
            destinationUrl);
}
 
开发者ID:PerchLive,项目名称:PerchBroadcast-Android-SDK,代码行数:26,代码来源:S3QueuedUploader.java

示例3: initData

import com.amazonaws.mobileconnectors.s3.transferutility.TransferObserver; //导入依赖的package包/类
/**
 * Gets all relevant transfers from the Transfer Service for populating the
 * UI
 */
private void initData() {
    transferRecordMaps.clear();
    // Use TransferUtility to get all upload transfers.
    observers = transferUtility.getTransfersWithType(TransferType.UPLOAD);
    TransferListener listener = new UploadListener();
    for (TransferObserver observer : observers) {

        // For each transfer we will will create an entry in
        // transferRecordMaps which will display
        // as a single row in the UI
        HashMap<String, Object> map = new HashMap<String, Object>();
        Util.fillMap(map, observer, false);
        transferRecordMaps.add(map);

        // Sets listeners to in progress transfers
        if (TransferState.WAITING.equals(observer.getState())
                || TransferState.WAITING_FOR_NETWORK.equals(observer.getState())
                || TransferState.IN_PROGRESS.equals(observer.getState())) {
            observer.setTransferListener(listener);
        }
    }
    simpleAdapter.notifyDataSetChanged();
}
 
开发者ID:awslabs,项目名称:aws-sdk-android-samples,代码行数:28,代码来源:UploadActivity.java

示例4: beginUpload

import com.amazonaws.mobileconnectors.s3.transferutility.TransferObserver; //导入依赖的package包/类
private void beginUpload(String filePath) {
    if (filePath == null) {
        Toast.makeText(this, "Could not find the filepath of the selected file",
                Toast.LENGTH_LONG).show();
        return;
    }
    File file = new File(filePath);
    TransferObserver observer = transferUtility.upload(Constants.BUCKET_NAME, file.getName(),
            file);
    /*
     * Note that usually we set the transfer listener after initializing the
     * transfer. However it isn't required in this sample app. The flow is
     * click upload button -> start an activity for image selection
     * startActivityForResult -> onActivityResult -> beginUpload -> onResume
     * -> set listeners to in progress transfers.
     */
    // observer.setTransferListener(new UploadListener());
}
 
开发者ID:awslabs,项目名称:aws-sdk-android-samples,代码行数:19,代码来源:UploadActivity.java

示例5: initData

import com.amazonaws.mobileconnectors.s3.transferutility.TransferObserver; //导入依赖的package包/类
/**
 * Gets all relevant transfers from the Transfer Service for populating the
 * UI
 */
private void initData() {
    transferRecordMaps.clear();
    // Uses TransferUtility to get all previous download records.
    observers = transferUtility.getTransfersWithType(TransferType.DOWNLOAD);
    TransferListener listener = new DownloadListener();
    for (TransferObserver observer : observers) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        Util.fillMap(map, observer, false);
        transferRecordMaps.add(map);

        // Sets listeners to in progress transfers
        if (TransferState.WAITING.equals(observer.getState())
                || TransferState.WAITING_FOR_NETWORK.equals(observer.getState())
                || TransferState.IN_PROGRESS.equals(observer.getState())) {
            observer.setTransferListener(listener);
        }
    }
    simpleAdapter.notifyDataSetChanged();
}
 
开发者ID:awslabs,项目名称:aws-sdk-android-samples,代码行数:24,代码来源:DownloadActivity.java

示例6: beginDownload

import com.amazonaws.mobileconnectors.s3.transferutility.TransferObserver; //导入依赖的package包/类
private void beginDownload(String key) {
    // Location to download files from S3 to. You can choose any accessible
    // file.
    File file = new File(Environment.getExternalStorageDirectory().toString() + "/" + key);

    // Initiate the download
    TransferObserver observer = transferUtility.download(Constants.BUCKET_NAME, key, file);
    /*
     * Note that usually we set the transfer listener after initializing the
     * transfer. However it isn't required in this sample app. The flow is
     * click upload button -> start an activity for image selection
     * startActivityForResult -> onActivityResult -> beginUpload -> onResume
     * -> set listeners to in progress transfers.
     */
    // observer.setTransferListener(new DownloadListener());
}
 
开发者ID:awslabs,项目名称:aws-sdk-android-samples,代码行数:17,代码来源:DownloadActivity.java

示例7: startTransfer

import com.amazonaws.mobileconnectors.s3.transferutility.TransferObserver; //导入依赖的package包/类
private TransferObserver startTransfer(final String filePath, final long fileSize,
                                       final ContentProgressListener listener) {
    final TransferObserver observer;
    final File localTransferFile = new File(localTransferPath + filePath);
    final String s3Key = s3DirPrefix + filePath;
    final int transferId;

    synchronized (this) {
        sizeTransferring += fileSize;
        observer = transferUtility.download(bucket, s3Key, localTransferFile);

        transferId = observer.getId();
        // Set the progress listener for the transfer
        progressListeners.put(transferId, listener);

        transfersInProgress.put(transferId, observer);
        managedFilesToTransfers.put(filePath, transferId);
    }

    // Set our self to listen for progress and state changes. This should
    // not be set until the observer has been added to the progressListeners
    // data structure.
    // (This does not stop listening onPause and resume listening onResume;
    // instead it stays listening until the download succeeds or fails.)
    observer.setTransferListener(this);

    // Transfers get created in the waiting state, which we will miss since we can't set
    // our listener until we have a transfer ID to associate it with, and even if we
    // could it appear that the initial creation of the transfer causes onStateChanged
    // to be called.
    onStateChanged(transferId, observer.getState());

    return observer;
}
 
开发者ID:jtran064,项目名称:PlatePicks-Android,代码行数:35,代码来源:S3TransferHelper.java

示例8: setProgressListener

import com.amazonaws.mobileconnectors.s3.transferutility.TransferObserver; //导入依赖的package包/类
/**
 * Sets the progress listener for a given s3Key being transferred.
 * @param relativeFilePath the relative path and file name.
 * @param listener the progress listener.
 */
public synchronized void setProgressListener(final String relativeFilePath, final ContentProgressListener listener) {
    final Integer transferId = managedFilesToTransfers.get(relativeFilePath);
    if (transferId != null) {
        if (listener == null) {
            progressListeners.remove(transferId);
            return;
        }

        final TransferObserver observer = transfersInProgress.get(transferId);
        if (observer != null) {
            final ContentProgressListener currentListener = progressListeners.get(transferId);
            progressListeners.put(transferId, listener);

            if (currentListener != listener) {
                observer.refresh();
                final TransferState transferState = observer.getState();

                if (transferState == TransferState.WAITING ||
                    transferState == TransferState.WAITING_FOR_NETWORK ||
                    transferState == TransferState.RESUMED_WAITING) {
                    ThreadUtils.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            onStateChanged(transferId, transferState);
                        }
                    });
                }
            }
        }
    } else {
        Log.w(LOG_TAG, String.format("Attempt to set progress listener for file '%s'," +
            " but no transfer is in progress for that file.", relativeFilePath));
    }
}
 
开发者ID:jtran064,项目名称:PlatePicks-Android,代码行数:40,代码来源:S3TransferHelper.java

示例9: getTransferState

import com.amazonaws.mobileconnectors.s3.transferutility.TransferObserver; //导入依赖的package包/类
private synchronized TransferState getTransferState(final String relativeFilePath) {
    final Integer transferId = managedFilesToTransfers.get(relativeFilePath);
    if (transferId == null) {
        return null;
    }
    final TransferObserver observer = transfersInProgress.get(transferId);
    observer.refresh();
    return observer.getState();
}
 
开发者ID:jtran064,项目名称:PlatePicks-Android,代码行数:10,代码来源:S3TransferHelper.java

示例10: cleanUpTransfer

import com.amazonaws.mobileconnectors.s3.transferutility.TransferObserver; //导入依赖的package包/类
/**
 * Cleans up all accounting data structures related to a transfer. Should be called from a
 * context that is synchronized on this object.
 * @param observer the transfer observer.
 */
private synchronized void cleanUpTransfer(final TransferObserver observer) {
    final int transferId = observer.getId();
    final String relativePath = getRelativeFilePath(observer.getAbsoluteFilePath());
    observer.cleanTransferListener();
    transfersInProgress.remove(transferId);
    managedFilesToTransfers.remove(relativePath);
    transferUtility.deleteTransferRecord(transferId);
    progressListeners.remove(transferId);
}
 
开发者ID:jtran064,项目名称:PlatePicks-Android,代码行数:15,代码来源:S3TransferHelper.java

示例11: onProgressChanged

import com.amazonaws.mobileconnectors.s3.transferutility.TransferObserver; //导入依赖的package包/类
@Override
public synchronized void onProgressChanged(final int id, final long bytesCurrent, final long bytesTotal) {
    final TransferObserver observer = transfersInProgress.get(id);
    if (observer == null) {
        // Logging at debug level since the on progress changed update frequently happens
        // after the state has already changed to complete.
        Log.d(LOG_TAG, String.format("Received progress update for id(%d), but transfer not in progress.", id));
        return;
    }
    final String filePath = getRelativeFilePath(observer.getAbsoluteFilePath());
    final ContentProgressListener listener = progressListeners.get(id);
    final long maxCacheSize = localContentCache.getMaxCacheSize();

    final boolean isPinned = localContentCache.shouldPinFile(filePath);
    if (!isPinned && bytesTotal > maxCacheSize) {
        // cancel the transfer
        transferUtility.cancel(id);
        cleanUpTransfer(observer);
    }
    if (listener != null) {
        ThreadUtils.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (!isPinned && bytesTotal > maxCacheSize) {
                    listener.onError(filePath, new IllegalStateException(String.format(
                        "Cancelled due to transfer size %s exceeds max cache size of %s",
                        StringFormatUtils.getBytesString(bytesTotal, true),
                        StringFormatUtils.getBytesString(maxCacheSize, true))));
                } else {
                    listener.onProgressUpdate(filePath, false, bytesCurrent,
                        bytesTotal);
                }
            }
        });
    }
}
 
开发者ID:jtran064,项目名称:PlatePicks-Android,代码行数:37,代码来源:S3TransferHelper.java

示例12: transferFile

import com.amazonaws.mobileconnectors.s3.transferutility.TransferObserver; //导入依赖的package包/类
private void transferFile(File compressedFile, String parent, TransferListenerAdapter transferListener) {
    String filename = getFilename(compressedFile, parent);
    transferListener.setFilename(filename);
    transferListener.setBucket(context.getString(R.string.amazon_s3_bucket_id));

    TransferObserver observer = AmazonServicesManager.getTransferUtility()
            .upload(AmazonServicesManager.BUCKET_ID, filename, compressedFile);
    transfersRetained.add(transferListener);
    observer.setTransferListener(transferListener);
}
 
开发者ID:rapidpro,项目名称:ureport-android,代码行数:11,代码来源:TransferManager.java

示例13: upload

import com.amazonaws.mobileconnectors.s3.transferutility.TransferObserver; //导入依赖的package包/类
protected void upload(){
    mProgressCallback.setExporting(true);
    init();

    mProgressCallback.showProgress(ProgressUpdateCallback.UPLOAD);

    TransferObserver observer = mTransferUtility.upload(
            mCtx.getResources().getString(R.string.door43_bucket),     /* The bucket to upload to */
            mZipFile.getName(),    /* The key for the uploaded object */
            mZipFile        /* The file where the data to upload exists */
    );
    observer.setTransferListener(mListener);

}
 
开发者ID:WycliffeAssociates,项目名称:translationRecorder,代码行数:15,代码来源:S3Export.java

示例14: onPause

import com.amazonaws.mobileconnectors.s3.transferutility.TransferObserver; //导入依赖的package包/类
@Override
protected void onPause() {
    super.onPause();
    // Clear transfer listeners to prevent memory leak, or
    // else this activity won't be garbage collected.
    if (observers != null && !observers.isEmpty()) {
        for (TransferObserver observer : observers) {
            observer.cleanTransferListener();
        }
    }
}
 
开发者ID:awslabs,项目名称:aws-sdk-android-samples,代码行数:12,代码来源:UploadActivity.java

示例15: updateList

import com.amazonaws.mobileconnectors.s3.transferutility.TransferObserver; //导入依赖的package包/类
private void updateList() {
    TransferObserver observer = null;
    HashMap<String, Object> map = null;
    for (int i = 0; i < observers.size(); i++) {
        observer = observers.get(i);
        map = transferRecordMaps.get(i);
        Util.fillMap(map, observer, i == checkedIndex);
    }
    simpleAdapter.notifyDataSetChanged();

}
 
开发者ID:awslabs,项目名称:aws-sdk-android-samples,代码行数:12,代码来源:UploadActivity.java


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