Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to convert a bunch of string into a file array and then upload it ?

 
Vishwas Gagrani
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!,
i have a bunch of strings, that i need to convert into n number of files ( file array) , so that i may upload it. How can i accomplish this ?
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the data is in memory already, why convert it back to files before uploading it?
 
Vishwas Gagrani
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lester Burnham wrote:If the data is in memory already, why convert it back to files before uploading it?



because my uploader code takes in a file[] as parameter. Also, the text to be uploaded may vary from 1byte to say... 1 mb in size. So i can't just upload it as simple string.
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not just rewrite the uploader code to work with strings?

Also, the text to be uploaded may vary from 1byte to say... 1 mb in size. So i can't just upload it as simple string.

Not following. You said "i have a bunch of strings" - so the data is in memory already, yes? What does the size of the texts have to do with it?
 
Vishwas Gagrani
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lester Burnham wrote:Why not just rewrite the uploader code to work with strings?

Also, the text to be uploaded may vary from 1byte to say... 1 mb in size. So i can't just upload it as simple string.

Not following. You said "i have a bunch of strings" - so the data is in memory already, yes? What does the size of the texts have to do with it?


It won't be a good idea to upload such a big size of string, in the form of string. It would be a slow process. Instead, it is a good idea to first convert it into a file object ( but not on the local drive, but on the fly ) and then insert all such files in a file array and then upload it.
thanks.
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It won't be a good idea to upload such a big size of string, in the form of string.

How do you think the file uploading works? By creating a byte[], and then sending it in the body of an HTTP POST (assuming that's how the upload works - you haven't said anything about that). It is true, though, that not the complete byte[] needs to be in memory - it can be read and sent piecemeal. But writing the contents of a String to disk, only to read it back into memory will certainly not be faster than converting it to a byte[] in memory.

Instead, it is a good idea to first convert it into a file object ( but not on the local drive, but on the fly ) and then insert all such files in a file array and then upload it.

The contents of File objects do not exist in memory - it exists in actual files on a disk (with all the security implications that entails for applets).
 
Vishwas Gagrani
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lester Burnham wrote:
It won't be a good idea to upload such a big size of string, in the form of string.

How do you think the file uploading works? By creating a byte[], and then sending it in the body of an HTTP POST (assuming that's how the upload works - you haven't said anything about that). It is true, though, that not the complete byte[] needs to be in memory - it can be read and sent piecemeal. But writing the contents of a String to disk, only to read it back into memory will certainly not be faster than converting it to a byte[] in memory.

Instead, it is a good idea to first convert it into a file object ( but not on the local drive, but on the fly ) and then insert all such files in a file array and then upload it.

The contents of File objects do not exist in memory - it exists in actual files on a disk (with all the security implications that entails for applets).


Yeah, i know that converting it into a physical file on the local drive, would be an unnecessary step. That's why, i just want to have some file object, in the memory only, because that is what my uploader code accepts.
But i think, as you said, it is not possible to make such file object ( without pointing it on the drive).

So, i am again left with the problem... how to make a communication between uploader code that accepts only a file[ ] , and the number of strings ( say a string array ) .
I cannot write the string uploader separately, because the code is a part of very complex bigger code, and it would take a huge amount of time to make it work with it.
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you can't make changes to the uploader code (which I think would be a much better way of handling this), check out RAM disk implementations like Apache Commons VFS: http://commons.apache.org/vfs/filesystems.html#ram

Note that you may still have to sign the applet since it uses classes in the java.io.* package.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic