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


Java FileMetadata类代码示例

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


FileMetadata类属于com.dropbox.core.v2.files包,在下文中一共展示了FileMetadata类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: uploadFile

import com.dropbox.core.v2.files.FileMetadata; //导入依赖的package包/类
public FileMetadata uploadFile(File file) throws Exception {
    if (authSession()) {
        try {
            InputStream is = new FileInputStream(file);
            try {
                FileMetadata fileMetadata = dropboxClient.files().uploadBuilder("/" + file.getName()).withMode(WriteMode.ADD).uploadAndFinish(is);
                Log.i("Financisto", "Dropbox: The uploaded file's rev is: " + fileMetadata.getRev());
                return fileMetadata;
            } finally {
                IOUtil.closeInput(is);
            }
        } catch (Exception e) {
            Log.e("Financisto", "Dropbox: Something wrong", e);
            throw new ImportExportException(R.string.dropbox_error, e);
        }
    } else {
        throw new ImportExportException(R.string.dropbox_auth_error);
    }
}
 
开发者ID:tiberiusteng,项目名称:financisto1-holo,代码行数:20,代码来源:Dropbox.java

示例4: backup

import com.dropbox.core.v2.files.FileMetadata; //导入依赖的package包/类
@Override
public FileMetadata backup(BackupConfiguration backupConf) throws BackupException {
	dropboxService.assumeAvailable();
	String localFileBackup = null;
	try {	
		localFileBackup = mongoDumpService.backup(backupConf);
		FileMetadata dbFile;
		String dropTarget = getDropboxFilename(backupConf);
		try {
			dbFile = dropboxService.uploadFile(localFileBackup, dropTarget);
			log.debug("backup uploaded '{}'", dbFile.getPathLower());
		} catch (Throwable e) {
			String exMsg = String.format("Unable to upload backup '%s' to dropbox : %s", dropTarget, e.getMessage());
			throw new BackupException(exMsg, e);
		}
		return dbFile;
	} catch (BackupException be) {
		throw be;
	} finally {
		if (localFileBackup != null) {
			new File(localFileBackup).delete();
		}
	}
}
 
开发者ID:boly38,项目名称:mongodbdump-java-wrapper,代码行数:25,代码来源:DropboxMongoBackupServiceImpl.java

示例5: uploadFiles

import com.dropbox.core.v2.files.FileMetadata; //导入依赖的package包/类
private void uploadFiles(List<MotionEvent> motionEvents) throws IOException {
    for (MotionEvent motionEvent : motionEvents) {
        try (InputStream in = new ByteArrayInputStream(motionEvent.getImage())) {
            String dropboxPath = "/motion_events/" + eyeballsConfiguration.getCameraName() + "/" + concurrentDateFormatAccess.convertDateToString(motionEvent.getTimestamp());
            createFolder(dropboxPath);

            FileMetadata metadata = dbxClientV2.files().uploadBuilder(dropboxPath + "/" + motionEvent.getId() + ".jpg")
                    .withMode(WriteMode.ADD)
                    .withClientModified(motionEvent.getTimestamp())
                    .uploadAndFinish(in);

            log.debug(metadata.toStringMultiline());
        } catch (Exception e) {
            log.error("Error uploading to Dropbox. ", e);
        }
    }
}
 
开发者ID:chriskearney,项目名称:eyeballs,代码行数:18,代码来源:DropboxMotionEventConsumer.java

示例6: convertMetadata

import com.dropbox.core.v2.files.FileMetadata; //导入依赖的package包/类
public static DropboxFileData convertMetadata(final Metadata metadata) {
    final DropboxFileData.DropboxFileDataBuilder builder = DropboxFileData.builder()
        .changeType(DropboxChangeType.fromMetadata(metadata))
        .pathDisplay(metadata.getPathDisplay())
        .pathLower(metadata.getPathLower());

    if (metadata instanceof FolderMetadata) {
        final FolderMetadata folderMetadata = (FolderMetadata) metadata;
        builder.id(folderMetadata.getId());

    } else if (metadata instanceof FileMetadata) {
        final FileMetadata fileMetadata = (FileMetadata) metadata;
        final ZoneId zoneId = ZoneOffset.UTC;
        final Instant clientModifiedInstant = fileMetadata.getClientModified().toInstant();
        final Instant serverModifiedInstant = fileMetadata.getServerModified().toInstant();
        builder
            .id(fileMetadata.getId())
            .rev(fileMetadata.getRev())
            .size(fileMetadata.getSize())
            .clientModified(LocalDateTime.ofInstant(clientModifiedInstant, zoneId))
            .serverModified(LocalDateTime.ofInstant(serverModifiedInstant, zoneId));
    }

    return builder.build();
}
 
开发者ID:yuriytkach,项目名称:dsync-client,代码行数:26,代码来源:DropboxUtil.java

示例7: renderFile

import com.dropbox.core.v2.files.FileMetadata; //导入依赖的package包/类
private void renderFile(HttpServletResponse response, String path, FileMetadata f)
    throws IOException
{
    FormProtection fp = FormProtection.start(response);

    response.setContentType("text/html");
    response.setCharacterEncoding("utf-8");
    PrintWriter out = new PrintWriter(IOUtil.utf8Writer(response.getOutputStream()));

    out.println("<html>");
    out.println("<head><title>" + escapeHtml4(path) + "- Web File Browser</title></head>");
    out.println("<body>");
    fp.insertAntiRedressHtml(out);

    out.println("<h2>Path: " + escapeHtml4(path) + "</h2>");

    out.println("<pre>");
    out.print(escapeHtml4(f.toStringMultiline()));
    out.println("</pre>");

    out.println("</body>");
    out.println("</html>");

    out.flush();
}
 
开发者ID:dropbox,项目名称:dropbox-sdk-java,代码行数:26,代码来源:DropboxBrowse.java

示例8: doInBackground

import com.dropbox.core.v2.files.FileMetadata; //导入依赖的package包/类
@Override
protected FileMetadata doInBackground(String... params) {
    String localUri = params[0];
    File localFile = UriHelpers.getFileForUri(mContext, Uri.parse(localUri));

    if (localFile != null) {
        String remoteFolderPath = params[1];

        // Note - this is not ensuring the name is a valid dropbox file name
        String remoteFileName = localFile.getName();

        try (InputStream inputStream = new FileInputStream(localFile)) {
            return mDbxClient.files().uploadBuilder(remoteFolderPath + "/" + remoteFileName)
                    .withMode(WriteMode.OVERWRITE)
                    .uploadAndFinish(inputStream);
        } catch (DbxException | IOException e) {
            mException = e;
        }
    }

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

示例9: testRangeDownload

import com.dropbox.core.v2.files.FileMetadata; //导入依赖的package包/类
@Test
public void testRangeDownload() throws Exception {
    DbxClientV2 client = ITUtil.newClientV2();

    byte [] contents = ITUtil.randomBytes(500);
    String path = ITUtil.path(getClass(), "/testRangeDownload.dat");

    FileMetadata metadata = client.files().uploadBuilder(path)
        .withAutorename(false)
        .withMode(WriteMode.OVERWRITE)
        .withMute(true)
        .uploadAndFinish(new ByteArrayInputStream(contents));

    assertEquals(metadata.getSize(), contents.length);

    assertRangeDownload(client, path, contents, 0, contents.length);
    assertRangeDownload(client, path, contents, 0, 200);
    assertRangeDownload(client, path, contents, 300, 200);
    assertRangeDownload(client, path, contents, 499, 1);
    assertRangeDownload(client, path, contents, 0, 600);
    assertRangeDownload(client, path, contents, 250, null);
}
 
开发者ID:dropbox,项目名称:dropbox-sdk-java,代码行数:23,代码来源:DbxClientV2IT.java

示例10: constructFileMetadate

import com.dropbox.core.v2.files.FileMetadata; //导入依赖的package包/类
private FileMetadata constructFileMetadate() throws Exception {
    Class builderClass = FileMetadata.Builder.class;
    Constructor constructor = builderClass.getDeclaredConstructors()[0];
    constructor.setAccessible(true);

    List<Object> arguments = new ArrayList<Object>(Arrays.asList(
            "bar.txt",
            "id:1HkLjqifwMAAAAAAAAAAAQ",
            new Date(1456169040985L),
            new Date(1456169040985L),
            "2e0c38735597",
            2091603
    ));

    // hack for internal version of SDK
    if (constructor.getParameterTypes().length > 6) {
        arguments.addAll(Arrays.asList("20MB", "text.png", "text/plain"));
    }

    FileMetadata.Builder builder = (FileMetadata.Builder) constructor.newInstance(arguments.toArray());
    return builder.build();
}
 
开发者ID:dropbox,项目名称:dropbox-sdk-java,代码行数:23,代码来源:DbxClientV2Test.java

示例11: 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

示例12: read

import com.dropbox.core.v2.files.FileMetadata; //导入依赖的package包/类
@Override
public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
    try {
        final DownloadBuilder builder = new DbxUserFilesRequests(session.getClient()).downloadBuilder(file.getAbsolute());
        if(status.isAppend()) {
            final HttpRange range = HttpRange.withStatus(status);
            builder.range(range.getStart());
        }
        final DbxDownloader<FileMetadata> downloader = builder.start();
        return downloader.getInputStream();
    }
    catch(DbxException e) {
        throw new DropboxExceptionMappingService().map("Download {0} failed", e, file);
    }
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:16,代码来源:DropboxReadFeature.java

示例13: search

import com.dropbox.core.v2.files.FileMetadata; //导入依赖的package包/类
@Override
public AttributedList<Path> search(final Path workdir, final Filter<Path> regex, final ListProgressListener listener) throws BackgroundException {
    try {
        final AttributedList<Path> list = new AttributedList<>();
        long start = 0;
        SearchResult result;
        do {
            result = new DbxUserFilesRequests(session.getClient()).searchBuilder(workdir.isRoot() ? StringUtils.EMPTY : workdir.getAbsolute(), regex.toPattern().pattern())
                    .withMode(SearchMode.FILENAME).withStart(start).start();
            final List<SearchMatch> matches = result.getMatches();
            for(SearchMatch match : matches) {
                final Metadata metadata = match.getMetadata();
                final EnumSet<AbstractPath.Type> type;
                if(metadata instanceof FileMetadata) {
                    type = EnumSet.of(Path.Type.file);
                }
                else if(metadata instanceof FolderMetadata) {
                    type = EnumSet.of(Path.Type.directory);
                }
                else {
                    log.warn(String.format("Skip file %s", metadata));
                    return null;
                }
                list.add(new Path(metadata.getPathDisplay(), type, attributes.convert(metadata)));
                listener.chunk(workdir, list);
            }
            start = result.getStart();
        }
        while(result.getMore());
        return list;
    }
    catch(DbxException e) {
        throw new DropboxExceptionMappingService().map("Failure to read attributes of {0}", e, workdir);
    }
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:36,代码来源:DropboxSearchFeature.java

示例14: parse

import com.dropbox.core.v2.files.FileMetadata; //导入依赖的package包/类
protected Path parse(final Path directory, final Metadata metadata) {
    final EnumSet<AbstractPath.Type> type;
    if(metadata instanceof FileMetadata) {
        type = EnumSet.of(Path.Type.file);
    }
    else if(metadata instanceof FolderMetadata) {
        type = EnumSet.of(Path.Type.directory);
    }
    else {
        log.warn(String.format("Skip file %s", metadata));
        return null;
    }
    return new Path(directory, PathNormalizer.name(metadata.getName()), type, attributes.convert(metadata));
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:15,代码来源:DropboxListService.java

示例15: convert

import com.dropbox.core.v2.files.FileMetadata; //导入依赖的package包/类
protected PathAttributes convert(final Metadata metadata) {
    final PathAttributes attributes = new PathAttributes();
    if(metadata instanceof FileMetadata) {
        final FileMetadata fm = (FileMetadata) metadata;
        attributes.setSize(fm.getSize());
        attributes.setModificationDate(fm.getClientModified().getTime());
    }
    return attributes;
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:10,代码来源:DropboxAttributesFinderFeature.java


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