@@ -44,7 +44,7 @@ public class B2ApiClient {
4444 private String accountId = null ;
4545 private String applicationKey = null ;
4646
47- B2AuthorizeAccountResponse b2AuthorizeAccountResponse = null ;
47+ private B2AuthorizeAccountResponse b2AuthorizeAccountResponse = null ;
4848
4949 /**
5050 * Instantiate a new B2ApiClient object
@@ -225,12 +225,22 @@ public B2UploadFileRequest uploadFile(String bucketId, String fileName, File fil
225225 return (new B2UploadFileRequest (getB2AuthorizeAccountResponse (), b2GetUploadUrlResponse , fileName , file ));
226226 }
227227
228+ /**
229+ * Delete a version of a file
230+ *
231+ * @param fileName The name of the file to delete
232+ * @param fileId The version of the file to delete
233+ *
234+ * @return the deleted file response
235+ *
236+ * @throws B2ApiException if there was an error deleting the file
237+ */
228238 public B2DeleteFileVersionResponse deleteFileVersion (String fileName , String fileId ) throws B2ApiException {
229239 return (new B2DeleteFileVersionRequest (getB2AuthorizeAccountResponse (), fileName , fileId ).getResponse ());
230240 }
231241
232242 /**
233- * Update a busket to be a specified type
243+ * Update a bucket to be a specified type
234244 *
235245 * @param bucketId the id of the bucket to set
236246 * @param bucketType the type of the bucket
@@ -274,14 +284,46 @@ public B2ListFilesResponse listFileNames(String bucketId, String startFileName,
274284 return (new B2ListFileNamesRequest (getB2AuthorizeAccountResponse (), bucketId , startFileName , maxFileCount ).getResponse ());
275285 }
276286
287+ /**
288+ * List the files and versions for a specific bucket
289+ *
290+ * @param bucketId the id of the bucket to list
291+ *
292+ * @return the list file response
293+ *
294+ * @throws B2ApiException if there was an error with the call
295+ */
277296 public B2ListFilesResponse listFileVersions (String bucketId ) throws B2ApiException {
278297 return (new B2ListFileVersionsRequest (getB2AuthorizeAccountResponse (), bucketId ).getResponse ());
279298 }
280299
300+ /**
301+ * List the file versions in a bucket starting at a specific file name
302+ *
303+ * @param bucketId the id of the bucket
304+ * @param startFileName the file name to start with
305+ *
306+ * @return the list file response
307+ *
308+ * @throws B2ApiException if there was an error with the call
309+ */
281310 public B2ListFilesResponse listFileVersions (String bucketId , String startFileName ) throws B2ApiException {
282311 return (new B2ListFileVersionsRequest (getB2AuthorizeAccountResponse (), bucketId , startFileName , null , null ).getResponse ());
283312 }
284313
314+ /**
315+ * List the file versions in a bucket starting at a specific file name and file id
316+ *
317+ * @param bucketId the id of the bucket
318+ * @param startFileName the file name to start with
319+ * @param startFileId the id of the file to start with
320+ * @param maxFileCount the maximum number of files to return (must be less
321+ * than or equal to 1000, else an error is thrown)
322+ *
323+ * @return the list files response
324+ *
325+ * @throws B2ApiException if there was an error with the call
326+ */
285327 public B2ListFilesResponse listFileVersions (String bucketId , String startFileName , String startFileId , Integer maxFileCount ) throws B2ApiException {
286328 return (new B2ListFileVersionsRequest (getB2AuthorizeAccountResponse (), bucketId , startFileName , startFileId , maxFileCount ).getResponse ());
287329 }
@@ -369,27 +411,83 @@ public B2DownloadFileResponse downloadFileByName(String bucketName, String fileN
369411 return (new B2DownloadFileByNameRequest (getB2AuthorizeAccountResponse (), bucketName , fileName ).getResponse ());
370412 }
371413
372- public void downloadFileByIdToFile (String bucketId , String FileId , File file ) {
414+ public void downloadFileByIdToFile (String bucketId , String fileId , File file ) throws B2ApiException {
415+ try {
416+ FileUtils .copyInputStreamToFile (new B2DownloadFileByIdRequest (getB2AuthorizeAccountResponse (), fileId ).getResponse ().getContent (), file );
417+ } catch (IOException ex ) {
418+ throw new B2ApiException ("Could not download to file" , ex );
419+ }
373420 }
374421
375- public byte [] downloadByFileIdToBytes (String bucketId , String fileId ) {
376- return (new byte [] {});
422+ /**
423+ * Download a file to a byte[]
424+ *
425+ * Note: This will not return any of the headers that accompanied the download.
426+ * See downloadFileByName to retrieve the complete response including sha1,
427+ * content length, content type and all headers.
428+ *
429+ * @param fileId the id of the file to download
430+ *
431+ * @return the array of bytes for the file
432+ *
433+ * @throws B2ApiException if there was an error with the call
434+ */
435+ public byte [] downloadByFileIdToBytes (String fileId ) throws B2ApiException {
436+ try {
437+ return (IOUtils .toByteArray (new B2DownloadFileByIdRequest (getB2AuthorizeAccountResponse (), fileId ).getResponse ().getContent ()));
438+ } catch (IOException ex ) {
439+ throw new B2ApiException ("Could not download to bytes" , ex );
440+ }
377441 }
378442
443+ /**
444+ * Download a file to an input stream
445+ *
446+ * Note: This will not return any of the headers that accompanied the download.
447+ * See downloadFileByName to retrieve the complete response including sha1,
448+ * content length, content type and all headers.
449+ *
450+ * @param fileId the id of the file to download
451+ *
452+ * @return the input stream for the file
453+ *
454+ * @throws B2ApiException if there was an error with the call
455+ */
379456 public InputStream downloadFileByIdToStream (String fileId ) throws B2ApiException {
380457 return (new B2DownloadFileByIdRequest (getB2AuthorizeAccountResponse (), fileId ).getResponse ().getContent ());
381458 }
382459
460+ /**
461+ * Download a file
462+ *
463+ * @param fileId the id of the file to download
464+ *
465+ * @return the download file response
466+ *
467+ * @throws B2ApiException if there was an error with the call
468+ */
383469 public B2DownloadFileResponse downloadFileById (String fileId ) throws B2ApiException {
384470 return (new B2DownloadFileByIdRequest (getB2AuthorizeAccountResponse (), fileId ).getResponse ());
385471 }
386472
473+ /**
474+ * Perform a HEAD request on a file which will return the information
475+ * associated with it.
476+ *
477+ * @param fileId the id of the file to retrieve the information for
478+ *
479+ * @return the download file response
480+ *
481+ * @throws B2ApiException if there was an error with the call
482+ */
483+
387484 public B2DownloadFileResponse headFileById (String fileId ) throws B2ApiException {
388485 return (new B2HeadFileByIdRequest (getB2AuthorizeAccountResponse (), fileId ).getResponse ());
389486 }
390487
391488 /**
392- * Return an authorize account response and cache it, or create a new one
489+ * return the authorize account response. This is only done once and is
490+ * cached for further use.
393491 *
394492 * @return the authorize account response
395493 * @throws B2ApiException if there was an error authenticating
0 commit comments