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

Commit eafdf9e

Browse files
committed
Add new request parameters prefix and delimiter.
1 parent ee2dafb commit eafdf9e

5 files changed

Lines changed: 241 additions & 227 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ public B2ListFilesResponse listFileNames(String bucketId) throws B2ApiException,
676676
* @throws IOException if there was an error communicating with the API service
677677
*/
678678
public B2ListFilesResponse listFileNames(String bucketId, String startFileName, Integer maxFileCount) throws B2ApiException, IOException {
679-
return new B2ListFileNamesRequest(client, b2AuthorizeAccountResponse, bucketId, startFileName, maxFileCount).getResponse();
679+
return new B2ListFileNamesRequest(client, b2AuthorizeAccountResponse, bucketId, startFileName, maxFileCount, null, null).getResponse();
680680
}
681681

682682
/**
@@ -705,7 +705,7 @@ public B2ListFilesResponse listFileVersions(String bucketId) throws B2ApiExcepti
705705
* @throws IOException if there was an error communicating with the API service
706706
*/
707707
public B2ListFilesResponse listFileVersions(String bucketId, String startFileName) throws B2ApiException, IOException {
708-
return new B2ListFileVersionsRequest(client, b2AuthorizeAccountResponse, bucketId, null, startFileName, null).getResponse();
708+
return new B2ListFileVersionsRequest(client, b2AuthorizeAccountResponse, bucketId, null, startFileName, null, null, null).getResponse();
709709
}
710710

711711
/**
@@ -723,7 +723,7 @@ public B2ListFilesResponse listFileVersions(String bucketId, String startFileNam
723723
* @throws IOException if there was an error communicating with the API service
724724
*/
725725
public B2ListFilesResponse listFileVersions(String bucketId, String startFileName, String startFileId, Integer maxFileCount) throws B2ApiException, IOException {
726-
return new B2ListFileVersionsRequest(client, b2AuthorizeAccountResponse, bucketId, maxFileCount, startFileName, startFileId).getResponse();
726+
return new B2ListFileVersionsRequest(client, b2AuthorizeAccountResponse, bucketId, maxFileCount, startFileName, startFileId, null, null).getResponse();
727727
}
728728

729729
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

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

Lines changed: 70 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -16,92 +16,98 @@
1616
* this source code or binaries.
1717
*/
1818

19-
import java.io.IOException;
20-
2119
import org.apache.http.impl.client.CloseableHttpClient;
2220
import org.apache.http.util.EntityUtils;
2321

22+
import java.io.IOException;
23+
2424
import synapticloop.b2.exception.B2ApiException;
2525
import synapticloop.b2.response.B2AuthorizeAccountResponse;
2626
import synapticloop.b2.response.B2ListFilesResponse;
2727

2828
/**
2929
* <p>Lists the names of all files in a bucket, starting at a given name.</p>
30-
*
30+
* <p>
3131
* <p>This call returns at most 1000 file names, but it can be called repeatedly to scan through all of the file names in a bucket. Each time you call, it returns an "endFileName" that can be used as the starting point for the next call.</p>
3232
* <p>There may be many file versions for the same name, but this call will return each name only once. If you want all of the versions, use b2_list_file_versions instead.</p>
33-
*
34-
*
35-
* This is the interaction class for the <strong>b2_list_file_names</strong> api calls, this was
33+
* <p>
34+
* <p>
35+
* This is the interaction class for the <strong>b2_list_file_names</strong> api calls, this was
3636
* generated from the backblaze api documentation - which can be found here:
37-
*
37+
* <p>
3838
* <a href="http://www.backblaze.com/b2/docs/b2_list_file_names.html">http://www.backblaze.com/b2/docs/b2_list_file_names.html</a>
39-
*
39+
*
4040
* @author synapticloop
4141
*/
4242
public class B2ListFileNamesRequest extends BaseB2Request {
43-
private static final String B2_LIST_FILE_NAMES = BASE_API_VERSION + "b2_list_file_versions";
43+
private static final String B2_LIST_FILE_NAMES = BASE_API_VERSION + "b2_list_file_versions";
4444

45-
private static final int DEFAULT_MAX_FILE_COUNT = 100;
45+
private static final int DEFAULT_MAX_FILE_COUNT = 100;
4646

47-
/**
48-
* Create a list file names request, this will return at most the default
49-
* number of files, which is 100.
50-
*
51-
* @param client the HTTP client to use
52-
* @param b2AuthorizeAccountResponse the authorize account response
53-
* @param bucketId the id of the bucket to list
54-
*/
55-
public B2ListFileNamesRequest(CloseableHttpClient client, B2AuthorizeAccountResponse b2AuthorizeAccountResponse, String bucketId) {
56-
this(client, b2AuthorizeAccountResponse, bucketId, null, DEFAULT_MAX_FILE_COUNT);
57-
}
47+
/**
48+
* Create a list file names request, this will return at most the default
49+
* number of files, which is 100.
50+
*
51+
* @param client the HTTP client to use
52+
* @param b2AuthorizeAccountResponse the authorize account response
53+
* @param bucketId the id of the bucket to list
54+
*/
55+
public B2ListFileNamesRequest(CloseableHttpClient client, B2AuthorizeAccountResponse b2AuthorizeAccountResponse, String bucketId) {
56+
this(client, b2AuthorizeAccountResponse, bucketId, null, DEFAULT_MAX_FILE_COUNT, null, null);
57+
}
5858

59-
/**
60-
* Create a list file names request returning up to the maxFileCount number of results
61-
*
62-
* @param client the HTTP client to use
63-
* @param b2AuthorizeAccountResponse the authorize account response
64-
* @param bucketId the id of the bucket to list
65-
* @param maxFileCount The maximum number of files to return from this call.
66-
* The default value is 100, and the maximum allowed is 1000.
67-
*/
68-
public B2ListFileNamesRequest(CloseableHttpClient client, B2AuthorizeAccountResponse b2AuthorizeAccountResponse, String bucketId, Integer maxFileCount) {
69-
this(client, b2AuthorizeAccountResponse, bucketId, null, maxFileCount);
70-
}
59+
/**
60+
* Create a list file names request returning up to the maxFileCount number of results
61+
*
62+
* @param client the HTTP client to use
63+
* @param b2AuthorizeAccountResponse the authorize account response
64+
* @param bucketId the id of the bucket to list
65+
* @param maxFileCount The maximum number of files to return from this call.
66+
* The default value is 100, and the maximum allowed is 1000.
67+
*/
68+
public B2ListFileNamesRequest(CloseableHttpClient client, B2AuthorizeAccountResponse b2AuthorizeAccountResponse, String bucketId, Integer maxFileCount) {
69+
this(client, b2AuthorizeAccountResponse, bucketId, null, maxFileCount, null, null);
70+
}
7171

72-
/**
73-
* Create a list file names request returning up to the maxFileCount number of results
74-
*
75-
* @param client the HTTP client to use
76-
* @param b2AuthorizeAccountResponse the authorize account response
77-
* @param bucketId the id of the bucket to list
78-
* @param startFileName The first file name to return. If there is a file
79-
* with this name, it will be returned in the list. If not, the first
80-
* file name after this the first one after this name.
81-
* @param maxFileCount The maximum number of files to return from this call.
82-
* The default value is 100, and the maximum allowed is 1000.
83-
*/
84-
public B2ListFileNamesRequest(CloseableHttpClient client, B2AuthorizeAccountResponse b2AuthorizeAccountResponse, String bucketId, String startFileName, Integer maxFileCount) {
85-
super(client, b2AuthorizeAccountResponse, b2AuthorizeAccountResponse.getApiUrl() + B2_LIST_FILE_NAMES);
72+
/**
73+
* Create a list file names request returning up to the maxFileCount number of results
74+
*
75+
* @param client the HTTP client to use
76+
* @param b2AuthorizeAccountResponse the authorize account response
77+
* @param bucketId the id of the bucket to list
78+
* @param startFileName The first file name to return. If there is a file
79+
* with this name, it will be returned in the list. If not, the first
80+
* file name after this the first one after this name.
81+
* @param maxFileCount The maximum number of files to return from this call.
82+
* @param prefix Files returned will be limited to those with the given prefix. Defaults to the empty string, which matches all files.
83+
* @param delimiter Files returned will be limited to those within the top folder, or any one subfolder. Defaults to NULL. Folder names will also be returned. The delimiter character will be used to "break" file names into folders.
84+
*/
85+
public B2ListFileNamesRequest(CloseableHttpClient client, B2AuthorizeAccountResponse b2AuthorizeAccountResponse, String bucketId, String startFileName, Integer maxFileCount, String prefix, String delimiter) {
86+
super(client, b2AuthorizeAccountResponse, b2AuthorizeAccountResponse.getApiUrl() + B2_LIST_FILE_NAMES);
8687

87-
this.addProperty(B2RequestProperties.KEY_BUCKET_ID, bucketId);
88+
this.addProperty(B2RequestProperties.KEY_BUCKET_ID, bucketId);
8889

89-
if(null != startFileName) {
90-
this.addProperty(B2RequestProperties.KEY_START_FILE_NAME, startFileName);
91-
}
90+
if(null != startFileName) {
91+
this.addProperty(B2RequestProperties.KEY_START_FILE_NAME, startFileName);
92+
}
93+
if(null != prefix) {
94+
this.addProperty(B2RequestProperties.KEY_PREFIX, prefix);
95+
}
96+
if(null != delimiter) {
97+
this.addProperty(B2RequestProperties.KEY_DELIMITER, delimiter);
98+
}
9299

93-
this.addProperty(B2RequestProperties.KEY_MAX_FILE_COUNT, maxFileCount);
94-
}
100+
this.addProperty(B2RequestProperties.KEY_MAX_FILE_COUNT, maxFileCount);
101+
}
95102

96-
/**
97-
* Return the list file names response
98-
*
99-
* @return the list file names response
100-
*
101-
* @throws B2ApiException if something went wrong
102-
* @throws IOException if there was an error communicating with the API service
103-
*/
104-
public B2ListFilesResponse getResponse() throws B2ApiException, IOException {
105-
return new B2ListFilesResponse(EntityUtils.toString(executePost().getEntity()));
106-
}
103+
/**
104+
* Return the list file names response
105+
*
106+
* @return the list file names response
107+
* @throws B2ApiException if something went wrong
108+
* @throws IOException if there was an error communicating with the API service
109+
*/
110+
public B2ListFilesResponse getResponse() throws B2ApiException, IOException {
111+
return new B2ListFilesResponse(EntityUtils.toString(executePost().getEntity()));
112+
}
107113
}

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

Lines changed: 81 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -16,100 +16,106 @@
1616
* this source code or binaries.
1717
*/
1818

19-
import java.io.IOException;
20-
2119
import org.apache.http.impl.client.CloseableHttpClient;
2220
import org.apache.http.util.EntityUtils;
2321

22+
import java.io.IOException;
23+
2424
import synapticloop.b2.exception.B2ApiException;
2525
import synapticloop.b2.response.B2AuthorizeAccountResponse;
2626
import synapticloop.b2.response.B2ListFilesResponse;
2727

2828
/**
29-
* <p>Lists all of the versions of all of the files contained in one bucket, in
30-
* alphabetical order by file name, and by reverse of date/time uploaded for
29+
* <p>Lists all of the versions of all of the files contained in one bucket, in
30+
* alphabetical order by file name, and by reverse of date/time uploaded for
3131
* versions of files with the same name.</p>
32-
*
32+
* <p>
3333
* This is the interaction class for the <strong>b2_list_file_versions</strong> api calls, this was
3434
* generated from the backblaze api documentation - which can be found here:
35-
*
35+
* <p>
3636
* <a href="http://www.backblaze.com/b2/docs/b2_list_file_versions.html">http://www.backblaze.com/b2/docs/b2_list_file_versions.html</a>
37-
*
37+
*
3838
* @author synapticloop
3939
*/
4040
public class B2ListFileVersionsRequest extends BaseB2Request {
41-
private static final String B2_LIST_FILE_VERSIONS = BASE_API_VERSION + "b2_list_file_versions";
41+
private static final String B2_LIST_FILE_VERSIONS = BASE_API_VERSION + "b2_list_file_versions";
4242

43-
private static final int DEFAULT_MAX_FILE_COUNT = 100;
43+
private static final int DEFAULT_MAX_FILE_COUNT = 100;
4444

45-
/**
46-
* Create a list files request
47-
*
48-
*
49-
* @param client The HTTP client to use
50-
* @param b2AuthorizeAccountResponse the authorize account response
51-
* @param bucketId The id of the bucket to look for file names in.
52-
*/
53-
public B2ListFileVersionsRequest(CloseableHttpClient client, B2AuthorizeAccountResponse b2AuthorizeAccountResponse,
54-
String bucketId) {
55-
this(client, b2AuthorizeAccountResponse, bucketId, DEFAULT_MAX_FILE_COUNT);
56-
}
45+
/**
46+
* Create a list files request
47+
*
48+
* @param client The HTTP client to use
49+
* @param b2AuthorizeAccountResponse the authorize account response
50+
* @param bucketId The id of the bucket to look for file names in.
51+
*/
52+
public B2ListFileVersionsRequest(CloseableHttpClient client, B2AuthorizeAccountResponse b2AuthorizeAccountResponse,
53+
String bucketId) {
54+
this(client, b2AuthorizeAccountResponse, bucketId, DEFAULT_MAX_FILE_COUNT);
55+
}
5756

58-
/**
59-
* Create a list files request
60-
*
61-
* @param client The HTTP client to use
62-
* @param b2AuthorizeAccountResponse the authorize account response
63-
* @param bucketId The id of the bucket to look for file names in.
64-
* @param maxFileCount The maximum number of files to return from this call.
65-
* The default value is 100, and the maximum allowed is 1000.
66-
*/
67-
public B2ListFileVersionsRequest(CloseableHttpClient client, B2AuthorizeAccountResponse b2AuthorizeAccountResponse,
68-
String bucketId, Integer maxFileCount) {
69-
this(client, b2AuthorizeAccountResponse, bucketId, maxFileCount, null, null);
70-
}
57+
/**
58+
* Create a list files request
59+
*
60+
* @param client The HTTP client to use
61+
* @param b2AuthorizeAccountResponse the authorize account response
62+
* @param bucketId The id of the bucket to look for file names in.
63+
* @param maxFileCount The maximum number of files to return from this call.
64+
* The default value is 100, and the maximum allowed is 1000.
65+
*/
66+
public B2ListFileVersionsRequest(CloseableHttpClient client, B2AuthorizeAccountResponse b2AuthorizeAccountResponse,
67+
String bucketId, Integer maxFileCount) {
68+
this(client, b2AuthorizeAccountResponse, bucketId, maxFileCount, null, null, null, null);
69+
}
7170

72-
/**
73-
* Create a list files request
74-
*
75-
* @param client The HTTP client to use
76-
* @param b2AuthorizeAccountResponse the authorize account response
77-
* @param bucketId The id of the bucket to look for file names in.
78-
* @param maxFileCount The maximum number of files to return from this call.
79-
* The default value is 100, and the maximum allowed is 1000.
80-
* @param startFileName The first file name to return. If there are no files
81-
* with this name, the first version of the file with the first name after
82-
* the given name will be the first in the list. If startFileId is also
83-
* specified, the name-and-id pair is the starting point. If there is a
84-
* file with the given name and ID, it will be first in the list.
85-
* Otherwise, the first file version that comes after the given name and
86-
* ID will be first in the list.
87-
* @param startFileId The first file ID to return. startFileName must also
88-
* be provided if startFileId is specified. (See startFileName.)
89-
*/
90-
public B2ListFileVersionsRequest(CloseableHttpClient client, B2AuthorizeAccountResponse b2AuthorizeAccountResponse,
91-
String bucketId, Integer maxFileCount, String startFileName, String startFileId) {
92-
super(client, b2AuthorizeAccountResponse, b2AuthorizeAccountResponse.getApiUrl() + B2_LIST_FILE_VERSIONS);
71+
/**
72+
* Create a list files request
73+
*
74+
* @param client The HTTP client to use
75+
* @param b2AuthorizeAccountResponse the authorize account response
76+
* @param bucketId The id of the bucket to look for file names in.
77+
* @param maxFileCount The maximum number of files to return from this call.
78+
* The default value is 100, and the maximum allowed is 1000.
79+
* @param startFileName The first file name to return. If there are no files
80+
* with this name, the first version of the file with the first name after
81+
* the given name will be the first in the list. If startFileId is also
82+
* specified, the name-and-id pair is the starting point. If there is a
83+
* file with the given name and ID, it will be first in the list.
84+
* Otherwise, the first file version that comes after the given name and
85+
* ID will be first in the list.
86+
* @param startFileId The first file ID to return. startFileName must also
87+
* @param prefix Files returned will be limited to those with the given prefix. Defaults to the empty string, which matches all files.
88+
* @param delimiter Files returned will be limited to those within the top folder, or any one subfolder. Defaults to NULL. Folder names will also be returned. The delimiter character will be used to "break" file names into folders.
89+
*/
90+
public B2ListFileVersionsRequest(CloseableHttpClient client, B2AuthorizeAccountResponse b2AuthorizeAccountResponse,
91+
String bucketId, Integer maxFileCount, String startFileName, String startFileId,
92+
String prefix, String delimiter) {
93+
super(client, b2AuthorizeAccountResponse, b2AuthorizeAccountResponse.getApiUrl() + B2_LIST_FILE_VERSIONS);
9394

94-
this.addProperty(B2RequestProperties.KEY_BUCKET_ID, bucketId);
95-
this.addProperty(B2RequestProperties.KEY_MAX_FILE_COUNT, maxFileCount);
96-
if(null != startFileName) {
97-
this.addProperty(B2RequestProperties.KEY_START_FILE_NAME, startFileName);
98-
}
99-
if(null != startFileId) {
100-
this.addProperty(B2RequestProperties.KEY_START_FILE_ID, startFileId);
101-
}
102-
}
95+
this.addProperty(B2RequestProperties.KEY_BUCKET_ID, bucketId);
96+
this.addProperty(B2RequestProperties.KEY_MAX_FILE_COUNT, maxFileCount);
97+
if(null != startFileName) {
98+
this.addProperty(B2RequestProperties.KEY_START_FILE_NAME, startFileName);
99+
}
100+
if(null != startFileId) {
101+
this.addProperty(B2RequestProperties.KEY_START_FILE_ID, startFileId);
102+
}
103+
if(null != prefix) {
104+
this.addProperty(B2RequestProperties.KEY_PREFIX, prefix);
105+
}
106+
if(null != delimiter) {
107+
this.addProperty(B2RequestProperties.KEY_DELIMITER, delimiter);
108+
}
109+
}
103110

104-
/**
105-
* Return the list file versions response
106-
*
107-
* @return the list file versions response
108-
*
109-
* @throws B2ApiException if something went wrong
110-
* @throws IOException if there was an error communicating with the API service
111-
*/
112-
public B2ListFilesResponse getResponse() throws B2ApiException, IOException {
113-
return new B2ListFilesResponse(EntityUtils.toString(executePost().getEntity()));
114-
}
111+
/**
112+
* Return the list file versions response
113+
*
114+
* @return the list file versions response
115+
* @throws B2ApiException if something went wrong
116+
* @throws IOException if there was an error communicating with the API service
117+
*/
118+
public B2ListFilesResponse getResponse() throws B2ApiException, IOException {
119+
return new B2ListFilesResponse(EntityUtils.toString(executePost().getEntity()));
120+
}
115121
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public final class B2RequestProperties {
3030
public static final String KEY_PART_SHA1_ARRAY = "partSha1Array";
3131
public static final String KEY_START_PART_NUMBER = "startPartNumber";
3232
public static final String KEY_MAX_PART_COUNT = "maxPartCount";
33+
public static final String KEY_PREFIX = "prefix";
34+
public static final String KEY_DELIMITER = "delimiter";
3335
public static final String REQUEST_PROPERTY_CONTENT_TYPE = "Content-Type";
3436
public static final String REQUEST_PROPERTY_AUTHORIZATION = "Authorization";
3537
}

0 commit comments

Comments
 (0)