This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes UPloading a Big file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "UPloading a Big file" Watch "UPloading a Big file" New topic
Author

UPloading a Big file

Abhilesh Khatri
Ranch Hand

Joined: Oct 02, 2002
Posts: 39
Hi all,
I am trying to upload a big file of size 3 MB.
I am using readLine(byte, int, byte) to upload this file.
It works fine. But takes about an hour to upload the file, which is unacceptable. Performance is crucial for our application.
Can any one suggest how to upload the file and achieve optimal performance
I am pasting the code snippet for your reference
ServletInputStream in = request.getInputStream();
byte[] line = new byte[128];
int i = in.readLine(line, 0, 128);
if (i < 3){
return null;
}
int boundaryLength = i - 2;
String boundary = new String(line, 0, boundaryLength);
fields = new Hashtable();

while (i != -1) {

fileData = new String();
String newLine = new String(line, 0, i);

if (newLine.startsWith("Content-Disposition: form-data; name=\""))
{
if (newLine.indexOf("filename=\"") != -1)
{
setFilename(new String(line, 0, i-2));

i = in.readLine(line, 0, 128);
setContentType(new String(line, 0, i-2));
i = in.readLine(line, 0, 128);
i = in.readLine(line, 0, 128);
newLine = new String(line, 0, i);
fileData+=newLine;
while (i != -1 && !newLine.startsWith(boundary)) {
i = in.readLine(line, 0, 128);
newLine = new String(line, 0, i);
fileData+=newLine;
}
}
else {
int pos = newLine.indexOf("name=\"");
String fieldName = newLine.substring(pos+6, newLine.length()-3);
i = in.readLine(line, 0, 128);
i = in.readLine(line, 0, 128);
newLine = new String(line, 0, i);
StringBuffer fieldValue = new StringBuffer(128);
while (i != -1 && !newLine.startsWith(boundary)) {
i = in.readLine(line, 0, 128);
if ((i==boundaryLength+2 || i==boundaryLength+4)
&& (new String(line, 0, i).startsWith(boundary)))
fieldValue.append(newLine.substring(0, newLine.length()-2));
elsefieldValue.append(newLine);
newLine = new String(line, 0, i);
}
fields.put(fieldName, fieldValue.toString());
}
}
i = in.readLine(line, 0, 128);

....
..
 
Have you checked out Aspose?
 
subject: UPloading a Big file
 
It's not a secret anymore!