Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overload method void uploadFile(String doi, File file); to void uploadFile(String doi, InputStream is); #12

Closed
AleixMT opened this issue Nov 10, 2022 · 2 comments

Comments

@AleixMT
Copy link
Contributor

AleixMT commented Nov 10, 2022

The interface Interface DatasetOperations defines the specification for the method void uploadFile(String doi, File file); which as far as my Java knowledge goes (please correct me if there is a workaround for this and I am wrong) it forces the developer to have an instance of File, which has to be on the disk.

In my case, I am retrieving the file data from the database so I do not have a file, instead I have an InputStream / Byte array (preferably an InputStream for memory optimization).

In order to use the method void uploadFile(String doi, File file); from class DatasetOperationsImplV1, I would need to write the InputStream from my DB into disk in order to obtain my File. This is wasteful. (again, correct me if I am wrong).

I checked the implementation of method void uploadFile(String doi, File file); and I noticed that you are using the class FileUploader. From there you are using the SWORD library to perform the update. I can see that you use the class Deposit as a model to send data to the SWORD library for the upload.

The Class Deposit defines the field for the File as private InputStream file = null; (line 8), and its setter (the method that you actually use in class FileUploader to add the file) as public void setFile(InputStream file){...} (line 87). This means that the SWORD library is actually using an InputStream, so adding an overloaded method in your library that receives an InputStream instead of a File should not be very difficult.

Proposed changes:

  • Class FileUploader implement the overloaded method public DepositReceipt deposit(**InputStream file**, String apiKey, URI dataverseServer, String doi) throws IOException, SWORDClientException, SWORDError, ProtocolViolationException {...}
  • Interface DatasetOperations add the overloaded method void uploadFile(String doi, **InputStream file**);
  • Class DatasetOperationsImplV1 implement the overloaded method void uploadFile(String doi, ** InputStream file**){...}

Justification of changes:

  • Optimization and reasonable usage flexibility.

With this I should be able to update a "File" using an InputStream directly from my database without writing to a file temporarily.

Please, tell me what do you think of this proposed changes and also tell me if it makes sense implementing this new way of using your library. If you agree I will try to implement it by myself and when I am finished I will do a pull request.

Any feedback is very much appreciated.

And, again, thanks for this library. It is being very useful for me :D :D

@otter606
Copy link
Contributor

otter606 commented Nov 12, 2022 via email

@richarda23
Copy link
Collaborator

merged now, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants