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


Java FileMetadata.getRev方法代码示例

本文整理汇总了Java中com.dropbox.core.v2.files.FileMetadata.getRev方法的典型用法代码示例。如果您正苦于以下问题:Java FileMetadata.getRev方法的具体用法?Java FileMetadata.getRev怎么用?Java FileMetadata.getRev使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.dropbox.core.v2.files.FileMetadata的用法示例。


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

示例1: download

import com.dropbox.core.v2.files.FileMetadata; //导入方法依赖的package包/类
/**
 * Download file from Dropbox and store it to a local file.
 */
public VersionedRook download(Uri repoUri, Uri uri, File localFile) throws IOException {
    linkedOrThrow();

    OutputStream out = new BufferedOutputStream(new FileOutputStream(localFile));

    try {
        Metadata pathMetadata = dbxClient.files().getMetadata(uri.getPath());

        if (pathMetadata instanceof FileMetadata) {
            FileMetadata metadata = (FileMetadata) pathMetadata;

            String rev = metadata.getRev();
            long mtime = metadata.getServerModified().getTime();

            dbxClient.files().download(metadata.getPathLower(), rev).download(out);

            return new VersionedRook(repoUri, uri, rev, mtime);

        } else {
            throw new IOException("Failed downloading Dropbox file " + uri + ": Not a file");
        }

    } catch (DbxException e) {
        if (e.getMessage() != null) {
            throw new IOException("Failed downloading Dropbox file " + uri + ": " + e.getMessage());
        } else {
            throw new IOException("Failed downloading Dropbox file " + uri + ": " + e.toString());
        }
    } finally {
        out.close();
    }
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:36,代码来源:DropboxClient.java

示例2: move

import com.dropbox.core.v2.files.FileMetadata; //导入方法依赖的package包/类
public VersionedRook move(Uri repoUri, Uri from, Uri to) throws IOException {
    linkedOrThrow();

    try {
        FileMetadata metadata = (FileMetadata) dbxClient.files().move(from.getPath(), to.getPath());

        String rev = metadata.getRev();
        long mtime = metadata.getServerModified().getTime();

        return new VersionedRook(repoUri, to, rev, mtime);

    } catch (Exception e) {
        e.printStackTrace();

        if (e.getMessage() != null) { // TODO: Move this throwing to utils
            throw new IOException("Failed moving " + from + " to " + to + ": " + e.getMessage(), e);
        } else {
            throw new IOException("Failed moving " + from + " to " + to + ": " + e.toString(), e);
        }
    }
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:22,代码来源:DropboxClient.java

示例3: upload

import com.dropbox.core.v2.files.FileMetadata; //导入方法依赖的package包/类
/** Upload file to Dropbox. */
public VersionedRook upload(File file, Uri repoUri, String fileName) throws IOException {
    linkedOrThrow();

    Uri bookUri = repoUri.buildUpon().appendPath(fileName).build();

    if (file.length() > UPLOAD_FILE_SIZE_LIMIT * 1024 * 1024) {
        throw new IOException(LARGE_FILE);
    }

    FileMetadata metadata;
    InputStream in = new FileInputStream(file);

    try {
        metadata = dbxClient.files()
                .uploadBuilder(bookUri.getPath())
                .withMode(WriteMode.OVERWRITE)
                .uploadAndFinish(in);

    } catch (DbxException e) {
        if (e.getMessage() != null) {
            throw new IOException("Failed overwriting " + bookUri.getPath() + " on Dropbox: " + e.getMessage());
        } else {
            throw new IOException("Failed overwriting " + bookUri.getPath() + " on Dropbox: " + e.toString());
        }
    }

    String rev = metadata.getRev();
    long mtime = metadata.getServerModified().getTime();

    return new VersionedRook(repoUri, bookUri, rev, mtime);
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:33,代码来源:DropboxClient.java

示例4: run

import com.dropbox.core.v2.files.FileMetadata; //导入方法依赖的package包/类
public void run(){

            File file = null;

            try{

                file = File.createTempFile( "mybooks", "json" );

                try( FileOutputStream out = new FileOutputStream( file ) ){
                    String json = mGson.toJson( updatedBooks );
                    out.write( json.getBytes() );
                    FileMetadata fileMetadata = dbxClientV2.files()
                            .uploadBuilder(BOOKS_FILE_PATH)
                            .withMode(WriteMode.OVERWRITE)
                            .uploadAndFinish(new FileInputStream(file));

                    mLatestRev = fileMetadata.getRev();
                    setBooks( updatedBooks );
                    notifyBooksChanged();

                    if( delBook != null ){
                        notifyBookDeleted( delBook );
                    }else{
                        notifyUploadOk();
                    }
                }

            }catch( Exception e ){
                Log.e( getClass().getName(), e.toString() );
                notifyError( String.format( "error uploading file (%s)", e.getMessage() ) );

            }finally{
                if( file != null ) file.delete();
                mUpdateFileThread = null;
            }

        }
 
开发者ID:derlin,项目名称:mybooks-android,代码行数:38,代码来源:DboxService.java

示例5: printChanges

import com.dropbox.core.v2.files.FileMetadata; //导入方法依赖的package包/类
/**
 * Prints changes made to a folder in Dropbox since the given
 * cursor was retrieved.
 *
 * @param dbxClient Dropbox client to use for fetching folder changes
 * @param cursor lastest cursor received since last set of changes
 *
 * @return latest cursor after changes
 */
private static String printChanges(DbxClientV2 client, String cursor)
    throws DbxApiException, DbxException {

    while (true) {
        ListFolderResult result = client.files()
            .listFolderContinue(cursor);
        for (Metadata metadata : result.getEntries()) {
            String type;
            String details;
            if (metadata instanceof FileMetadata) {
                FileMetadata fileMetadata = (FileMetadata) metadata;
                type = "file";
                details = "(rev=" + fileMetadata.getRev() + ")";
            } else if (metadata instanceof FolderMetadata) {
                FolderMetadata folderMetadata = (FolderMetadata) metadata;
                type = "folder";
                details = folderMetadata.getSharingInfo() != null ? "(shared)" : "";
            } else if (metadata instanceof DeletedMetadata) {
                type = "deleted";
                details = "";
            } else {
                throw new IllegalStateException("Unrecognized metadata type: " + metadata.getClass());
            }

            System.out.printf("\t%10s %24s \"%s\"\n", type, details, metadata.getPathLower());
        }
        // update cursor to fetch remaining results
        cursor = result.getCursor();

        if (!result.getHasMore()) {
            break;
        }
    }

    return cursor;
}
 
开发者ID:dropbox,项目名称:dropbox-sdk-java,代码行数:46,代码来源:Main.java

示例6: getBooks

import com.dropbox.core.v2.files.FileMetadata; //导入方法依赖的package包/类
public List<VersionedRook> getBooks(Uri repoUri) throws IOException {
    linkedOrThrow();

    List<VersionedRook> list = new ArrayList<>();

    String path = repoUri.getPath();

    /* Fix root path. */
    if (path == null || path.equals("/")) {
        path = ROOT_PATH;
    }

    /* Strip trailing slashes. */
    path = path.replaceAll("/+$", "");

    try {
        if (ROOT_PATH.equals(path) || dbxClient.files().getMetadata(path) instanceof FolderMetadata) {
            /* Get folder content. */
            ListFolderResult result = dbxClient.files().listFolder(path);
            while (true) {
                for (Metadata metadata : result.getEntries()) {
                    if (metadata instanceof FileMetadata) {
                        FileMetadata file = (FileMetadata) metadata;

                        if (BookName.isSupportedFormatFileName(file.getName())) {
                            Uri uri = repoUri.buildUpon().appendPath(file.getName()).build();
                            VersionedRook book = new VersionedRook(
                                    repoUri,
                                    uri,
                                    file.getRev(),
                                    file.getServerModified().getTime());

                            list.add(book);
                        }
                    }
                }

                if (!result.getHasMore()) {
                    break;
                }

                result = dbxClient.files().listFolderContinue(result.getCursor());
            }

        } else {
            throw new IOException("Not a directory: " + repoUri);
        }

    } catch (DbxException e) {
        e.printStackTrace();

        /* If we get NOT_FOUND from Dropbox, just return the empty list. */
        if (e instanceof GetMetadataErrorException) {
            if (((GetMetadataErrorException) e).errorValue.getPathValue() == LookupError.NOT_FOUND) {
                return list;
            }
        }

        throw new IOException("Failed getting the list of files in " + repoUri +
                              " listing " + path + ": " +
                              (e.getMessage() != null ? e.getMessage() : e.toString()));
    }

    return list;
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:66,代码来源:DropboxClient.java


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