Skip to content
This repository was archived by the owner on Dec 6, 2024. It is now read-only.

Commit 8f49078

Browse files
SynapticloopSynapticloop
authored andcommitted
added new documentation
1 parent 980ebdb commit 8f49078

6 files changed

Lines changed: 125 additions & 17 deletions

File tree

README.md

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<img src="https://travis-ci.org/synapticloop/backblaze-b2-java-api.svg?branch=master" />
1+
[![Build Status](https://travis-ci.org/synapticloop/backblaze-b2-java-api.svg?branch=master)](https://travis-ci.org/synapticloop/backblaze-b2-java-api)
22

33
A Java API for the truly excellent backblaze B2 storage
44

@@ -22,6 +22,74 @@ b2ApiClient.uploadFile(createPrivateBucket.getBucketId(), "myfile.txt", new File
2222

2323
see [B2ApiClient.java](https://github.com/synapticloop/backblaze-b2-java-api/blob/master/src/main/java/synapticloop/b2/B2ApiClient.java) for a complete list of relatively self-explanatory methods.
2424

25+
```
26+
// create a new B2ApiClient
27+
B2ApiClient(String, String)
28+
29+
// create a bucket
30+
createBucket(String, BucketType)
31+
32+
// delete bucket
33+
deleteBucket(String)
34+
35+
// delete bucket and all containing files
36+
deleteBucketFully(String)
37+
38+
// delete a version of a file
39+
deleteFileVersion(String, String)
40+
41+
// download the full file by id, returning a variety of objects
42+
downloadFileById(String)
43+
downloadFileByIdToBytes(String)
44+
downloadFileByIdToFile(String, File)
45+
downloadFileByIdToStream(String)
46+
47+
// download the full file by name, returning a variety of objects
48+
downloadFileByName(String, String)
49+
downloadFileByNameToBytes(String, String)
50+
downloadFileByNameToFile(String, String, File)
51+
downloadFileByNameToStream(String, String)
52+
53+
// download partial content of a file by id, returning a variety of objects
54+
downloadFileRangeById(String, long, long)
55+
downloadFileRangeByIdToBytes(String, long, long)
56+
downloadFileRangeByIdToFile(String, File, long, long)
57+
downloadFileRangeByIdToStream(String, long, long)
58+
59+
// download partial content of a file by name, returning a variety of objects
60+
downloadFileRangeByName(String, String, long, long)
61+
downloadFileRangeByNameToBytes(String, String, long, long)
62+
downloadFileRangeByNameToFile(String, String, File, long, long)
63+
downloadFileRangeByNameToStream(String, String, long, long)
64+
65+
// retrieve information on a file
66+
getFileInfo(String)
67+
68+
// return the headers associated with a file
69+
headFileById(String)
70+
71+
// list all of the buckets
72+
listBuckets()
73+
74+
// list file names
75+
listFileNames(String)
76+
listFileNames(String, String, Integer)
77+
78+
// list file versions
79+
listFileVersions(String)
80+
listFileVersions(String, String)
81+
listFileVersions(String, String, String, Integer)
82+
83+
// update the bucket type (private or public)
84+
updateBucket(String, BucketType)
85+
86+
// upload a file
87+
uploadFile(String, String, File)
88+
uploadFile(String, String, File, Map<String, String>)
89+
uploadFile(String, String, File, String)
90+
uploadFile(String, String, File, String, Map<String, String>)
91+
```
92+
2593
# Dependency Management
2694

2795
> Note that the latest version can be found [https://bintray.com/synapticloop/maven/backblaze-b2-java-api/view](https://bintray.com/synapticloop/maven/backblaze-b2-java-api/view)

src/main/java/synapticloop/b2/B2ApiClient.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,17 @@ public List<B2BucketResponse> listBuckets() throws B2ApiException {
155155
return(new B2ListBucketsRequest(getB2AuthorizeAccountResponse()).getResponse());
156156
}
157157

158+
/**
159+
* List all of the buckets in the account that
160+
*
161+
* @return the list of buckets for the account
162+
*
163+
* @throws B2ApiException if something went wrong
164+
*/
165+
public List<B2BucketResponse> listBuckets(String pattern) throws B2ApiException {
166+
return(new B2ListBucketsRequest(getB2AuthorizeAccountResponse()).getResponse());
167+
}
168+
158169
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
159170
*
160171
* FILE INFORMATION API ACTIONS

src/main/java/synapticloop/b2/request/BaseB2Request.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ protected String executePost() throws B2ApiException {
208208

209209
setHeaders(httpPost);
210210

211-
LOGGER.debug("POST request to URL '{}', with data of '{}'", url, postData);
211+
LOGGER.debug("POST request to URL '{}', with data of '{}'", url, obfuscateData(postData));
212212

213213
try {
214214
httpPost.setEntity(new StringEntity(postData));
@@ -351,6 +351,17 @@ private void setHeaders(HttpRequestBase httpRequestBase) {
351351
httpRequestBase.setHeader(headerKey, unencodedHeaders.get(headerKey));
352352
}
353353
}
354+
}
354355

356+
/**
357+
* Obfuscate the data by removing the accountId and replacing it with the
358+
* string "[redacted]"
359+
*
360+
* @param data the data to obfuscate
361+
*
362+
* @return the obfuscated data
363+
*/
364+
private String obfuscateData(String data) {
365+
return(data.replaceAll("\"accountId\":\".*\"", "\"accountId\":\"[redacted]\""));
355366
}
356367
}

src/main/java/synapticloop/b2/response/B2DownloadFileResponse.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ private void parseHeaders(CloseableHttpResponse closeableHttpResponse) throws B2
125125
*
126126
* @return the downloaded file
127127
*/
128-
public InputStream getContent() {
129-
return this.content;
130-
}
128+
public InputStream getContent() { return this.content; }
131129

132130
/**
133131
* Get the content length of the downloaded file

src/main/java/synapticloop/b2/response/B2HideFileResponse.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,11 @@ public B2HideFileResponse(String string) throws B2ApiException {
2626
this.size = jsonObject.optLong(KEY_SIZE);
2727
}
2828

29-
public String getFileId() {
30-
return this.fileId;
31-
}
29+
public String getFileId() { return this.fileId; }
3230

33-
public String getFileName() {
34-
return this.fileName;
35-
}
31+
public String getFileName() { return this.fileName; }
3632

37-
public Action getAction() {
38-
return this.action;
39-
}
33+
public Action getAction() { return this.action; }
4034

41-
public long getSize() {
42-
return this.size;
43-
}
35+
public long getSize() { return this.size; }
4436
}

src/main/java/synapticloop/b2/response/B2ListFilesResponse.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ public class B2ListFilesResponse extends BaseB2Response {
1313
private String nextFileName = null;
1414
private String nextFileId = null;
1515

16+
/**
17+
* Instantiate a list files response with the JSON response as a
18+
* string from the API call. This response is then parsed into the
19+
* relevant fields.
20+
*
21+
* @param response the response (in JSON format)
22+
*
23+
* @throws B2ApiException if there was an error parsing the response
24+
*/
1625
public B2ListFilesResponse(String string) throws B2ApiException {
1726
JSONObject jsonObject = getParsedResponse(string);
1827

@@ -27,7 +36,26 @@ public B2ListFilesResponse(String string) throws B2ApiException {
2736
}
2837
}
2938

39+
/**
40+
* get the next file name that is the next result to be returned after this
41+
* result set - or null if there are no more files
42+
*
43+
* @return the next file name to start the next iteration (or null if no next file)
44+
*/
3045
public String getNextFileName() { return this.nextFileName; }
46+
47+
/**
48+
* get the next file id that is the next result to be returned after this
49+
* result set - or null if there are no more files
50+
*
51+
* @return the next file id to start the next iteration (or null if no next file id)
52+
*/
3153
public String getNextFileId() { return this.nextFileId; }
54+
55+
/**
56+
* Return the list of files include file info
57+
*
58+
* @return the list of files for this request
59+
*/
3260
public List<B2FileInfoResponse> getFiles() { return this.files; }
3361
}

0 commit comments

Comments
 (0)