-
Notifications
You must be signed in to change notification settings - Fork 4
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
Comments
Hi Aleix
Thanks for the detailed proposal. It sounds an excellent idea. You are
right, insisting on a java.util.File is quite restrictive.
Please go ahead and raise a PR.
Thanks again
Richard
…On Thu, Nov 10, 2022 at 3:00 PM Aleix Mariné Tena ***@***.***> wrote:
The interface interface DatasetOperations
<https://github.com/IQSS/dataverse-client-java/blob/master/src/main/java/com/researchspace/dataverse/api/v1/DatasetOperations.java>
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
<https://github.com/IQSS/dataverse-client-java/blob/master/src/main/java/com/researchspace/dataverse/http/DataverseOperationsImplV1.java>
method 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
<https://github.com/IQSS/dataverse-client-java/blob/master/src/main/java/com/researchspace/dataverse/sword/FileUploader.java>.
From there you are using the SWORD library to perform the update. I can see
that you use the class Deposit
<https://github.com/swordapp/JavaClient2.0/blob/master/src/main/java/org/swordapp/client/Deposit.java>
as a model to send data to the SWORD library for the upload.
The class Deposit
<https://github.com/swordapp/JavaClient2.0/blob/master/src/main/java/org/swordapp/client/Deposit.java>
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
<https://github.com/IQSS/dataverse-client-java/blob/master/src/main/java/com/researchspace/dataverse/sword/FileUploader.java>
add the overloaded method public DepositReceipt deposit(**InputStream
file**, String apiKey, URI dataverseServer, String doi) throws IOException,
SWORDClientException, SWORDError, ProtocolViolationException {
- interface DatasetOperations
<https://github.com/IQSS/dataverse-client-java/blob/master/src/main/java/com/researchspace/dataverse/api/v1/DatasetOperations.java>
add the overloaded method void uploadFile(String doi, **InputStream
file**);
- class DatasetOperationsImplV1
<https://github.com/IQSS/dataverse-client-java/blob/master/src/main/java/com/researchspace/dataverse/http/DataverseOperationsImplV1.java>
add the overloaded method void uploadFile(String doi, ** InputStream
file**);
Justification of changes:
- Optimization, flexibility.
With this I should be able to update a "File" using an InputStream
directly from my database.
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 finish 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
—
Reply to this email directly, view it on GitHub
<#12>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACIDVHKSX4LVDLWKB43K3STWHUEZZANCNFSM6AAAAAAR4UYNBE>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
merged now, thank you |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The interface
Interface DatasetOperations
defines the specification for the methodvoid 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 ofFile
, 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 anInputStream
for memory optimization).In order to use the method
void uploadFile(String doi, File file);
from class DatasetOperationsImplV1, I would need to write theInputStream
from my DB into disk in order to obtain myFile
. 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 classFileUploader
. From there you are using the SWORD library to perform the update. I can see that you use the classDeposit
as a model to send data to the SWORD library for the upload.The
Class Deposit
defines the field for theFile
asprivate InputStream file = null;
(line 8), and its setter (the method that you actually use in classFileUploader
to add the file) aspublic void setFile(InputStream file){...}
(line 87). This means that the SWORD library is actually using anInputStream
, so adding an overloaded method in your library that receives anInputStream
instead of aFile
should not be very difficult.Proposed changes:
Class FileUploader
implement the overloaded methodpublic DepositReceipt deposit(**InputStream file**, String apiKey, URI dataverseServer, String doi) throws IOException, SWORDClientException, SWORDError, ProtocolViolationException {...}
Interface DatasetOperations
add the overloaded methodvoid uploadFile(String doi, **InputStream file**);
Class DatasetOperationsImplV1
implement the overloaded methodvoid uploadFile(String doi, ** InputStream file**){...}
Justification of changes:
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
The text was updated successfully, but these errors were encountered: