Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
docs(api): 添加Upload基本示例
Browse files Browse the repository at this point in the history
  • Loading branch information
xuxiaocheng0201 committed Jul 10, 2024
1 parent 87ed49d commit ddaf02c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/com/xuxiaocheng/wlist/api/core/files/Upload.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@

/**
* The core upload API.
* <p>For a basic example: <pre> {@code
* Assumptions.assumeTrue(size <= Integer.MAX_VALUE);
* final UploadConfirmation confirmation = Upload.request(client, token, root, filename, size, md5, md5s, Duplicate.Error).get();
* if (!confirmation.done()) {
* final UploadInformation information = Upload.confirm(client, token).get();
* for (int i = 0, chunksSize = information.chunks().size(); i < chunksSize; ++i) {
* final UploadChunkInformation chunk = information.chunks().get(i);
* final ByteBuffer buf = content.slice((int) chunk.start(), (int) chunk.size());
* final MessageDigest sha256 = MessageDigest.getInstance("Sha256");
* sha256.update(buf);
* final BigInteger h = new BigInteger(1, sha256.digest());
* final String hash = String.format("%64s", h.toString(16)).replace(' ', '0');
* final Optional<String> res = Upload.upload(client, token, i, buf.rewind(), new AtomicBoolean(true)).get();
* Assertions.assertEquals(Optional.of(hash), res); // handle error (retry)
* }
* }
* final FileInformation information = Basic.get(Upload.finish(client, confirmation.token()));
* }</pre>
*/
public enum Upload {;
/**
Expand Down

0 comments on commit ddaf02c

Please sign in to comment.