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

Commit 3fa604b

Browse files
author
synapticloop
committed
added in missing fields that weren't being picked up
1 parent 6e7e455 commit 3fa604b

File tree

8 files changed

+99
-27
lines changed

8 files changed

+99
-27
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,9 @@ repositories {
480480

481481
```
482482
dependencies {
483-
runtime(group: 'synapticloop', name: 'backblaze-b2-java-api', version: '2.1.1', ext: 'jar')
483+
runtime(group: 'synapticloop', name: 'backblaze-b2-java-api', version: '2.1.2', ext: 'jar')
484484
485-
compile(group: 'synapticloop', name: 'backblaze-b2-java-api', version: '2.1.1', ext: 'jar')
485+
compile(group: 'synapticloop', name: 'backblaze-b2-java-api', version: '2.1.2', ext: 'jar')
486486
}
487487
```
488488

@@ -494,9 +494,9 @@ or, more simply for versions of gradle greater than 2.1
494494

495495
```
496496
dependencies {
497-
runtime 'synapticloop:backblaze-b2-java-api:2.1.1'
497+
runtime 'synapticloop:backblaze-b2-java-api:2.1.2'
498498
499-
compile 'synapticloop:backblaze-b2-java-api:2.1.1'
499+
compile 'synapticloop:backblaze-b2-java-api:2.1.2'
500500
}
501501
```
502502

@@ -514,7 +514,7 @@ dependencies {
514514
<dependency>
515515
<groupId>synapticloop</groupId>
516516
<artifactId>backblaze-b2-java-api</artifactId>
517-
<version>2.1.1</version>
517+
<version>2.1.2</version>
518518
<type>jar</type>
519519
</dependency>
520520
```

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ group = 'synapticloop'
1414
archivesBaseName = 'backblaze-b2-java-api'
1515
description = """A java api for the truly excellent backblaze b2 storage service"""
1616

17-
version = '2.1.1'
17+
version = '2.1.2'
1818

1919
sourceCompatibility = 1.7
2020
targetCompatibility = 1.7

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package synapticloop.b2.request;
22

3-
import static org.apache.http.entity.ContentType.*;
4-
53
/*
64
* Copyright (c) 2016 Synapticloop.
75
*
@@ -18,6 +16,8 @@
1816
* this source code or binaries.
1917
*/
2018

19+
import static org.apache.http.entity.ContentType.*;
20+
2121
import java.io.IOException;
2222
import java.net.URI;
2323
import java.net.URISyntaxException;
@@ -46,8 +46,6 @@
4646
import synapticloop.b2.exception.B2ApiException;
4747
import synapticloop.b2.response.B2AuthorizeAccountResponse;
4848

49-
import static org.apache.http.entity.ContentType.APPLICATION_JSON;
50-
5149
public abstract class BaseB2Request {
5250
private static final Logger LOGGER = LoggerFactory.getLogger(BaseB2Request.class);
5351

@@ -353,7 +351,7 @@ protected CloseableHttpResponse execute(final HttpUriRequest request) throws IOE
353351
*/
354352
private Object obfuscateData(String key, Object data) {
355353
if(LOGGER.isDebugEnabled()) {
356-
if("accountId".equals(key)) {
354+
if(B2RequestProperties.KEY_ACCOUNT_ID.equals(key)) {
357355
return("[redacted]");
358356
}
359357
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class B2DownloadFileResponse {
6666
private final String contentSha1;
6767
private final String uploadTimestamp;
6868

69-
private final Map<String, String> fileInfo = new HashMap<>();
69+
private final Map<String, String> fileInfo = new HashMap<String, String>();
7070

7171
/**
7272
* Instantiate a bucket response with the JSON response as a string from

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

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public class B2FileInfoResponse extends BaseB2Response {
3333
private final String contentType;
3434
private final String contentSha1;
3535
private final Long contentLength;
36+
private final String accountId;
37+
private final String bucketId;
3638

3739
private final Map<String, String> fileInfo;
3840
private Action action;
@@ -68,6 +70,8 @@ public B2FileInfoResponse(final JSONObject response) throws B2ApiException {
6870

6971
this.size = this.readLong(B2ResponseProperties.KEY_SIZE);
7072
this.uploadTimestamp = this.readLong(B2ResponseProperties.KEY_UPLOAD_TIMESTAMP);
73+
this.accountId = this.readString(B2ResponseProperties.KEY_ACCOUNT_ID);
74+
this.bucketId = this.readString(B2ResponseProperties.KEY_BUCKET_ID);
7175

7276
this.warnOnMissedKeys();
7377
}
@@ -105,14 +109,14 @@ public B2FileInfoResponse(final JSONObject response) throws B2ApiException {
105109
* @return the sha1 has of the content
106110
*/
107111
public String getContentSha1() { return this.contentSha1; }
108-
112+
109113
/**
110114
* Get the file info for the downloaded file - which is a map of key value
111115
* pairs with both the key and value being strings
112116
*
113117
* @return the file info map of key:value strings
114118
*/
115-
119+
116120
public Map<String, String> getFileInfo() { return this.fileInfo; }
117121

118122
/**
@@ -134,21 +138,37 @@ public B2FileInfoResponse(final JSONObject response) throws B2ApiException {
134138
*/
135139
public Long getUploadTimestamp() { return this.uploadTimestamp; }
136140

141+
/**
142+
* Return the account ID used to authorize this account
143+
*
144+
* @return the account ID
145+
*/
146+
public String getAccountId() { return this.accountId; }
147+
148+
/**
149+
* Return the bucket ID that this file belongs in
150+
*
151+
* @return the bucket ID
152+
*/
153+
public String getBucketId() { return this.bucketId; }
154+
137155
@Override
138156
protected Logger getLogger() { return LOGGER; }
139157

140158
@Override
141159
public String toString() {
142-
final StringBuilder sb = new StringBuilder("B2FileInfoResponse{");
143-
sb.append("fileId='").append(fileId).append('\'');
144-
sb.append(", fileName='").append(fileName).append('\'');
145-
sb.append(", contentLength=").append(contentLength);
146-
sb.append(", contentType=").append(contentType);
147-
sb.append(", contentSha1='").append(contentSha1).append('\'');
148-
sb.append(", fileInfo=").append(fileInfo);
149-
sb.append(", size=").append(size);
150-
sb.append(", uploadTimestamp=").append(uploadTimestamp);
151-
sb.append('}');
152-
return sb.toString();
160+
return "B2FileInfoResponse " +
161+
"[fileId=" + this.fileId +
162+
", fileName=" + this.fileName +
163+
", contentType=" + this.contentType +
164+
", contentSha1=" + this.contentSha1 +
165+
", contentLength=" + this.contentLength +
166+
", accountId=" + this.accountId +
167+
", bucketId=" + this.bucketId +
168+
", fileInfo=" + this.fileInfo +
169+
", action=" + this.action +
170+
", size=" + this.size +
171+
", uploadTimestamp=" + this.uploadTimestamp +
172+
"]";
153173
}
154174
}

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package synapticloop.b2.response;
22

3+
import java.util.Map;
4+
35
/*
46
* Copyright (c) 2016 Synapticloop.
57
*
@@ -31,7 +33,12 @@ public class B2HideFileResponse extends BaseB2Response {
3133
private final Integer size;
3234
private final Long uploadTimestamp;
3335

34-
/**
36+
private final Long contentLength;
37+
private final String contentType;
38+
private final String contentSha1;
39+
private final Map<String, String> fileInfo;
40+
41+
/**
3542
* Instantiate a hide file response with the JSON response as a string from
3643
* the API call. This response is then parsed into the relevant fields.
3744
*
@@ -60,6 +67,10 @@ public B2HideFileResponse(String json) throws B2ApiException {
6067

6168
this.size = this.readInt(B2ResponseProperties.KEY_SIZE);
6269
this.uploadTimestamp = this.readLong(B2ResponseProperties.KEY_UPLOAD_TIMESTAMP);
70+
this.contentLength = this.readLong(B2ResponseProperties.KEY_CONTENT_LENGTH);
71+
this.contentType =this.readString(B2ResponseProperties.KEY_CONTENT_TYPE);
72+
this.contentSha1 =this.readString(B2ResponseProperties.KEY_CONTENT_SHA1);
73+
this.fileInfo = this.readMap(B2ResponseProperties.KEY_FILE_INFO);
6374

6475
this.warnOnMissedKeys();
6576
}
@@ -88,4 +99,33 @@ public String toString() {
8899
return sb.toString();
89100
}
90101

102+
/**
103+
* Get the content length of the downloaded file
104+
*
105+
* @return the length of the content
106+
*/
107+
public Long getContentLength() { return this.contentLength; }
108+
109+
/**
110+
* Get the content type of the downloaded file
111+
*
112+
* @return the content type of the downloaded file
113+
*/
114+
public String getContentType() { return this.contentType; }
115+
116+
/**
117+
* Get the SHA1 of the returned content
118+
*
119+
* @return the SHA1 of the returned content
120+
*/
121+
public String getContentSha1() { return this.contentSha1; }
122+
123+
/**
124+
* Get the file info for the file, this will be returned in the map as
125+
* key(tag), value (super-secret-tag)
126+
*
127+
* @return The map of the file info
128+
*/
129+
public Map<String, String> getFileInfo() { return this.fileInfo; }
130+
91131
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public class B2StartLargeFileResponse extends BaseB2Response {
3232
private final String accountId;
3333
private final String bucketId;
3434
private final String contentType;
35+
private final String uploadTimestamp;
36+
3537
private final Map<String, String> fileInfo;
3638

3739
public B2StartLargeFileResponse(String json) throws B2ApiException {
@@ -43,6 +45,7 @@ public B2StartLargeFileResponse(String json) throws B2ApiException {
4345
this.bucketId = this.readString(B2ResponseProperties.KEY_BUCKET_ID);
4446
this.contentType = this.readString(B2ResponseProperties.KEY_CONTENT_TYPE);
4547
this.fileInfo = this.readMap(B2ResponseProperties.KEY_FILE_INFO);
48+
this.uploadTimestamp = this.readString(B2ResponseProperties.KEY_UPLOAD_TIMESTAMP);
4649

4750
this.warnOnMissedKeys();
4851
}
@@ -57,6 +60,13 @@ public B2StartLargeFileResponse(String json) throws B2ApiException {
5760

5861
public String getContentType() { return this.contentType; }
5962

63+
/**
64+
* Get the upload timestamp of the file
65+
*
66+
* @return the upload timestamp of the file
67+
*/
68+
public String getUploadTimestamp() { return this.uploadTimestamp; }
69+
6070
public Map<String, String> getFileInfo() { return this.fileInfo; }
6171

6272
@Override

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,11 @@ protected void warnOnMissedKeys() {
213213
Iterator keys = response.keys();
214214
while (keys.hasNext()) {
215215
String key = (String) keys.next();
216-
getLogger().warn("Found an unexpected key of '{}' in JSON that is not mapped to a field, with value '{}'.", key, response.get(key));
216+
if(B2ResponseProperties.KEY_ACCOUNT_ID.equals(key)) {
217+
getLogger().warn("Found an unexpected key of '{}' in JSON that is not mapped to a field, with value '{}'.", key, "[redacted]");
218+
} else {
219+
getLogger().warn("Found an unexpected key of '{}' in JSON that is not mapped to a field, with value '{}'.", key, response.get(key));
220+
}
217221
}
218222
}
219223
}

0 commit comments

Comments
 (0)