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

Commit 03e500a

Browse files
author
synapticloop
committed
Merge branch 'iterate-ch-feature/b2-prefix-delimiter'
2 parents ee2dafb + 8e0ce77 commit 03e500a

File tree

5 files changed

+278
-227
lines changed

5 files changed

+278
-227
lines changed

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

+40-3
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,25 @@ 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();
680+
}
681+
682+
/**
683+
* Return a list of all of the files within a bucket with the specified ID,
684+
* by default a maximum of 100 files are returned with this request.
685+
*
686+
* @param bucketId the id of the bucket to list
687+
* @param startFileName the start file name, or if null, this will be the first file
688+
* @param maxFileCount (optional) if null, the default is 100, the maximum number to be returned is 1000
689+
* @param prefix Files returned will be limited to those with the given prefix. Defaults to the empty string, which matches all files.
690+
* @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.
691+
* @return the list of files response
692+
*
693+
* @throws B2ApiException if there was an error with the call,
694+
* @throws IOException if there was an error communicating with the API service
695+
*/
696+
public B2ListFilesResponse listFileNames(String bucketId, String startFileName, Integer maxFileCount, String prefix, String delimiter) throws B2ApiException, IOException {
697+
return new B2ListFileNamesRequest(client, b2AuthorizeAccountResponse, bucketId, startFileName, maxFileCount, prefix, delimiter).getResponse();
680698
}
681699

682700
/**
@@ -705,7 +723,7 @@ public B2ListFilesResponse listFileVersions(String bucketId) throws B2ApiExcepti
705723
* @throws IOException if there was an error communicating with the API service
706724
*/
707725
public B2ListFilesResponse listFileVersions(String bucketId, String startFileName) throws B2ApiException, IOException {
708-
return new B2ListFileVersionsRequest(client, b2AuthorizeAccountResponse, bucketId, null, startFileName, null).getResponse();
726+
return new B2ListFileVersionsRequest(client, b2AuthorizeAccountResponse, bucketId, null, startFileName, null, null, null).getResponse();
709727
}
710728

711729
/**
@@ -723,7 +741,26 @@ public B2ListFilesResponse listFileVersions(String bucketId, String startFileNam
723741
* @throws IOException if there was an error communicating with the API service
724742
*/
725743
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();
744+
return new B2ListFileVersionsRequest(client, b2AuthorizeAccountResponse, bucketId, maxFileCount, startFileName, startFileId, null, null).getResponse();
745+
}
746+
747+
/**
748+
* List the file versions in a bucket starting at a specific file name and file id
749+
*
750+
* @param bucketId the id of the bucket
751+
* @param startFileName the file name to start with
752+
* @param startFileId the id of the file to start with
753+
* @param maxFileCount the maximum number of files to return (must be less than or equal to 1000, else an error is thrown)
754+
* @param prefix Files returned will be limited to those with the given prefix. Defaults to the empty string, which matches all files.
755+
* @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.
756+
*
757+
* @return the list files response
758+
*
759+
* @throws B2ApiException if there was an error with the call
760+
* @throws IOException if there was an error communicating with the API service
761+
*/
762+
public B2ListFilesResponse listFileVersions(String bucketId, String startFileName, String startFileId, Integer maxFileCount, String prefix, String delimiter) throws B2ApiException, IOException {
763+
return new B2ListFileVersionsRequest(client, b2AuthorizeAccountResponse, bucketId, maxFileCount, startFileName, startFileId, prefix, delimiter).getResponse();
727764
}
728765

729766
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

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

+70-64
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
}

0 commit comments

Comments
 (0)