123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720 |
- package com.epson.iprint.storage.onedrive;
- import android.app.Activity;
- import android.content.Context;
- import android.os.AsyncTask;
- import android.support.p000v4.app.NotificationCompat;
- import com.box.androidsdk.content.models.BoxRepresentation;
- import com.epson.iprint.storage.StorageItem;
- import com.epson.iprint.storage.StorageSecureStore;
- import com.epson.iprint.storage.StorageServiceClient;
- import com.onedrive.sdk.authentication.IAccountInfo;
- import com.onedrive.sdk.concurrency.ChunkedUploadProvider;
- import com.onedrive.sdk.concurrency.ICallback;
- import com.onedrive.sdk.concurrency.IProgressCallback;
- import com.onedrive.sdk.core.ClientException;
- import com.onedrive.sdk.core.OneDriveErrorCodes;
- import com.onedrive.sdk.extensions.ChunkedUploadSessionDescriptor;
- import com.onedrive.sdk.extensions.IItemCollectionPage;
- import com.onedrive.sdk.extensions.IItemCollectionRequestBuilder;
- import com.onedrive.sdk.extensions.IOneDriveClient;
- import com.onedrive.sdk.extensions.Item;
- import com.onedrive.sdk.extensions.Shared;
- import com.onedrive.sdk.extensions.UploadSession;
- import com.onedrive.sdk.options.QueryOption;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- import epson.print.CommonDefine;
- import epson.print.R;
- import epson.server.utils.Define;
- public class OneDriveClient extends StorageServiceClient {
- private static final String[] EXTENSIONS_IPRINT_SPEC = {"doc", "docx", "rtf", "xls", "xlsm", "xlsx", "ppt", "pptx", "pps", "ppsx"};
- private static final String[] EXTENSIONS_ONEDRIVE_SPEC = {"doc", "docx", "epub", "eml", "htm", "html", "md", NotificationCompat.CATEGORY_MESSAGE, "odp", "ods", "odt", "pps", "ppsx", "ppt", "pptx", "rtf", "tif", "tiff", "xls", "xlsm", "xlsx"};
- private static final String[] MIMETYPE_IPRINT_SPEC = {CommonDefine.DOC_TYPE_1, CommonDefine.DOCX_TYPE_2, CommonDefine.POWERPOINT_TYPE_1, "application/vnd.openxmlformats-officedocument.presentationml.slideshow", CommonDefine.POWERPOINT_TYPE_2, CommonDefine.RTF_TYPE, CommonDefine.EXCEL_TYPE_1, CommonDefine.EXCEL_TYPE_2, "application/vnd.ms-excel.sheet.macroEnabled.12"};
- protected static final String TAG = "OneDriveClient";
- private List<StorageItem> mStorageItemList;
- private StorageServiceClient.ProcessError mUploadProcessError;
- private IOneDriveClient oneDriveClient;
- public interface OnOneDriveClientListener {
- void onNotifyOneDriveClientCollectionPage(List<StorageItem> list);
- }
- protected boolean isNeedSignin() {
- return true;
- }
- public boolean isSupportedUploadType(StorageServiceClient.UploadFileType uploadFileType) {
- return false;
- }
- public OneDriveClient() {
- resetUploadProcessError();
- }
- public StorageServiceClient.ProcessError getUploadProcessError() {
- return mUploadProcessError;
- }
- public void resetUploadProcessError() {
- mUploadProcessError = StorageServiceClient.ProcessError.NONE;
- }
- public StorageServiceClient.Uploader getUploader(Context context, StorageServiceClient.UploadFileType uploadFileType, String str, String str2) {
- return new OneDriveUploader(context, uploadFileType, str, str2);
- }
- public StorageServiceClient.Downloader getDownloader(Context context, StorageItem storageItem, String str) {
- return new OneDriveDownloader(context, storageItem, str);
- }
- public StorageServiceClient.Enumerator getEnumerator(final Context context) {
- return new StorageServiceClient.Enumerator() {
- public void enumerate(StorageItem storageItem, StorageServiceClient.EnumerateCompletion enumerateCompletion) {
- }
- public StorageItem getRootItem() {
- return new StorageItem("", "", StorageItem.ItemType.DIRECTORY, (Object) null);
- }
- public void enumerate(StorageItem storageItem, final StorageServiceClient.EnumerateCompletion enumerateCompletion, final StorageServiceClient.SigninCompletion signinCompletion) {
- if (storageItem.path.isEmpty()) {
- OneDriveClient.this.getClient((Activity) context, new OneDriveAuthenticator.OnOneDriveAuthenticatorListener() {
- public void onNotifyOneDriveClient(IOneDriveClient iOneDriveClient) {
- if (iOneDriveClient != null) {
- StorageServiceClient.SigninCompletion signinCompletion = signinCompletion;
- if (signinCompletion != null) {
- signinCompletion.onSigninCompletion();
- }
- OneDriveClient.this.getRootFolder(iOneDriveClient, enumerateCompletion);
- return;
- }
- enumerateCompletion.onEnumerateComplete(OneDriveClient.this.mStorageItemList, StorageServiceClient.ProcessError.ERROR);
- }
- });
- return;
- }
- String str = ((Item) storageItem.userInfo).f323id;
- OneDriveClient oneDriveClient = OneDriveClient.this;
- oneDriveClient.getItems(oneDriveClient.oneDriveClient, str, enumerateCompletion);
- }
- };
- }
- public boolean isSignedIn(Context context) {
- return StorageSecureStore.getSharedSecureStore().fetch(Define.ONEDRIVE_TOKEN) != null;
- }
- public boolean revokeSignedInData(Activity activity) {
- StorageSecureStore.getSharedSecureStore().revoke(Define.ONEDRIVE_TOKEN);
- IOneDriveClient iOneDriveClient = oneDriveClient;
- if (iOneDriveClient == null) {
- return false;
- }
- logOut(iOneDriveClient, new ICallback<Void>() {
- public void success(Void voidR) {
- IOneDriveClient unused = OneDriveClient.this.oneDriveClient = null;
- }
- public void failure(ClientException clientException) {
- clientException.printStackTrace();
- IOneDriveClient unused = OneDriveClient.this.oneDriveClient = null;
- }
- });
- return false;
- }
- public String getStorageServiceName(Context context) {
- return context.getString(R.string.onedrive);
- }
- private void getItems(IOneDriveClient iOneDriveClient, String str, StorageServiceClient.EnumerateCompletion enumerateCompletion) {
- mStorageItemList = new ArrayList();
- getItem(iOneDriveClient, str, getCallbackItemCollectionPage(enumerateCompletion));
- }
- private ICallback<IItemCollectionPage> getCallbackItemCollectionPage(final StorageServiceClient.EnumerateCompletion enumerateCompletion) {
- return getCallbackCollectionPage(new OnOneDriveClientListener() {
- public void onNotifyOneDriveClientCollectionPage(List<StorageItem> list) {
- if (list != null) {
- list = OneDriveClient.this.getPrintableItems(list);
- }
- enumerateCompletion.onEnumerateComplete(list, list != null ? StorageServiceClient.ProcessError.NONE : StorageServiceClient.ProcessError.ERROR);
- }
- });
- }
- private void debug_list(List<StorageItem> list) {
- for (StorageItem storageItem : list) {
- getItemPhotos((Item) storageItem.userInfo);
- }
- }
- private List<StorageItem> getPrintableItems(List<StorageItem> list) {
- ArrayList arrayList = new ArrayList();
- for (StorageItem next : list) {
- if (next.type != StorageItem.ItemType.FILE || isPrintableFileTypes(next) || isConvertPdfExtension((Item) next.userInfo) || isConvertPdfMimeType((Item) next.userInfo)) {
- arrayList.add(next);
- }
- }
- return arrayList;
- }
- private ICallback<IItemCollectionPage> getCallbackCollectionPage(final OnOneDriveClientListener onOneDriveClientListener) {
- return new ICallback<IItemCollectionPage>() {
- public void success(IItemCollectionPage iItemCollectionPage) {
- if (iItemCollectionPage != null) {
- List currentPage = iItemCollectionPage.getCurrentPage();
- if (currentPage != null) {
- for (int i = 0; i < currentPage.size(); i++) {
- StorageItem access$600 = OneDriveClient.this.getStorageItem((Item) currentPage.get(i));
- if (access$600 != null) {
- OneDriveClient.this.mStorageItemList.add(access$600);
- }
- }
- if (iItemCollectionPage.getNextPage() != null) {
- OneDriveClient oneDriveClient = OneDriveClient.this;
- oneDriveClient.getNextPage(iItemCollectionPage, oneDriveClient.getCallbackCollectionPage(onOneDriveClientListener));
- return;
- }
- result(OneDriveClient.this.mStorageItemList);
- return;
- }
- result((List<StorageItem>) null);
- return;
- }
- result((List<StorageItem>) null);
- }
- public void failure(ClientException clientException) {
- clientException.printStackTrace();
- result((List<StorageItem>) null);
- }
- private void result(List<StorageItem> list) {
- OnOneDriveClientListener onOneDriveClientListener = onOneDriveClientListener;
- if (onOneDriveClientListener != null) {
- onOneDriveClientListener.onNotifyOneDriveClientCollectionPage(list);
- }
- }
- };
- }
- private StorageItem getStorageItem(Item item) {
- StorageItem storageItem = new StorageItem();
- storageItem.name = item.name;
- storageItem.path = File.separator + item.name;
- storageItem.userInfo = item;
- if (item.folder != null) {
- storageItem.type = StorageItem.ItemType.DIRECTORY;
- } else if (item.file != null) {
- storageItem.type = StorageItem.ItemType.FILE;
- } else if (item.image != null) {
- storageItem.type = StorageItem.ItemType.FILE;
- } else if (item.photo == null) {
- return null;
- } else {
- storageItem.type = StorageItem.ItemType.FILE;
- }
- return storageItem;
- }
- private void getRoot(IOneDriveClient iOneDriveClient, ICallback<Item> iCallback) {
- iOneDriveClient.getDrive().getRoot().buildRequest().get(iCallback);
- }
- private void getItem(IOneDriveClient iOneDriveClient, String str, ICallback<IItemCollectionPage> iCallback) {
- iOneDriveClient.getDrive().getItems(str).getChildren().buildRequest().get(iCallback);
- }
- private void getNextPage(IItemCollectionPage iItemCollectionPage, ICallback<IItemCollectionPage> iCallback) {
- ((IItemCollectionRequestBuilder) iItemCollectionPage.getNextPage()).buildRequest().get(iCallback);
- }
- private UploadSession getUploadSession(IOneDriveClient iOneDriveClient, String str) {
- return iOneDriveClient.getDrive().getRoot().getItemWithPath(str).getCreateSession(new ChunkedUploadSessionDescriptor()).buildRequest().post();
- }
- private void uploadLargeFile(UploadSession uploadSession, InputStream inputStream, int i, IProgressCallback<Item> iProgressCallback) {
- ChunkedUploadProvider createUploadProvider;
- QueryOption queryOption = new QueryOption("@name.conflictBehavior", "rename");
- if (uploadSession != null && (createUploadProvider = uploadSession.createUploadProvider(oneDriveClient, inputStream, i, Item.class)) != null) {
- try {
- createUploadProvider.upload(Collections.singletonList(queryOption), iProgressCallback, 655360, 5);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- private InputStream getDownloadInputStream(IOneDriveClient iOneDriveClient, String str) {
- return iOneDriveClient.getDrive().getItems(str).getContent().buildRequest().get();
- }
- private InputStream getDownloadInputStreamPdf(IOneDriveClient iOneDriveClient, String str) {
- return iOneDriveClient.getDrive().getItems(str).getContent().buildRequest(Collections.singletonList(new QueryOption("format", BoxRepresentation.TYPE_PDF))).get();
- }
- private void logOut(IOneDriveClient iOneDriveClient, ICallback<Void> iCallback) {
- iOneDriveClient.getAuthenticator().logout(iCallback);
- }
- public static void saveToken(IAccountInfo iAccountInfo) {
- String accessToken;
- if (iAccountInfo != null && (accessToken = iAccountInfo.getAccessToken()) != null && !accessToken.isEmpty()) {
- StorageSecureStore.getSharedSecureStore().put(Define.ONEDRIVE_TOKEN, accessToken, StorageSecureStore.EXEC_MODE.OVERWRITE_IF_EXIST);
- }
- }
- public boolean isSessionExpired() {
- IOneDriveClient iOneDriveClient = oneDriveClient;
- if (iOneDriveClient != null) {
- return isExpired(iOneDriveClient);
- }
- return true;
- }
- private boolean isExpired(IOneDriveClient iOneDriveClient) {
- return iOneDriveClient.getAuthenticator().getAccountInfo().isExpired();
- }
- private void getClient(Activity activity, OneDriveAuthenticator.OnOneDriveAuthenticatorListener onOneDriveAuthenticatorListener) {
- IOneDriveClient iOneDriveClient = oneDriveClient;
- if (iOneDriveClient == null) {
- getOneDriveClient(activity, onOneDriveAuthenticatorListener);
- } else if (onOneDriveAuthenticatorListener != null) {
- onOneDriveAuthenticatorListener.onNotifyOneDriveClient(iOneDriveClient);
- }
- }
- private void getOneDriveClient(Activity activity, final OneDriveAuthenticator.OnOneDriveAuthenticatorListener onOneDriveAuthenticatorListener) {
- OneDriveAuthenticator.getOneDriveClient(activity, new OneDriveAuthenticator.OnOneDriveAuthenticatorListener() {
- public void onNotifyOneDriveClient(IOneDriveClient iOneDriveClient) {
- IOneDriveClient unused = OneDriveClient.this.oneDriveClient = iOneDriveClient;
- OneDriveAuthenticator.OnOneDriveAuthenticatorListener onOneDriveAuthenticatorListener = onOneDriveAuthenticatorListener;
- if (onOneDriveAuthenticatorListener != null) {
- onOneDriveAuthenticatorListener.onNotifyOneDriveClient(OneDriveClient.this.oneDriveClient);
- }
- }
- });
- }
- private void getRootFolder(Activity activity, final StorageServiceClient.EnumerateCompletion enumerateCompletion) {
- getClient(activity, new OneDriveAuthenticator.OnOneDriveAuthenticatorListener() {
- public void onNotifyOneDriveClient(IOneDriveClient iOneDriveClient) {
- if (iOneDriveClient != null) {
- OneDriveClient.this.getRootFolder(iOneDriveClient, enumerateCompletion);
- } else {
- enumerateCompletion.onEnumerateComplete(OneDriveClient.this.mStorageItemList, StorageServiceClient.ProcessError.ERROR);
- }
- }
- });
- }
- private void getRootFolder(final IOneDriveClient iOneDriveClient, final StorageServiceClient.EnumerateCompletion enumerateCompletion) {
- getRoot(iOneDriveClient, new ICallback<Item>() {
- public void success(Item item) {
- if (item != null) {
- OneDriveClient.this.getItems(iOneDriveClient, item.f323id, enumerateCompletion);
- } else {
- enumerateCompletion.onEnumerateComplete(OneDriveClient.this.mStorageItemList, StorageServiceClient.ProcessError.ERROR);
- }
- }
- public void failure(ClientException clientException) {
- clientException.printStackTrace();
- enumerateCompletion.onEnumerateComplete(OneDriveClient.this.mStorageItemList, StorageServiceClient.ProcessError.ERROR);
- }
- });
- }
- private boolean isConvertPdfExtension(Item item) {
- int lastIndexOf;
- if (item != null && item.name != null && !item.name.isEmpty() && (lastIndexOf = item.name.lastIndexOf(CommonDefine.DOT)) > 0) {
- String substring = item.name.substring(lastIndexOf + 1);
- for (String equalsIgnoreCase : EXTENSIONS_IPRINT_SPEC) {
- if (substring.equalsIgnoreCase(equalsIgnoreCase)) {
- return true;
- }
- }
- }
- return false;
- }
- private boolean isConvertPdfMimeType(Item item) {
- if (!(item == null || item.file == null || item.file.mimeType == null)) {
- for (String equalsIgnoreCase : MIMETYPE_IPRINT_SPEC) {
- if (item.file.mimeType.equalsIgnoreCase(equalsIgnoreCase)) {
- return true;
- }
- }
- }
- return false;
- }
- private String getConvertPdfName(String str) {
- if (str == null || str.isEmpty()) {
- return "";
- }
- int lastIndexOf = str.lastIndexOf(CommonDefine.DOT);
- if (lastIndexOf > 0) {
- return str.substring(0, lastIndexOf) + CommonDefine.FileType_PDF;
- }
- return str + CommonDefine.FileType_PDF;
- }
- private String getItemPhotos(Item item) {
- String str = "";
- if (item == null) {
- return str;
- }
- if (item.name != null) {
- str = str + " name: " + item.name;
- }
- if (item.size != null) {
- str = str + " size: " + item.size;
- }
- if (item.file != null) {
- if (item.file.mimeType != null) {
- str = str + " mimeType: " + item.file.mimeType;
- }
- str = str + " -FILE- ";
- }
- if (item.folder != null) {
- str = str + " -FOLDER- ";
- }
- if (item.image != null) {
- str = str + " -IMAGE- ";
- }
- if (item.photo == null) {
- return str;
- }
- return str + " -PHOTO- ";
- }
- private String getItemDetails(Item item) {
- String str = "";
- if (item != null) {
- if (item.name != null) {
- str = str + " name: " + item.name;
- }
- if (item.size != null) {
- str = str + " size: " + item.size;
- }
- if (!(item.file == null || item.file.mimeType == null)) {
- str = str + " mimeType: " + item.file.mimeType;
- }
- if (!(item.folder == null || item.folder.childCount == null)) {
- str = str + " childCount: " + item.folder.childCount;
- }
- if (item.image != null) {
- if (item.image.width != null) {
- str = str + " width: " + item.image.width;
- }
- if (item.image.height != null) {
- str = str + " height: " + item.image.height;
- }
- }
- if (item.audio != null) {
- if (item.audio.title != null) {
- str = str + " title: " + item.audio.title;
- }
- if (item.audio.artist != null) {
- str = str + " artist: " + item.audio.artist;
- }
- if (item.audio.bitrate != null) {
- str = str + " bitrate: " + item.audio.bitrate;
- }
- }
- if (item.photo != null) {
- if (item.photo.cameraMake != null) {
- str = str + " cameraMake: " + item.photo.cameraMake;
- }
- if (item.photo.cameraModel != null) {
- str = str + " cameraModel: " + item.photo.cameraModel;
- }
- if (item.photo.exposureDenominator != null) {
- str = str + " exposureDenominator: " + item.photo.exposureDenominator;
- }
- if (item.photo.exposureNumerator != null) {
- str = str + " exposureNumerator: " + item.photo.exposureNumerator;
- }
- if (item.photo.fNumber != null) {
- str = str + " fNumber: " + item.photo.fNumber;
- }
- if (item.photo.focalLength != null) {
- str = str + " focalLength: " + item.photo.focalLength;
- }
- if (item.photo.iso != null) {
- str = str + " iso: " + item.photo.iso;
- }
- }
- if (item.video != null) {
- if (item.video.width != null) {
- str = str + " width: " + item.video.width;
- }
- if (item.video.height != null) {
- str = str + " height: " + item.video.height;
- }
- }
- if (!(item.createdBy == null || item.createdBy.application == null || item.createdBy.application.displayName == null)) {
- str = str + " createdBy-displayName: " + item.createdBy.application.displayName;
- }
- if (!(item.lastModifiedBy == null || item.lastModifiedBy.application == null || item.lastModifiedBy.application.displayName == null)) {
- str = str + " lastModifiedBy-displayName: " + item.lastModifiedBy.application.displayName;
- }
- if (!(item.parentReference == null || item.parentReference.path == null)) {
- str = str + " parentReference-path: " + item.parentReference.path;
- }
- Shared shared = item.shared;
- }
- return str;
- }
- class OneDriveDownloader extends StorageServiceClient.Downloader {
- private String mItemid;
- private StorageItem mStorageItem;
- private DownloadThread mThread = null;
- private String mWriteFilename;
- public boolean isCancelable() {
- return true;
- }
- OneDriveDownloader(Context context, StorageItem storageItem, String str) {
- super();
- mStorageItem = storageItem;
- mItemid = ((Item) storageItem.userInfo).f323id;
- mWriteFilename = str;
- }
- public void start(StorageServiceClient.DownloadCompletion downloadCompletion) {
- mThread = new DownloadThread(downloadCompletion);
- mThread.start();
- }
- public void cancel() {
- DownloadThread downloadThread = mThread;
- if (downloadThread != null) {
- downloadThread.cancel();
- }
- }
- class DownloadThread extends Thread {
- private volatile boolean bCanceled;
- private boolean bConvertPdf;
- private StorageServiceClient.DownloadCompletion downloaded;
- private InputStream inputStream;
- DownloadThread(StorageServiceClient.DownloadCompletion downloadCompletion) {
- downloaded = downloadCompletion;
- }
- public void run() {
- inputStream = null;
- boolean z = false;
- bCanceled = false;
- bConvertPdf = OneDriveClient.this.isConvertPdfExtension((Item) OneDriveDownloader.this.mStorageItem.userInfo) || OneDriveClient.this.isConvertPdfMimeType((Item) OneDriveDownloader.this.mStorageItem.userInfo);
- if (bConvertPdf && !this.bCanceled) {
- try {
- inputStream = OneDriveClient.this.getDownloadInputStreamPdf(OneDriveClient.this.oneDriveClient, OneDriveDownloader.this.mItemid);
- } catch (ClientException e) {
- e.printStackTrace();
- if (e.isError(OneDriveErrorCodes.NotSupported)) {
- bConvertPdf = inputStream != null;
- } else {
- bConvertPdf = inputStream != null;
- }
- }
- }
- if (!this.bConvertPdf && !this.bCanceled) {
- try {
- inputStream = OneDriveClient.this.getDownloadInputStream(OneDriveClient.this.oneDriveClient, OneDriveDownloader.this.mItemid);
- } catch (ClientException e2) {
- e2.printStackTrace();
- inputStream = null;
- }
- }
- String access$1600 = bConvertPdf ? OneDriveClient.this.getConvertPdfName(OneDriveDownloader.this.mWriteFilename) : OneDriveDownloader.this.mWriteFilename;
- if (inputStream != null && !this.bCanceled) {
- try {
- File file = new File(access$1600);
- if (!file.exists()) {
- file.getParentFile().mkdirs();
- }
- FileOutputStream fileOutputStream = new FileOutputStream(file, false);
- byte[] bArr = new byte[1048576];
- while (true) {
- try {
- int read = inputStream.read(bArr);
- if (read != -1 && !this.bCanceled) {
- fileOutputStream.write(bArr, 0, read);
- }
- } catch (IOException e3) {
- e3.printStackTrace();
- }
- }
- z = !this.bCanceled;
- try {
- fileOutputStream.close();
- } catch (IOException e4) {
- e4.printStackTrace();
- }
- } catch (IOException e5) {
- e5.printStackTrace();
- }
- }
- closeStream();
- downloaded.onDownloadComplete(OneDriveDownloader.this.mStorageItem, access$1600, z ? StorageServiceClient.ProcessError.NONE : bCanceled ? StorageServiceClient.ProcessError.CANCELED : StorageServiceClient.ProcessError.ERROR);
- }
- private void closeStream() {
- try {
- if (inputStream != null) {
- inputStream.close();
- inputStream = null;
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public void cancel() {
- bCanceled = true;
- }
- }
- }
- class OneDriveUploader extends StorageServiceClient.Uploader {
- private Activity mActivity;
- private LocalUploader mLocalUploader;
- private String mOrgFilePath;
- private String mUploadPath;
- public boolean isCancelable() {
- return true;
- }
- OneDriveUploader(Context context, StorageServiceClient.UploadFileType uploadFileType, String str, String str2) {
- super();
- mActivity = (Activity) context;
- mOrgFilePath = str;
- mUploadPath = str2;
- }
- public void start(StorageServiceClient.UploadCompletion uploadCompletion) {
- StorageServiceClient.ProcessError unused = OneDriveClient.this.mUploadProcessError = StorageServiceClient.ProcessError.NONE;
- OneDriveClient oneDriveClient = OneDriveClient.this;
- if (!oneDriveClient.isExpired(oneDriveClient.oneDriveClient)) {
- mLocalUploader = new LocalUploader(mActivity, mOrgFilePath, mUploadPath, uploadCompletion);
- AsyncTask.THREAD_POOL_EXECUTOR.execute(mLocalUploader);
- return;
- }
- StorageServiceClient.ProcessError unused2 = OneDriveClient.this.mUploadProcessError = StorageServiceClient.ProcessError.RETRY;
- uploadCompletion.onUploadComplete("", "", StorageServiceClient.ProcessError.RETRY);
- }
- public void cancel() {
- super.cancel();
- mLocalUploader.cancel();
- }
- }
- private class LocalUploader implements Runnable {
- private volatile boolean bCanceled = false;
- private FileInputStream fileInputStream;
- private StorageServiceClient.UploadCompletion mNotifier;
- private String mOrgFilePath;
- private String mUploadFilename;
- private boolean result = true;
- private UploadSession uploadSession;
- LocalUploader(Activity activity, String str, String str2, @NonNull StorageServiceClient.UploadCompletion uploadCompletion) {
- mOrgFilePath = str;
- mUploadFilename = str2;
- mNotifier = uploadCompletion;
- }
- public void run() {
- bCanceled = false;
- result = false;
- if (!(mOrgFilePath == null || mUploadFilename == null || bCanceled)) {
- fileInputStream = null;
- try {
- fileInputStream = new FileInputStream(mOrgFilePath);
- try {
- int available = fileInputStream.available();
- if (available > 0 && !this.bCanceled) {
- upload(available);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- } catch (FileNotFoundException e2) {
- e2.printStackTrace();
- } catch (Throwable th) {
- closefile();
- throw th;
- }
- closefile();
- }
- mNotifier.onUploadComplete(mOrgFilePath, mUploadFilename, result ? StorageServiceClient.ProcessError.NONE : bCanceled ? StorageServiceClient.ProcessError.CANCELED : StorageServiceClient.ProcessError.ERROR);
- }
- private void upload(int i) {
- uploadSession = null;
- try {
- uploadSession = OneDriveClient.this.getUploadSession(OneDriveClient.this.oneDriveClient, "/Epson iPrint/" + mUploadFilename);
- } catch (ClientException e) {
- e.printStackTrace();
- }
- UploadSession uploadSession2 = uploadSession;
- if (uploadSession2 != null) {
- OneDriveClient.this.uploadLargeFile(uploadSession2, fileInputStream, i, new IProgressCallback<Item>() {
- public void success(Item item) {
- boolean unused = LocalUploader.this.result = true;
- }
- public void failure(ClientException clientException) {
- clientException.printStackTrace();
- }
- public void progress(long j, long j2) {
- if (LocalUploader.this.bCanceled) {
- LocalUploader.this.uploadcancel();
- }
- }
- });
- }
- }
- private void uploadcancel() {
- closefile();
- }
- private void closefile() {
- try {
- if (fileInputStream != null) {
- fileInputStream.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public void cancel() {
- bCanceled = true;
- }
- }
- }
|