• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Yet another upload file question...

 
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using the struts upload (as part of a multipart/formdata form)

and in the action servlet I'm using

I have the following code inside of my action servlet:



Is there a quicker way to read/write the upload stream?

instead of using int should I use byte? and would an array make it go quicker?

thanks for any help

-Tad
 
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this: channels

(channels are part of the java.nio package)
 
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Struts provided a best way of getting the stream u can use that rather than writing ur own piece of code . There is one DataType called FormFile in struts which maps to <input typ="file"> in to ur form bean

and in ur action class just say getXXXXXXXXX() which returns u FormFile and execute getStream which return u stream
 
Tad Dicks
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sreenath, I'm using the struts Form file. Here's the code preceding what I have shown from above:


Where fmf = the actionForm passed to the actionServlet.
I realize I could shorten the code by getting rid of a declaration or two (but I don't think it would make a difference in the end result).

-Tad
 
Tad Dicks
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ray, thanks for the link I'll try it and see if it speeds things up any. Even if it doesn't the code for that looks a little "cleaner."

-Tad
 
Tad Dicks
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't use the File channels as the FormFile type only returns and InpuStream and not a FileInputStream (and I don't see any easy way to get one from the other).

I only wonder if ready a byte array at a time would be quicker... I'll give it a try.


-Tad
 
Ray Stojonic
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try:
FileChannel myChannel = ((FileInputStream)yourFormFile.getInputStream()).getChannel();

Later:
Scratch that, FormFile.getStream returns a ByteArrayInputStream which won't cast to FileInputStream.
[ April 15, 2005: Message edited by: Ray Stojonic ]
 
Tad Dicks
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well this is what I came up with using a byte array instead of just the int:



And it really seems to have increased the upload speeds alot over the previous:



I guess none of this is really particular to Struts though, but maybe this can help someone else who's experiencing the same problems with the uploads in struts that I'm having.

Still doesn't fix the problem of *really* large uploads(200 megs or greater) dropping out and being replaced with the smaller previously uploaded file (just truly odd).


I just want to repeat its *much* faster (by an order of 100 or so). I'm just confused why I haven't seen it mentioned/posted anywhere that this wouldbe the correct way to do it... and that the other way is painstakingly slow.

-Tad
[ April 15, 2005: Message edited by: Tad Dicks ]
 
Doe, a deer, a female deer. Ray, a pockeful of sun. Me, a name, I call my tiny ad ...
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic