Search in sources :

Example 1 with OneDriveServiceException

use of com.onedrive.sdk.http.OneDriveServiceException in project keepass2android by PhilippC.

the class OneDriveStorage method getFileEntry.

@Override
public FileEntry getFileEntry(String filename) throws Exception {
    try {
        filename = removeProtocol(filename);
        Item item = oneDriveClient.getDrive().getRoot().getItemWithPath(filename).buildRequest().get();
        return getFileEntry(filename, item);
    } catch (OneDriveServiceException e) {
        throw convertException(e);
    }
}
Also used : Item(com.onedrive.sdk.extensions.Item) OneDriveServiceException(com.onedrive.sdk.http.OneDriveServiceException)

Example 2 with OneDriveServiceException

use of com.onedrive.sdk.http.OneDriveServiceException in project keepass2android by PhilippC.

the class OneDriveStorage method openFileForRead.

@Override
public InputStream openFileForRead(String path) throws Exception {
    try {
        path = removeProtocol(path);
        logDebug("openFileForRead. Path=" + path);
        InputStream result = oneDriveClient.getDrive().getRoot().getItemWithPath(path).getContent().buildRequest().get();
        logDebug("ok");
        return result;
    } catch (OneDriveServiceException e) {
        throw convertException(e);
    }
}
Also used : InputStream(java.io.InputStream) OneDriveServiceException(com.onedrive.sdk.http.OneDriveServiceException)

Example 3 with OneDriveServiceException

use of com.onedrive.sdk.http.OneDriveServiceException in project keepass2android by PhilippC.

the class OneDriveStorage method listFiles.

@Override
public List<FileEntry> listFiles(String parentPath) throws Exception {
    try {
        ArrayList<FileEntry> result = new ArrayList<FileEntry>();
        parentPath = removeProtocol(parentPath);
        IItemCollectionPage itemsPage = oneDriveClient.getDrive().getRoot().getItemWithPath(parentPath).getChildren().buildRequest().get();
        if (parentPath.endsWith("/"))
            parentPath = parentPath.substring(0, parentPath.length() - 1);
        while (true) {
            List<Item> items = itemsPage.getCurrentPage();
            if (items.isEmpty())
                return result;
            for (Item i : items) {
                FileEntry e = getFileEntry(parentPath + "/" + i.name, i);
                Log.d("KP2AJ", e.path);
                result.add(e);
            }
            IItemCollectionRequestBuilder nextPageReqBuilder = itemsPage.getNextPage();
            if (nextPageReqBuilder == null)
                return result;
            itemsPage = nextPageReqBuilder.buildRequest().get();
        }
    } catch (OneDriveServiceException e) {
        throw convertException(e);
    }
}
Also used : Item(com.onedrive.sdk.extensions.Item) IItemCollectionPage(com.onedrive.sdk.extensions.IItemCollectionPage) ArrayList(java.util.ArrayList) IItemCollectionRequestBuilder(com.onedrive.sdk.extensions.IItemCollectionRequestBuilder) OneDriveServiceException(com.onedrive.sdk.http.OneDriveServiceException)

Aggregations

OneDriveServiceException (com.onedrive.sdk.http.OneDriveServiceException)3 Item (com.onedrive.sdk.extensions.Item)2 IItemCollectionPage (com.onedrive.sdk.extensions.IItemCollectionPage)1 IItemCollectionRequestBuilder (com.onedrive.sdk.extensions.IItemCollectionRequestBuilder)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1